Add a hint that the expressions produce a value

This commit is contained in:
Yuki Okushi 2021-07-30 05:35:03 +09:00
parent f3f8e758f2
commit eaff0fc25b
No known key found for this signature in database
GPG key ID: DABA5B072961C18A
6 changed files with 125 additions and 30 deletions

View file

@ -161,7 +161,18 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
if let Some(must_use_op) = must_use_op {
cx.struct_span_lint(UNUSED_MUST_USE, expr.span, |lint| {
lint.build(&format!("unused {} that must be used", must_use_op)).emit()
let mut lint = lint.build(&format!("unused {} that must be used", must_use_op));
lint.note(&format!("the {} produces a value", must_use_op));
if let Ok(snippet) = cx.sess().source_map().span_to_snippet(expr.span) {
lint.span_suggestion(
expr.span,
"use `let _ = ...` to ignore it",
format!("let _ = {}", snippet),
Applicability::MachineApplicable,
)
.emit()
}
lint.emit();
});
op_warned = true;
}