Auto merge of #103761 - chenyukang:yukang/fix-103320-must-use, r=compiler-errors
Add explanatory message for [#must_use] in ops Fixes #103320
This commit is contained in:
commit
044a28a409
7 changed files with 142 additions and 9 deletions
|
@ -1,7 +1,7 @@
|
|||
use crate::lints::{
|
||||
PathStatementDrop, PathStatementDropSub, PathStatementNoEffect, UnusedAllocationDiag,
|
||||
UnusedAllocationMutDiag, UnusedClosure, UnusedDef, UnusedDelim, UnusedDelimSuggestion,
|
||||
UnusedGenerator, UnusedImportBracesDiag, UnusedOp, UnusedResult,
|
||||
UnusedAllocationMutDiag, UnusedClosure, UnusedDef, UnusedDefSuggestion, UnusedDelim,
|
||||
UnusedDelimSuggestion, UnusedGenerator, UnusedImportBracesDiag, UnusedOp, UnusedResult,
|
||||
};
|
||||
use crate::Lint;
|
||||
use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
|
||||
|
@ -418,6 +418,19 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
|
|||
);
|
||||
}
|
||||
MustUsePath::Def(span, def_id, reason) => {
|
||||
let suggestion = if matches!(
|
||||
cx.tcx.get_diagnostic_name(*def_id),
|
||||
Some(sym::add)
|
||||
| Some(sym::sub)
|
||||
| Some(sym::mul)
|
||||
| Some(sym::div)
|
||||
| Some(sym::rem)
|
||||
| Some(sym::neg),
|
||||
) {
|
||||
Some(UnusedDefSuggestion::Default { span: span.shrink_to_lo() })
|
||||
} else {
|
||||
None
|
||||
};
|
||||
cx.emit_spanned_lint(
|
||||
UNUSED_MUST_USE,
|
||||
*span,
|
||||
|
@ -427,6 +440,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
|
|||
cx,
|
||||
def_id: *def_id,
|
||||
note: *reason,
|
||||
suggestion,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue