2024-11-13 19:39:08 -08:00
|
|
|
struct MyStruct;
|
|
|
|
|
|
|
|
|
|
impl MyStruct {
|
|
|
|
|
pub fn get_option() -> Option<Self> {
|
|
|
|
|
todo!()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn return_option() -> Option<i32> {
|
|
|
|
|
todo!()
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-08 20:07:19 +02:00
|
|
|
fn main() {
|
2022-04-12 19:34:55 +02:00
|
|
|
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();
|
|
|
|
|
|
2022-04-08 20:07:19 +02:00
|
|
|
let x = Some(3);
|
2022-04-09 18:35:18 +02:00
|
|
|
x.as_ref().take();
|
2025-02-11 17:57:08 +01:00
|
|
|
//~^ needless_option_take
|
|
|
|
|
|
2024-11-13 19:39:08 -08:00
|
|
|
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().take();
|
2025-02-11 17:57:08 +01:00
|
|
|
//~^ needless_option_take
|
|
|
|
|
|
2024-11-13 19:39:08 -08:00
|
|
|
let y = x.replace(289).take();
|
2025-02-11 17:57:08 +01:00
|
|
|
//~^ needless_option_take
|
|
|
|
|
|
2024-11-13 19:39:08 -08:00
|
|
|
let y = Some(3).as_mut().take();
|
2025-02-11 17:57:08 +01:00
|
|
|
//~^ needless_option_take
|
|
|
|
|
|
2024-11-13 19:39:08 -08:00
|
|
|
let y = Option::as_mut(&mut x).take();
|
2025-02-11 17:57:08 +01:00
|
|
|
//~^ needless_option_take
|
|
|
|
|
|
2024-11-13 19:39:08 -08:00
|
|
|
let x = return_option();
|
|
|
|
|
let x = return_option().take();
|
2025-02-11 17:57:08 +01:00
|
|
|
//~^ needless_option_take
|
|
|
|
|
|
2024-11-13 19:39:08 -08:00
|
|
|
let x = MyStruct::get_option();
|
|
|
|
|
let x = MyStruct::get_option().take();
|
2025-02-11 17:57:08 +01:00
|
|
|
//~^ needless_option_take
|
|
|
|
|
|
2024-11-13 19:39:08 -08:00
|
|
|
let mut my_vec = vec![1, 2, 3];
|
|
|
|
|
my_vec.push(4);
|
|
|
|
|
let y = my_vec.first();
|
|
|
|
|
let y = my_vec.first().take();
|
2025-02-11 17:57:08 +01:00
|
|
|
//~^ needless_option_take
|
|
|
|
|
|
2024-11-13 19:39:08 -08:00
|
|
|
let y = my_vec.first().take();
|
2025-02-11 17:57:08 +01:00
|
|
|
//~^ needless_option_take
|
2022-04-08 20:07:19 +02:00
|
|
|
}
|