Skip to content

Commit 9d1ed80

Browse files
committed
Change lint_dropping_copy_types to use UseLetUnderscoreIgnoreSuggestion as suggestion.
1 parent ac736d6 commit 9d1ed80

File tree

3 files changed

+8
-33
lines changed

3 files changed

+8
-33
lines changed

compiler/rustc_lint/messages.ftl

-2
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,6 @@ lint_drop_trait_constraints =
232232
233233
lint_dropping_copy_types = calls to `std::mem::drop` with a value that implements `Copy` does nothing
234234
.label = argument has type `{$arg_ty}`
235-
.note = use `let _ = ...` to ignore the expression or result
236-
.suggestion = use `let _ = ...` to ignore the expression or result
237235
238236
lint_dropping_references = calls to `std::mem::drop` with a reference instead of an owned value does nothing
239237
.label = argument has type `{$arg_ty}`

compiler/rustc_lint/src/drop_forget_useless.rs

+7-17
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ use rustc_span::sym;
55

66
use crate::{
77
lints::{
8-
DropCopyDiag, DropCopySuggestion, DropRefDiag, ForgetCopyDiag, ForgetRefDiag,
9-
UndroppedManuallyDropsDiag, UndroppedManuallyDropsSuggestion,
10-
UseLetUnderscoreIgnoreSuggestion,
8+
DropCopyDiag, DropRefDiag, ForgetCopyDiag, ForgetRefDiag, UndroppedManuallyDropsDiag,
9+
UndroppedManuallyDropsSuggestion, UseLetUnderscoreIgnoreSuggestion,
1110
},
1211
LateContext, LateLintPass, LintContext,
1312
};
@@ -183,23 +182,14 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
183182
);
184183
}
185184
sym::mem_drop if is_copy && !drop_is_single_call_in_arm => {
186-
let sugg = if let Some((_, node)) = cx.tcx.hir().parent_iter(expr.hir_id).nth(0)
187-
&& let Node::Stmt(stmt) = node
188-
&& let StmtKind::Semi(e) = stmt.kind
189-
&& e.hir_id == expr.hir_id
190-
{
191-
DropCopySuggestion::Suggestion {
192-
start_span: expr.span.shrink_to_lo().until(arg.span),
193-
end_span: arg.span.shrink_to_hi().until(expr.span.shrink_to_hi()),
194-
}
195-
} else {
196-
DropCopySuggestion::Note
197-
};
198-
199185
cx.emit_span_lint(
200186
DROPPING_COPY_TYPES,
201187
expr.span,
202-
DropCopyDiag { arg_ty, label: arg.span, sugg },
188+
DropCopyDiag {
189+
arg_ty,
190+
label: arg.span,
191+
sugg: let_underscore_ignore_sugg(),
192+
},
203193
);
204194
}
205195
sym::mem_forget if is_copy => {

compiler/rustc_lint/src/lints.rs

+1-14
Original file line numberDiff line numberDiff line change
@@ -691,20 +691,7 @@ pub struct DropCopyDiag<'a> {
691691
#[label]
692692
pub label: Span,
693693
#[subdiagnostic]
694-
pub sugg: DropCopySuggestion,
695-
}
696-
697-
#[derive(Subdiagnostic)]
698-
pub enum DropCopySuggestion {
699-
#[note(lint_note)]
700-
Note,
701-
#[multipart_suggestion(lint_suggestion, style = "verbose", applicability = "maybe-incorrect")]
702-
Suggestion {
703-
#[suggestion_part(code = "let _ = ")]
704-
start_span: Span,
705-
#[suggestion_part(code = "")]
706-
end_span: Span,
707-
},
694+
pub sugg: UseLetUnderscoreIgnoreSuggestion,
708695
}
709696

710697
#[derive(LintDiagnostic)]

0 commit comments

Comments
 (0)