Skip to content

Commit dcee2e8

Browse files
committed
Dont stop find loop node at struct field node
1 parent 4264548 commit dcee2e8

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

clippy_utils/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,7 @@ pub fn get_enclosing_loop_or_multi_call_closure<'tcx>(
14071407
ExprKind::Closure { .. } | ExprKind::Loop(..) => return Some(e),
14081408
_ => (),
14091409
},
1410-
Node::Stmt(_) | Node::Block(_) | Node::LetStmt(_) | Node::Arm(_) => (),
1410+
Node::Stmt(_) | Node::Block(_) | Node::LetStmt(_) | Node::Arm(_) | Node::ExprField(_) => (),
14111411
_ => break,
14121412
}
14131413
}

tests/ui/needless_option_as_deref.fixed

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,17 @@ fn from_field<'a>(s: &'a mut S<'a>) -> Option<&'a mut usize> {
5656
mod issue_non_copy_13077 {
5757
pub fn something(mut maybe_side_effect: Option<&mut String>) {
5858
for _ in 0..10 {
59-
let _ = S { field: other(maybe_side_effect) };
59+
let _ = S {
60+
field: other(maybe_side_effect.as_deref_mut()),
61+
};
6062
}
6163
}
6264

6365
fn other(_maybe_side_effect: Option<&mut String>) {
6466
unimplemented!()
6567
}
6668

67-
pub struct S { pub field: () }
69+
pub struct S {
70+
pub field: (),
71+
}
6872
}

tests/ui/needless_option_as_deref.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,17 @@ fn from_field<'a>(s: &'a mut S<'a>) -> Option<&'a mut usize> {
5656
mod issue_non_copy_13077 {
5757
pub fn something(mut maybe_side_effect: Option<&mut String>) {
5858
for _ in 0..10 {
59-
let _ = S { field: other(maybe_side_effect.as_deref_mut()) };
59+
let _ = S {
60+
field: other(maybe_side_effect.as_deref_mut()),
61+
};
6062
}
6163
}
6264

6365
fn other(_maybe_side_effect: Option<&mut String>) {
6466
unimplemented!()
6567
}
6668

67-
pub struct S { pub field: () }
69+
pub struct S {
70+
pub field: (),
71+
}
6872
}

tests/ui/needless_option_as_deref.stderr

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,5 @@ error: derefed type is same as origin
1919
LL | let _ = x.as_deref_mut();
2020
| ^^^^^^^^^^^^^^^^ help: try: `x`
2121

22-
error: derefed type is same as origin
23-
--> tests/ui/needless_option_as_deref.rs:59:38
24-
|
25-
LL | let _ = S { field: other(maybe_side_effect.as_deref_mut()) };
26-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `maybe_side_effect`
27-
28-
error: aborting due to 4 previous errors
22+
error: aborting due to 3 previous errors
2923

0 commit comments

Comments
 (0)