Warn unused_assignments for arguments

This commit is contained in:
Seo Sanghyeon 2015-11-03 19:04:36 +09:00
parent b7fbfb658e
commit 61e5b6dfdb
2 changed files with 26 additions and 4 deletions

View File

@ -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));
} }
} }
} }
} }

View File

@ -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() {}