Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn unused_assignments for arguments #29536

Merged
merged 1 commit into from
Nov 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {}