Skip to content

Commit eb4d88e

Browse files
committed
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
2 parents 22eeb11 + dcee2e8 commit eb4d88e

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

clippy_utils/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ pub fn get_enclosing_loop_or_multi_call_closure<'tcx>(
14081408
ExprKind::Closure { .. } | ExprKind::Loop(..) => return Some(e),
14091409
_ => (),
14101410
},
1411-
Node::Stmt(_) | Node::Block(_) | Node::LetStmt(_) | Node::Arm(_) => (),
1411+
Node::Stmt(_) | Node::Block(_) | Node::LetStmt(_) | Node::Arm(_) | Node::ExprField(_) => (),
14121412
_ => break,
14131413
}
14141414
}

tests/ui/needless_option_as_deref.fixed

+18
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,21 @@ struct S<'a> {
5252
fn from_field<'a>(s: &'a mut S<'a>) -> Option<&'a mut usize> {
5353
s.opt.as_deref_mut()
5454
}
55+
56+
mod issue_non_copy_13077 {
57+
pub fn something(mut maybe_side_effect: Option<&mut String>) {
58+
for _ in 0..10 {
59+
let _ = S {
60+
field: other(maybe_side_effect.as_deref_mut()),
61+
};
62+
}
63+
}
64+
65+
fn other(_maybe_side_effect: Option<&mut String>) {
66+
unimplemented!()
67+
}
68+
69+
pub struct S {
70+
pub field: (),
71+
}
72+
}

tests/ui/needless_option_as_deref.rs

+18
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,21 @@ struct S<'a> {
5252
fn from_field<'a>(s: &'a mut S<'a>) -> Option<&'a mut usize> {
5353
s.opt.as_deref_mut()
5454
}
55+
56+
mod issue_non_copy_13077 {
57+
pub fn something(mut maybe_side_effect: Option<&mut String>) {
58+
for _ in 0..10 {
59+
let _ = S {
60+
field: other(maybe_side_effect.as_deref_mut()),
61+
};
62+
}
63+
}
64+
65+
fn other(_maybe_side_effect: Option<&mut String>) {
66+
unimplemented!()
67+
}
68+
69+
pub struct S {
70+
pub field: (),
71+
}
72+
}

0 commit comments

Comments
 (0)