From eaeebb55e1962aa12f70165d8bd09c2eb823dfca Mon Sep 17 00:00:00 2001 From: John Ginger Date: Sun, 2 Dec 2018 15:40:24 +0000 Subject: [PATCH 1/5] Clearer error message for dead assign --- src/librustc/middle/liveness.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 54a0192d2e8a5..92c4077946feb 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -1658,10 +1658,10 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { 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)); + &format!("value passed to `{}` is never read (maybe it is overwritten before being read)", name)); } else { self.ir.tcx.lint_hir(lint::builtin::UNUSED_ASSIGNMENTS, hir_id, sp, - &format!("value assigned to `{}` is never read", name)); + &format!("value assigned to `{}` is never read (maybe it is overwritten before being read)", name)); } } } From 54026c14cf94230531c24bb52e84f549b3e3dea9 Mon Sep 17 00:00:00 2001 From: John Ginger Date: Sun, 2 Dec 2018 16:35:51 +0000 Subject: [PATCH 2/5] Fix line length --- src/librustc/middle/liveness.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 92c4077946feb..b154077adb75f 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -1658,10 +1658,12 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { 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 (maybe it is overwritten before being read)", name)); + &format!("value passed to `{}` is never read + (maybe it is overwritten before being read)", name)); } else { self.ir.tcx.lint_hir(lint::builtin::UNUSED_ASSIGNMENTS, hir_id, sp, - &format!("value assigned to `{}` is never read (maybe it is overwritten before being read)", name)); + &format!("value assigned to `{}` is never read + (maybe it is overwritten before being read)", name)); } } } From 4cf5702d527aabc225cb77683e28c8d8600a7e1b Mon Sep 17 00:00:00 2001 From: John Ginger Date: Mon, 3 Dec 2018 10:28:19 +0000 Subject: [PATCH 3/5] Fix stderr files --- src/test/ui/liveness/liveness-dead.stderr | 4 ++++ src/test/ui/liveness/liveness-unused.stderr | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/test/ui/liveness/liveness-dead.stderr b/src/test/ui/liveness/liveness-dead.stderr index 6709fee0abb72..4237995c3f1bf 100644 --- a/src/test/ui/liveness/liveness-dead.stderr +++ b/src/test/ui/liveness/liveness-dead.stderr @@ -1,4 +1,5 @@ error: value assigned to `x` is never read + (maybe it is overwritten before being read) --> $DIR/liveness-dead.rs:19:13 | LL | let mut x: isize = 3; //~ ERROR: value assigned to `x` is never read @@ -11,18 +12,21 @@ LL | #![deny(unused_assignments)] | ^^^^^^^^^^^^^^^^^^ error: value assigned to `x` is never read + (maybe it is overwritten before being read) --> $DIR/liveness-dead.rs:27:5 | LL | x = 4; //~ ERROR: value assigned to `x` is never read | ^ error: value passed to `x` is never read + (maybe it is overwritten before being read) --> $DIR/liveness-dead.rs:30:11 | LL | fn f4(mut x: i32) { //~ ERROR: value passed to `x` is never read | ^ error: value assigned to `x` is never read + (maybe it is overwritten before being read) --> $DIR/liveness-dead.rs:37:5 | LL | x = 4; //~ ERROR: value assigned to `x` is never read diff --git a/src/test/ui/liveness/liveness-unused.stderr b/src/test/ui/liveness/liveness-unused.stderr index 2846f242fbe4c..b9f4ad7b95a67 100644 --- a/src/test/ui/liveness/liveness-unused.stderr +++ b/src/test/ui/liveness/liveness-unused.stderr @@ -50,6 +50,7 @@ LL | let mut x = 3; = note: consider using `_x` instead error: value assigned to `x` is never read + (maybe it is overwritten before being read) --> $DIR/liveness-unused.rs:42:5 | LL | x += 4; @@ -102,6 +103,7 @@ LL | let x; = note: consider using `_x` instead error: value assigned to `x` is never read + (maybe it is overwritten before being read) --> $DIR/liveness-unused.rs:126:9 | LL | x = 0; //~ ERROR value assigned to `x` is never read From 70536d4b4c8287925ccc4a8255f3d42c70aed6e3 Mon Sep 17 00:00:00 2001 From: John Ginger Date: Mon, 3 Dec 2018 22:53:03 +0000 Subject: [PATCH 4/5] Fix stderr file (unused variable) --- .../ui/lint/issue-47390-unused-variable-in-struct-pattern.stderr | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.stderr b/src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.stderr index a8b0e3e4250ea..aea46e4e96cb5 100644 --- a/src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.stderr +++ b/src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.stderr @@ -44,6 +44,7 @@ LL | mut hours_are_suns, = note: consider using `_hours_are_suns` instead warning: value assigned to `hours_are_suns` is never read + (maybe it is overwritten before being read) --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:50:9 | LL | hours_are_suns = false; From c0e3f4b8bbf10cc308823c98913b942b75c6a543 Mon Sep 17 00:00:00 2001 From: John Ginger Date: Fri, 7 Dec 2018 14:15:36 +0000 Subject: [PATCH 5/5] Change to give a help message --- src/librustc/middle/liveness.rs | 14 ++++++++------ ...-47390-unused-variable-in-struct-pattern.stderr | 2 +- src/test/ui/liveness/liveness-dead.stderr | 11 +++++++---- src/test/ui/liveness/liveness-unused.stderr | 5 +++-- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index b154077adb75f..2136cd27e4306 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -1657,13 +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 - (maybe it is overwritten before being 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 - (maybe it is overwritten before being 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(); } } } diff --git a/src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.stderr b/src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.stderr index aea46e4e96cb5..6b9e1dc70573e 100644 --- a/src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.stderr +++ b/src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.stderr @@ -44,7 +44,6 @@ LL | mut hours_are_suns, = note: consider using `_hours_are_suns` instead warning: value assigned to `hours_are_suns` is never read - (maybe it is overwritten before being read) --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:50:9 | LL | hours_are_suns = false; @@ -56,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 diff --git a/src/test/ui/liveness/liveness-dead.stderr b/src/test/ui/liveness/liveness-dead.stderr index 4237995c3f1bf..6e43cccdccff2 100644 --- a/src/test/ui/liveness/liveness-dead.stderr +++ b/src/test/ui/liveness/liveness-dead.stderr @@ -1,5 +1,4 @@ error: value assigned to `x` is never read - (maybe it is overwritten before being read) --> $DIR/liveness-dead.rs:19:13 | LL | let mut x: isize = 3; //~ ERROR: value assigned to `x` is never read @@ -10,27 +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 - (maybe it is overwritten before being 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 - (maybe it is overwritten before being 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 - (maybe it is overwritten before being 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 diff --git a/src/test/ui/liveness/liveness-unused.stderr b/src/test/ui/liveness/liveness-unused.stderr index b9f4ad7b95a67..35ccc79a19ac0 100644 --- a/src/test/ui/liveness/liveness-unused.stderr +++ b/src/test/ui/liveness/liveness-unused.stderr @@ -50,7 +50,6 @@ LL | let mut x = 3; = note: consider using `_x` instead error: value assigned to `x` is never read - (maybe it is overwritten before being read) --> $DIR/liveness-unused.rs:42:5 | LL | x += 4; @@ -61,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 @@ -103,11 +103,12 @@ LL | let x; = note: consider using `_x` instead error: value assigned to `x` is never read - (maybe it is overwritten before being read) --> $DIR/liveness-unused.rs:126:9 | 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