-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2280b8a
commit f0b99b2
Showing
3 changed files
with
99 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
struct MyStruct; | ||
|
||
impl MyStruct { | ||
pub fn get_option() -> Option<Self> { | ||
todo!() | ||
} | ||
} | ||
|
||
fn return_option() -> Option<i32> { | ||
todo!() | ||
} | ||
|
||
fn main() { | ||
println!("Testing non erroneous option_take_on_temporary"); | ||
let mut option = Some(1); | ||
let _ = Box::new(move || option.take().unwrap()); | ||
|
||
println!("Testing non erroneous option_take_on_temporary"); | ||
let x = Some(3); | ||
x.as_ref(); | ||
|
||
let x = Some(3); | ||
x.as_ref(); | ||
//~^ ERROR: called `Option::take()` on a temporary value | ||
|
||
println!("Testing non erroneous option_take_on_temporary"); | ||
let mut x = Some(3); | ||
let y = x.as_mut(); | ||
|
||
let mut x = Some(3); | ||
let y = x.as_mut(); | ||
//~^ ERROR: called `Option::take()` on a temporary value | ||
let y = x.replace(289); | ||
//~^ ERROR: called `Option::take()` on a temporary value | ||
|
||
let y = Some(3).as_mut(); | ||
//~^ ERROR: called `Option::take()` on a temporary value | ||
|
||
let y = Option::as_mut(&mut x); | ||
//~^ ERROR: called `Option::take()` on a temporary value | ||
|
||
let x = return_option(); | ||
let x = return_option(); | ||
//~^ ERROR: called `Option::take()` on a temporary value | ||
|
||
let x = MyStruct::get_option(); | ||
let x = MyStruct::get_option(); | ||
//~^ ERROR: called `Option::take()` on a temporary value | ||
|
||
let mut my_vec = vec![1, 2, 3]; | ||
my_vec.push(4); | ||
let y = my_vec.first(); | ||
let y = my_vec.first(); | ||
//~^ ERROR: called `Option::take()` on a temporary value | ||
|
||
let y = my_vec.first(); | ||
//~^ ERROR: called `Option::take()` on a temporary value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters