Auto merge of #13102 - tesuji:fix-needless_option_as_deref, r=Alexendoo

Fix `needless_option_as_deref` false-positive on struct literals

changelog: [`needless_option_as_deref`] Fix false-positive on struct literals.

Fixes #13077 .

r?  Alexendoo
This commit is contained in:
bors 2024-07-15 16:23:41 +00:00
commit eb4d88e690
3 changed files with 37 additions and 1 deletions

View File

@ -1408,7 +1408,7 @@ pub fn get_enclosing_loop_or_multi_call_closure<'tcx>(
ExprKind::Closure { .. } | ExprKind::Loop(..) => return Some(e), ExprKind::Closure { .. } | ExprKind::Loop(..) => return Some(e),
_ => (), _ => (),
}, },
Node::Stmt(_) | Node::Block(_) | Node::LetStmt(_) | Node::Arm(_) => (), Node::Stmt(_) | Node::Block(_) | Node::LetStmt(_) | Node::Arm(_) | Node::ExprField(_) => (),
_ => break, _ => break,
} }
} }

View File

@ -52,3 +52,21 @@ struct S<'a> {
fn from_field<'a>(s: &'a mut S<'a>) -> Option<&'a mut usize> { fn from_field<'a>(s: &'a mut S<'a>) -> Option<&'a mut usize> {
s.opt.as_deref_mut() s.opt.as_deref_mut()
} }
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: (),
}
}

View File

@ -52,3 +52,21 @@ struct S<'a> {
fn from_field<'a>(s: &'a mut S<'a>) -> Option<&'a mut usize> { fn from_field<'a>(s: &'a mut S<'a>) -> Option<&'a mut usize> {
s.opt.as_deref_mut() s.opt.as_deref_mut()
} }
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: (),
}
}