From dcee2e8a0fb95887284b7779f2fd809f148722c5 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 15 Jul 2024 15:56:17 +0000 Subject: [PATCH] Dont stop find loop node at struct field node --- clippy_utils/src/lib.rs | 2 +- tests/ui/needless_option_as_deref.fixed | 8 ++++++-- tests/ui/needless_option_as_deref.rs | 8 ++++++-- tests/ui/needless_option_as_deref.stderr | 8 +------- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 8a6750c8997..0156e223c8d 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1407,7 +1407,7 @@ pub fn get_enclosing_loop_or_multi_call_closure<'tcx>( 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, } } diff --git a/tests/ui/needless_option_as_deref.fixed b/tests/ui/needless_option_as_deref.fixed index 7bde155582b..84eaf12fc13 100644 --- a/tests/ui/needless_option_as_deref.fixed +++ b/tests/ui/needless_option_as_deref.fixed @@ -56,7 +56,9 @@ fn from_field<'a>(s: &'a mut S<'a>) -> Option<&'a mut usize> { 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) }; + let _ = S { + field: other(maybe_side_effect.as_deref_mut()), + }; } } @@ -64,5 +66,7 @@ mod issue_non_copy_13077 { unimplemented!() } - pub struct S { pub field: () } + pub struct S { + pub field: (), + } } diff --git a/tests/ui/needless_option_as_deref.rs b/tests/ui/needless_option_as_deref.rs index ab06a38f742..fff1e45d846 100644 --- a/tests/ui/needless_option_as_deref.rs +++ b/tests/ui/needless_option_as_deref.rs @@ -56,7 +56,9 @@ fn from_field<'a>(s: &'a mut S<'a>) -> Option<&'a mut usize> { 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()) }; + let _ = S { + field: other(maybe_side_effect.as_deref_mut()), + }; } } @@ -64,5 +66,7 @@ fn other(_maybe_side_effect: Option<&mut String>) { unimplemented!() } - pub struct S { pub field: () } + pub struct S { + pub field: (), + } } diff --git a/tests/ui/needless_option_as_deref.stderr b/tests/ui/needless_option_as_deref.stderr index 3211062af91..a05d0aa9276 100644 --- a/tests/ui/needless_option_as_deref.stderr +++ b/tests/ui/needless_option_as_deref.stderr @@ -19,11 +19,5 @@ error: derefed type is same as origin LL | let _ = x.as_deref_mut(); | ^^^^^^^^^^^^^^^^ help: try: `x` -error: derefed type is same as origin - --> tests/ui/needless_option_as_deref.rs:59:38 - | -LL | let _ = S { field: other(maybe_side_effect.as_deref_mut()) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `maybe_side_effect` - -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors