Auto merge of #43850 - GuillaumeGomez:unused-variable-lint, r=arielb1
Add a note to unused variables Fixes #26720.
This commit is contained in:
commit
c88624682d
3 changed files with 19 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -1840,6 +1840,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)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue