Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 337181e

Browse files
committedJul 31, 2021
Auto merge of #87607 - JohnTitor:help-to-unused-must-use-op, r=estebank
Add a hint that the expressions produce a value Fixes #85913 The second commit is semi-_unrelated_ but it allows us to run the related tests just on `src/test/ui/lint`.
2 parents 7069a8c + 924eddf commit 337181e

File tree

84 files changed

+325
-143
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+325
-143
lines changed
 

‎compiler/rustc_lint/src/unused.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,15 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
161161

162162
if let Some(must_use_op) = must_use_op {
163163
cx.struct_span_lint(UNUSED_MUST_USE, expr.span, |lint| {
164-
lint.build(&format!("unused {} that must be used", must_use_op)).emit()
164+
let mut lint = lint.build(&format!("unused {} that must be used", must_use_op));
165+
lint.span_label(expr.span, &format!("the {} produces a value", must_use_op));
166+
lint.span_suggestion_verbose(
167+
expr.span.shrink_to_lo(),
168+
"use `let _ = ...` to ignore the resulting value",
169+
"let _ = ".to_string(),
170+
Applicability::MachineApplicable,
171+
);
172+
lint.emit();
165173
});
166174
op_warned = true;
167175
}

‎src/test/ui/lint/fn_must_use.stderr

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,23 @@ warning: unused comparison that must be used
4747
--> $DIR/fn_must_use.rs:74:5
4848
|
4949
LL | 2 == 3;
50-
| ^^^^^^
50+
| ^^^^^^ the comparison produces a value
51+
|
52+
help: use `let _ = ...` to ignore the resulting value
53+
|
54+
LL | let _ = 2 == 3;
55+
| ^^^^^^^
5156

5257
warning: unused comparison that must be used
5358
--> $DIR/fn_must_use.rs:75:5
5459
|
5560
LL | m == n;
56-
| ^^^^^^
61+
| ^^^^^^ the comparison produces a value
62+
|
63+
help: use `let _ = ...` to ignore the resulting value
64+
|
65+
LL | let _ = m == n;
66+
| ^^^^^^^
5767

5868
warning: 8 warnings emitted
5969

0 commit comments

Comments
 (0)
Please sign in to comment.