Skip to content

Commit c0e3f4b

Browse files
committed
Change to give a help message
1 parent 70536d4 commit c0e3f4b

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

src/librustc/middle/liveness.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,13 +1657,15 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
16571657
fn report_dead_assign(&self, hir_id: HirId, sp: Span, var: Variable, is_argument: bool) {
16581658
if let Some(name) = self.should_warn(var) {
16591659
if is_argument {
1660-
self.ir.tcx.lint_hir(lint::builtin::UNUSED_ASSIGNMENTS, hir_id, sp,
1661-
&format!("value passed to `{}` is never read
1662-
(maybe it is overwritten before being read)", name));
1660+
self.ir.tcx.struct_span_lint_hir(lint::builtin::UNUSED_ASSIGNMENTS, hir_id, sp,
1661+
&format!("value passed to `{}` is never read", name))
1662+
.help("maybe it is overwritten before being read?")
1663+
.emit();
16631664
} else {
1664-
self.ir.tcx.lint_hir(lint::builtin::UNUSED_ASSIGNMENTS, hir_id, sp,
1665-
&format!("value assigned to `{}` is never read
1666-
(maybe it is overwritten before being read)", name));
1665+
self.ir.tcx.struct_span_lint_hir(lint::builtin::UNUSED_ASSIGNMENTS, hir_id, sp,
1666+
&format!("value assigned to `{}` is never read", name))
1667+
.help("maybe it is overwritten before being read?")
1668+
.emit();
16671669
}
16681670
}
16691671
}

src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ LL | mut hours_are_suns,
4444
= note: consider using `_hours_are_suns` instead
4545

4646
warning: value assigned to `hours_are_suns` is never read
47-
(maybe it is overwritten before being read)
4847
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:50:9
4948
|
5049
LL | hours_are_suns = false;
@@ -56,6 +55,7 @@ note: lint level defined here
5655
LL | #![warn(unused)] // UI tests pass `-A unused` (#43896)
5756
| ^^^^^^
5857
= note: #[warn(unused_assignments)] implied by #[warn(unused)]
58+
= help: maybe it is overwritten before being read?
5959

6060
warning: unused variable: `fire`
6161
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:54:32
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
error: value assigned to `x` is never read
2-
(maybe it is overwritten before being read)
32
--> $DIR/liveness-dead.rs:19:13
43
|
54
LL | let mut x: isize = 3; //~ ERROR: value assigned to `x` is never read
@@ -10,27 +9,31 @@ note: lint level defined here
109
|
1110
LL | #![deny(unused_assignments)]
1211
| ^^^^^^^^^^^^^^^^^^
12+
= help: maybe it is overwritten before being read?
1313

1414
error: value assigned to `x` is never read
15-
(maybe it is overwritten before being read)
1615
--> $DIR/liveness-dead.rs:27:5
1716
|
1817
LL | x = 4; //~ ERROR: value assigned to `x` is never read
1918
| ^
19+
|
20+
= help: maybe it is overwritten before being read?
2021

2122
error: value passed to `x` is never read
22-
(maybe it is overwritten before being read)
2323
--> $DIR/liveness-dead.rs:30:11
2424
|
2525
LL | fn f4(mut x: i32) { //~ ERROR: value passed to `x` is never read
2626
| ^
27+
|
28+
= help: maybe it is overwritten before being read?
2729

2830
error: value assigned to `x` is never read
29-
(maybe it is overwritten before being read)
3031
--> $DIR/liveness-dead.rs:37:5
3132
|
3233
LL | x = 4; //~ ERROR: value assigned to `x` is never read
3334
| ^
35+
|
36+
= help: maybe it is overwritten before being read?
3437

3538
error: aborting due to 4 previous errors
3639

src/test/ui/liveness/liveness-unused.stderr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ LL | let mut x = 3;
5050
= note: consider using `_x` instead
5151

5252
error: value assigned to `x` is never read
53-
(maybe it is overwritten before being read)
5453
--> $DIR/liveness-unused.rs:42:5
5554
|
5655
LL | x += 4;
@@ -61,6 +60,7 @@ note: lint level defined here
6160
|
6261
LL | #![deny(unused_assignments)]
6362
| ^^^^^^^^^^^^^^^^^^
63+
= help: maybe it is overwritten before being read?
6464

6565
error: variable `z` is assigned to, but never used
6666
--> $DIR/liveness-unused.rs:47:13
@@ -103,11 +103,12 @@ LL | let x;
103103
= note: consider using `_x` instead
104104

105105
error: value assigned to `x` is never read
106-
(maybe it is overwritten before being read)
107106
--> $DIR/liveness-unused.rs:126:9
108107
|
109108
LL | x = 0; //~ ERROR value assigned to `x` is never read
110109
| ^
110+
|
111+
= help: maybe it is overwritten before being read?
111112

112113
error: aborting due to 13 previous errors
113114

0 commit comments

Comments
 (0)