Add a hint that the expressions produce a value
This commit is contained in:
parent
f3f8e758f2
commit
eaff0fc25b
6 changed files with 125 additions and 30 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue