Skip to content

Commit 924eddf

Browse files
committed
Apply review suggestion
1 parent f3c59a8 commit 924eddf

File tree

5 files changed

+157
-70
lines changed

5 files changed

+157
-70
lines changed

compiler/rustc_lint/src/unused.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,13 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
162162
if let Some(must_use_op) = must_use_op {
163163
cx.struct_span_lint(UNUSED_MUST_USE, expr.span, |lint| {
164164
let mut lint = lint.build(&format!("unused {} that must be used", must_use_op));
165-
lint.note(&format!("the {} produces a value", must_use_op));
166-
if let Ok(snippet) = cx.sess().source_map().span_to_snippet(expr.span) {
167-
lint.span_suggestion(
168-
expr.span,
169-
"use `let _ = ...` to ignore it",
170-
format!("let _ = {}", snippet),
171-
Applicability::MachineApplicable,
172-
)
173-
.emit()
174-
}
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+
);
175172
lint.emit();
176173
});
177174
op_warned = true;

src/test/ui/lint/fn_must_use.stderr

+10-4
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,23 @@ warning: unused comparison that must be used
4747
--> $DIR/fn_must_use.rs:74:5
4848
|
4949
LL | 2 == 3;
50-
| ^^^^^^ help: use `let _ = ...` to ignore it: `let _ = 2 == 3`
50+
| ^^^^^^ the comparison produces a value
5151
|
52-
= note: the comparison produces a value
52+
help: use `let _ = ...` to ignore the resulting value
53+
|
54+
LL | let _ = 2 == 3;
55+
| ^^^^^^^
5356

5457
warning: unused comparison that must be used
5558
--> $DIR/fn_must_use.rs:75:5
5659
|
5760
LL | m == n;
58-
| ^^^^^^ help: use `let _ = ...` to ignore it: `let _ = m == n`
61+
| ^^^^^^ the comparison produces a value
62+
|
63+
help: use `let _ = ...` to ignore the resulting value
5964
|
60-
= note: the comparison produces a value
65+
LL | let _ = m == n;
66+
| ^^^^^^^
6167

6268
warning: 8 warnings emitted
6369

src/test/ui/lint/unused-borrows.stderr

+30-12
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,72 @@ error: unused borrow that must be used
22
--> $DIR/unused-borrows.rs:6:5
33
|
44
LL | &42;
5-
| ^^^ help: use `let _ = ...` to ignore it: `let _ = &42`
5+
| ^^^ the borrow produces a value
66
|
77
note: the lint level is defined here
88
--> $DIR/unused-borrows.rs:1:9
99
|
1010
LL | #![deny(unused_must_use)]
1111
| ^^^^^^^^^^^^^^^
12-
= note: the borrow produces a value
12+
help: use `let _ = ...` to ignore the resulting value
13+
|
14+
LL | let _ = &42;
15+
| ^^^^^^^
1316

1417
error: unused borrow that must be used
1518
--> $DIR/unused-borrows.rs:9:5
1619
|
1720
LL | &mut foo(42);
18-
| ^^^^^^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = &mut foo(42)`
21+
| ^^^^^^^^^^^^ the borrow produces a value
22+
|
23+
help: use `let _ = ...` to ignore the resulting value
1924
|
20-
= note: the borrow produces a value
25+
LL | let _ = &mut foo(42);
26+
| ^^^^^^^
2127

2228
error: unused borrow that must be used
2329
--> $DIR/unused-borrows.rs:12:5
2430
|
2531
LL | &&42;
26-
| ^^^^ help: use `let _ = ...` to ignore it: `let _ = &&42`
32+
| ^^^^ the borrow produces a value
33+
|
34+
help: use `let _ = ...` to ignore the resulting value
2735
|
28-
= note: the borrow produces a value
36+
LL | let _ = &&42;
37+
| ^^^^^^^
2938

3039
error: unused borrow that must be used
3140
--> $DIR/unused-borrows.rs:15:5
3241
|
3342
LL | &&mut 42;
34-
| ^^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = &&mut 42`
43+
| ^^^^^^^^ the borrow produces a value
3544
|
36-
= note: the borrow produces a value
45+
help: use `let _ = ...` to ignore the resulting value
46+
|
47+
LL | let _ = &&mut 42;
48+
| ^^^^^^^
3749

3850
error: unused borrow that must be used
3951
--> $DIR/unused-borrows.rs:18:5
4052
|
4153
LL | &mut &42;
42-
| ^^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = &mut &42`
54+
| ^^^^^^^^ the borrow produces a value
55+
|
56+
help: use `let _ = ...` to ignore the resulting value
4357
|
44-
= note: the borrow produces a value
58+
LL | let _ = &mut &42;
59+
| ^^^^^^^
4560

4661
error: unused borrow that must be used
4762
--> $DIR/unused-borrows.rs:23:5
4863
|
4964
LL | && foo(42);
50-
| ^^^^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = && foo(42)`
65+
| ^^^^^^^^^^ the borrow produces a value
66+
|
67+
help: use `let _ = ...` to ignore the resulting value
5168
|
52-
= note: the borrow produces a value
69+
LL | let _ = && foo(42);
70+
| ^^^^^^^
5371

5472
error: aborting due to 6 previous errors
5573

src/test/ui/lint/unused/issue-85913.stderr

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ error: unused logical operation that must be used
22
--> $DIR/issue-85913.rs:4:5
33
|
44
LL | function() && return 1;
5-
| ^^^^^^^^^^^^^^^^^^^^^^ help: use `let _ = ...` to ignore it: `let _ = function() && return 1`
5+
| ^^^^^^^^^^^^^^^^^^^^^^ the logical operation produces a value
66
|
77
note: the lint level is defined here
88
--> $DIR/issue-85913.rs:1:9
99
|
1010
LL | #![deny(unused_must_use)]
1111
| ^^^^^^^^^^^^^^^
12-
= note: the logical operation produces a value
12+
help: use `let _ = ...` to ignore the resulting value
13+
|
14+
LL | let _ = function() && return 1;
15+
| ^^^^^^^
1316

1417
error: aborting due to previous error
1518

0 commit comments

Comments
 (0)