1
Fork 0

Change lint_dropping_copy_types to use UseLetUnderscoreIgnoreSuggestion as suggestion.

This commit is contained in:
surechen 2024-05-29 18:09:20 +08:00
parent ac736d6d88
commit 9d1ed80a8a
3 changed files with 8 additions and 33 deletions

View file

@ -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 lint_dropping_copy_types = calls to `std::mem::drop` with a value that implements `Copy` does nothing
.label = argument has type `{$arg_ty}` .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 lint_dropping_references = calls to `std::mem::drop` with a reference instead of an owned value does nothing
.label = argument has type `{$arg_ty}` .label = argument has type `{$arg_ty}`

View file

@ -5,9 +5,8 @@ use rustc_span::sym;
use crate::{ use crate::{
lints::{ lints::{
DropCopyDiag, DropCopySuggestion, DropRefDiag, ForgetCopyDiag, ForgetRefDiag, DropCopyDiag, DropRefDiag, ForgetCopyDiag, ForgetRefDiag, UndroppedManuallyDropsDiag,
UndroppedManuallyDropsDiag, UndroppedManuallyDropsSuggestion, UndroppedManuallyDropsSuggestion, UseLetUnderscoreIgnoreSuggestion,
UseLetUnderscoreIgnoreSuggestion,
}, },
LateContext, LateLintPass, LintContext, 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 => { 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( cx.emit_span_lint(
DROPPING_COPY_TYPES, DROPPING_COPY_TYPES,
expr.span, 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 => { sym::mem_forget if is_copy => {

View file

@ -691,20 +691,7 @@ pub struct DropCopyDiag<'a> {
#[label] #[label]
pub label: Span, pub label: Span,
#[subdiagnostic] #[subdiagnostic]
pub sugg: DropCopySuggestion, pub sugg: UseLetUnderscoreIgnoreSuggestion,
}
#[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,
},
} }
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]