diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 070ad5159086e..8e5f748c78e29 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 6b9cbabf20e97..45f90bf9037c5 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>(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 4f1c870d87457..d4c0eb21342fa 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