Skip to content

Commit

Permalink
Auto merge of #29536 - sanxiyn:unused-assign-arg, r=alexcrichton
Browse files Browse the repository at this point in the history
Fix #29136.
  • Loading branch information
bors committed Nov 4, 2015
2 parents 8fa8684 + 61e5b6d commit 4ee11cd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,11 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
// Ignore unused self.
let name = path1.node;
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);
}
}
}
})
}
Expand Down Expand Up @@ -1609,11 +1613,19 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
ln: LiveNode,
var: Variable) {
if self.live_on_exit(ln, var).is_none() {
let r = self.should_warn(var);
if let Some(name) = r {
self.report_dead_assign(id, sp, var, false);
}
}

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,
format!("value assigned to `{}` is never read", name));
}
}
}
}
}
10 changes: 10 additions & 0 deletions src/test/compile-fail/liveness-dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,14 @@ fn f3() {
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() {}

0 comments on commit 4ee11cd

Please sign in to comment.