2022-04-07 12:39:59 -05:00
|
|
|
#![allow(unused)]
|
|
|
|
#![warn(clippy::needless_option_as_deref)]
|
2023-07-02 07:35:19 -05:00
|
|
|
#![allow(clippy::useless_vec)]
|
2021-09-08 09:31:47 -05:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// should lint
|
|
|
|
let _: Option<&usize> = Some(&1);
|
|
|
|
let _: Option<&mut usize> = Some(&mut 1);
|
|
|
|
|
2022-04-07 12:39:59 -05:00
|
|
|
let mut y = 0;
|
|
|
|
let mut x = Some(&mut y);
|
|
|
|
let _ = x;
|
|
|
|
|
2021-09-08 09:31:47 -05:00
|
|
|
// should not lint
|
|
|
|
let _ = Some(Box::new(1)).as_deref();
|
|
|
|
let _ = Some(Box::new(1)).as_deref_mut();
|
2022-04-07 12:39:59 -05:00
|
|
|
|
2022-05-05 09:12:52 -05:00
|
|
|
let mut y = 0;
|
|
|
|
let mut x = Some(&mut y);
|
|
|
|
for _ in 0..3 {
|
|
|
|
let _ = x.as_deref_mut();
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut y = 0;
|
|
|
|
let mut x = Some(&mut y);
|
|
|
|
let mut closure = || {
|
|
|
|
let _ = x.as_deref_mut();
|
|
|
|
};
|
|
|
|
closure();
|
|
|
|
closure();
|
|
|
|
|
2022-04-07 12:39:59 -05:00
|
|
|
// #7846
|
|
|
|
let mut i = 0;
|
|
|
|
let mut opt_vec = vec![Some(&mut i)];
|
|
|
|
opt_vec[0].as_deref_mut().unwrap();
|
|
|
|
|
|
|
|
let mut i = 0;
|
|
|
|
let x = &mut Some(&mut i);
|
|
|
|
(*x).as_deref_mut();
|
|
|
|
|
|
|
|
// #8047
|
|
|
|
let mut y = 0;
|
|
|
|
let mut x = Some(&mut y);
|
|
|
|
x.as_deref_mut();
|
|
|
|
dbg!(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct S<'a> {
|
|
|
|
opt: Option<&'a mut usize>,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn from_field<'a>(s: &'a mut S<'a>) -> Option<&'a mut usize> {
|
|
|
|
s.opt.as_deref_mut()
|
2021-09-08 09:31:47 -05:00
|
|
|
}
|
2024-07-25 11:29:17 -05:00
|
|
|
|
|
|
|
mod issue_non_copy_13077 {
|
|
|
|
pub fn something(mut maybe_side_effect: Option<&mut String>) {
|
|
|
|
for _ in 0..10 {
|
|
|
|
let _ = S {
|
|
|
|
field: other(maybe_side_effect.as_deref_mut()),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn other(_maybe_side_effect: Option<&mut String>) {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct S {
|
|
|
|
pub field: (),
|
|
|
|
}
|
|
|
|
}
|