about summary refs log tree commit diff
diff options
context:
space:
mode:
authorsurechen <chenshuo17@huawei.com>2024-05-29 18:09:20 +0800
committersurechen <chenshuo17@huawei.com>2024-05-29 18:09:20 +0800
commit9d1ed80a8af72ad6918809861697e76ec38df178 (patch)
treed100181eefa8ec552e5c588775e8d19d8d3c379d
parentac736d6d8887349c4dacb1fa19cccebf7dae13fd (diff)
downloadrust-9d1ed80a8af72ad6918809861697e76ec38df178.tar.gz
rust-9d1ed80a8af72ad6918809861697e76ec38df178.zip
Change lint_dropping_copy_types to use UseLetUnderscoreIgnoreSuggestion as suggestion.
-rw-r--r--compiler/rustc_lint/messages.ftl2
-rw-r--r--compiler/rustc_lint/src/drop_forget_useless.rs24
-rw-r--r--compiler/rustc_lint/src/lints.rs15
3 files changed, 8 insertions, 33 deletions
diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl
index 49c95ad935d..fb71cb60140 100644
--- a/compiler/rustc_lint/messages.ftl
+++ b/compiler/rustc_lint/messages.ftl
@@ -232,8 +232,6 @@ lint_drop_trait_constraints =
 
 lint_dropping_copy_types = calls to `std::mem::drop` with a value that implements `Copy` does nothing
     .label = argument has type `{$arg_ty}`
-    .note = use `let _ = ...` to ignore the expression or result
-    .suggestion = use `let _ = ...` to ignore the expression or result
 
 lint_dropping_references = calls to `std::mem::drop` with a reference instead of an owned value does nothing
     .label = argument has type `{$arg_ty}`
diff --git a/compiler/rustc_lint/src/drop_forget_useless.rs b/compiler/rustc_lint/src/drop_forget_useless.rs
index 2c0973404ee..eea0898d83f 100644
--- a/compiler/rustc_lint/src/drop_forget_useless.rs
+++ b/compiler/rustc_lint/src/drop_forget_useless.rs
@@ -5,9 +5,8 @@ use rustc_span::sym;
 
 use crate::{
     lints::{
-        DropCopyDiag, DropCopySuggestion, DropRefDiag, ForgetCopyDiag, ForgetRefDiag,
-        UndroppedManuallyDropsDiag, UndroppedManuallyDropsSuggestion,
-        UseLetUnderscoreIgnoreSuggestion,
+        DropCopyDiag, DropRefDiag, ForgetCopyDiag, ForgetRefDiag, UndroppedManuallyDropsDiag,
+        UndroppedManuallyDropsSuggestion, UseLetUnderscoreIgnoreSuggestion,
     },
     LateContext, LateLintPass, LintContext,
 };
@@ -183,23 +182,14 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
                     );
                 }
                 sym::mem_drop if is_copy && !drop_is_single_call_in_arm => {
-                    let sugg = if let Some((_, node)) = cx.tcx.hir().parent_iter(expr.hir_id).nth(0)
-                        && let Node::Stmt(stmt) = node
-                        && let StmtKind::Semi(e) = stmt.kind
-                        && e.hir_id == expr.hir_id
-                    {
-                        DropCopySuggestion::Suggestion {
-                            start_span: expr.span.shrink_to_lo().until(arg.span),
-                            end_span: arg.span.shrink_to_hi().until(expr.span.shrink_to_hi()),
-                        }
-                    } else {
-                        DropCopySuggestion::Note
-                    };
-
                     cx.emit_span_lint(
                         DROPPING_COPY_TYPES,
                         expr.span,
-                        DropCopyDiag { arg_ty, label: arg.span, sugg },
+                        DropCopyDiag {
+                            arg_ty,
+                            label: arg.span,
+                            sugg: let_underscore_ignore_sugg(),
+                        },
                     );
                 }
                 sym::mem_forget if is_copy => {
diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs
index 4705bbd5bf6..84d46ef3b65 100644
--- a/compiler/rustc_lint/src/lints.rs
+++ b/compiler/rustc_lint/src/lints.rs
@@ -691,20 +691,7 @@ pub struct DropCopyDiag<'a> {
     #[label]
     pub label: Span,
     #[subdiagnostic]
-    pub sugg: DropCopySuggestion,
-}
-
-#[derive(Subdiagnostic)]
-pub enum DropCopySuggestion {
-    #[note(lint_note)]
-    Note,
-    #[multipart_suggestion(lint_suggestion, style = "verbose", applicability = "maybe-incorrect")]
-    Suggestion {
-        #[suggestion_part(code = "let _ = ")]
-        start_span: Span,
-        #[suggestion_part(code = "")]
-        end_span: Span,
-    },
+    pub sugg: UseLetUnderscoreIgnoreSuggestion,
 }
 
 #[derive(LintDiagnostic)]