about summary refs log tree commit diff
path: root/clippy_lints/src
diff options
context:
space:
mode:
authorTimo <30553356+y21@users.noreply.github.com>2025-03-19 22:51:38 +0000
committerGitHub <noreply@github.com>2025-03-19 22:51:38 +0000
commit221ae5f1767375c2eb8e9f326db609012d0bcfd0 (patch)
treef6cfa39883fdf6a91d208e61d5bc98cef6953cd4 /clippy_lints/src
parent48ce25ea0e02f46d2888aed2f80cf86b2dc172d6 (diff)
parentaf40c23215dc9e82041dab9e6d40b376b88313e9 (diff)
fix suggestion for assignments have enclosing parentheses under `needless_late_init` (#14169)
fixes #9895

changelog: [`needless_late_init`]: correct suggestion when assignments
have enclosing parentheses
Diffstat (limited to 'clippy_lints/src')
-rw-r--r--clippy_lints/src/needless_late_init.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/clippy_lints/src/needless_late_init.rs b/clippy_lints/src/needless_late_init.rs
index 863a1f895c9..6e73ae149b4 100644
--- a/clippy_lints/src/needless_late_init.rs
+++ b/clippy_lints/src/needless_late_init.rs
@@ -1,6 +1,6 @@
 use clippy_utils::diagnostics::span_lint_and_then;
 use clippy_utils::path_to_local;
-use clippy_utils::source::{SourceText, SpanRangeExt};
+use clippy_utils::source::{SourceText, SpanRangeExt, snippet};
 use clippy_utils::ty::needs_ordered_drop;
 use clippy_utils::visitors::{for_each_expr, for_each_expr_without_closures, is_local_used};
 use core::ops::ControlFlow;
@@ -100,7 +100,6 @@ fn stmt_needs_ordered_drop(cx: &LateContext<'_>, stmt: &Stmt<'_>) -> bool {
 #[derive(Debug)]
 struct LocalAssign {
     lhs_id: HirId,
-    lhs_span: Span,
     rhs_span: Span,
     span: Span,
 }
@@ -118,7 +117,6 @@ impl LocalAssign {
 
             Some(Self {
                 lhs_id: path_to_local(lhs)?,
-                lhs_span: lhs.span,
                 rhs_span: rhs.span.source_callsite(),
                 span,
             })
@@ -281,7 +279,10 @@ fn check<'tcx>(
                         format!("move the declaration `{binding_name}` here"),
                         vec![
                             (local_stmt.span, String::new()),
-                            (assign.lhs_span, let_snippet.to_owned()),
+                            (
+                                assign.span,
+                                let_snippet.to_owned() + " = " + &snippet(cx, assign.rhs_span, ".."),
+                            ),
                         ],
                         Applicability::MachineApplicable,
                     );