Warn unused_assignments for arguments
This commit is contained in:
parent
b7fbfb658e
commit
61e5b6dfdb
@ -1555,7 +1555,11 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||||||
// Ignore unused self.
|
// Ignore unused self.
|
||||||
let name = path1.node;
|
let name = path1.node;
|
||||||
if name != special_idents::self_.name {
|
if name != special_idents::self_.name {
|
||||||
self.warn_about_unused(sp, p_id, entry_ln, var);
|
if !self.warn_about_unused(sp, p_id, entry_ln, var) {
|
||||||
|
if self.live_on_entry(entry_ln, var).is_none() {
|
||||||
|
self.report_dead_assign(p_id, sp, var, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1609,11 +1613,19 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||||||
ln: LiveNode,
|
ln: LiveNode,
|
||||||
var: Variable) {
|
var: Variable) {
|
||||||
if self.live_on_exit(ln, var).is_none() {
|
if self.live_on_exit(ln, var).is_none() {
|
||||||
let r = self.should_warn(var);
|
self.report_dead_assign(id, sp, var, false);
|
||||||
if let Some(name) = r {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn report_dead_assign(&self, id: NodeId, sp: Span, var: Variable, is_argument: bool) {
|
||||||
|
if let Some(name) = self.should_warn(var) {
|
||||||
|
if is_argument {
|
||||||
|
self.ir.tcx.sess.add_lint(lint::builtin::UNUSED_ASSIGNMENTS, id, sp,
|
||||||
|
format!("value passed to `{}` is never read", name));
|
||||||
|
} else {
|
||||||
self.ir.tcx.sess.add_lint(lint::builtin::UNUSED_ASSIGNMENTS, id, sp,
|
self.ir.tcx.sess.add_lint(lint::builtin::UNUSED_ASSIGNMENTS, id, sp,
|
||||||
format!("value assigned to `{}` is never read", name));
|
format!("value assigned to `{}` is never read", name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,4 +27,14 @@ fn f3() {
|
|||||||
x = 4; //~ ERROR: value assigned to `x` is never read
|
x = 4; //~ ERROR: value assigned to `x` is never read
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn f4(mut x: i32) { //~ ERROR: value passed to `x` is never read
|
||||||
|
x = 4;
|
||||||
|
x.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn f5(mut x: i32) {
|
||||||
|
x.clone();
|
||||||
|
x = 4; //~ ERROR: value assigned to `x` is never read
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
Loading…
Reference in New Issue
Block a user