Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clearer error message for dead assign #56439

Merged
merged 5 commits into from
Dec 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1657,11 +1657,15 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
fn report_dead_assign(&self, hir_id: HirId, sp: Span, var: Variable, is_argument: bool) {
if let Some(name) = self.should_warn(var) {
if is_argument {
self.ir.tcx.lint_hir(lint::builtin::UNUSED_ASSIGNMENTS, hir_id, sp,
&format!("value passed to `{}` is never read", name));
self.ir.tcx.struct_span_lint_hir(lint::builtin::UNUSED_ASSIGNMENTS, hir_id, sp,
&format!("value passed to `{}` is never read", name))
.help("maybe it is overwritten before being read?")
.emit();
} else {
self.ir.tcx.lint_hir(lint::builtin::UNUSED_ASSIGNMENTS, hir_id, sp,
&format!("value assigned to `{}` is never read", name));
self.ir.tcx.struct_span_lint_hir(lint::builtin::UNUSED_ASSIGNMENTS, hir_id, sp,
&format!("value assigned to `{}` is never read", name))
.help("maybe it is overwritten before being read?")
.emit();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ note: lint level defined here
LL | #![warn(unused)] // UI tests pass `-A unused` (#43896)
| ^^^^^^
= note: #[warn(unused_assignments)] implied by #[warn(unused)]
= help: maybe it is overwritten before being read?

warning: unused variable: `fire`
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:54:32
Expand Down
7 changes: 7 additions & 0 deletions src/test/ui/liveness/liveness-dead.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,31 @@ note: lint level defined here
|
LL | #![deny(unused_assignments)]
| ^^^^^^^^^^^^^^^^^^
= help: maybe it is overwritten before being read?

error: value assigned to `x` is never read
--> $DIR/liveness-dead.rs:27:5
|
LL | x = 4; //~ ERROR: value assigned to `x` is never read
| ^
|
= help: maybe it is overwritten before being read?

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

error: value assigned to `x` is never read
--> $DIR/liveness-dead.rs:37:5
|
LL | x = 4; //~ ERROR: value assigned to `x` is never read
| ^
|
= help: maybe it is overwritten before being read?

error: aborting due to 4 previous errors

3 changes: 3 additions & 0 deletions src/test/ui/liveness/liveness-unused.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ note: lint level defined here
|
LL | #![deny(unused_assignments)]
| ^^^^^^^^^^^^^^^^^^
= help: maybe it is overwritten before being read?

error: variable `z` is assigned to, but never used
--> $DIR/liveness-unused.rs:47:13
Expand Down Expand Up @@ -106,6 +107,8 @@ error: value assigned to `x` is never read
|
LL | x = 0; //~ ERROR value assigned to `x` is never read
| ^
|
= help: maybe it is overwritten before being read?

error: aborting due to 13 previous errors