diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2017-08-13 20:07:09 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2017-08-16 13:53:47 +0200 |
| commit | 9b0607ab4e2d560e6547da1de9d3cd5ed2c3d4fd (patch) | |
| tree | c1184172a59417c470f7db5a13b537be674f196f /src | |
| parent | b6179602bea71607a9ea63197eca423fcce5f7b0 (diff) | |
| download | rust-9b0607ab4e2d560e6547da1de9d3cd5ed2c3d4fd.tar.gz rust-9b0607ab4e2d560e6547da1de9d3cd5ed2c3d4fd.zip | |
Add a note to unused variables
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/middle/liveness.rs | 10 | ||||
| -rw-r--r-- | src/librustc/ty/context.rs | 11 | ||||
| -rw-r--r-- | src/test/ui/span/issue-24690.stderr | 1 |
3 files changed, 19 insertions, 3 deletions
diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 070ad515908..8e5f748c78e 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -1482,12 +1482,16 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { }; if is_assigned { - self.ir.tcx.lint_node(lint::builtin::UNUSED_VARIABLES, id, sp, + self.ir.tcx.lint_node_note(lint::builtin::UNUSED_VARIABLES, id, sp, &format!("variable `{}` is assigned to, but never used", + name), + &format!("to disable this warning, consider using `_{}` instead", name)); } else if name != "self" { - self.ir.tcx.lint_node(lint::builtin::UNUSED_VARIABLES, id, sp, - &format!("unused variable: `{}`", name)); + self.ir.tcx.lint_node_note(lint::builtin::UNUSED_VARIABLES, id, sp, + &format!("unused variable: `{}`", name), + &format!("to disable this warning, consider using `_{}` instead", + name)); } } true diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 6b9cbabf20e..45f90bf9037 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -1522,6 +1522,17 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { self.struct_span_lint_node(lint, id, span.into(), msg).emit() } + pub fn lint_node_note<S: Into<MultiSpan>>(self, + lint: &'static Lint, + id: NodeId, + span: S, + msg: &str, + note: &str) { + let mut err = self.struct_span_lint_node(lint, id, span.into(), msg); + err.note(note); + err.emit() + } + pub fn lint_level_at_node(self, lint: &'static Lint, mut id: NodeId) -> (lint::Level, lint::LintSource) { diff --git a/src/test/ui/span/issue-24690.stderr b/src/test/ui/span/issue-24690.stderr index 4f1c870d874..d4c0eb21342 100644 --- a/src/test/ui/span/issue-24690.stderr +++ b/src/test/ui/span/issue-24690.stderr @@ -10,6 +10,7 @@ note: lint level defined here 18 | #![warn(unused)] | ^^^^^^ = note: #[warn(unused_variables)] implied by #[warn(unused)] + = note: to disable this warning, consider using `_theOtherTwo` instead warning: variable `theTwo` should have a snake case name such as `the_two` --> $DIR/issue-24690.rs:22:9 |
