Skip to content
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
16 changes: 4 additions & 12 deletions src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,12 @@ impl LintPass for UnusedMut {
}

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedMut {
fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) {
if let hir::ExprMatch(_, ref arms, _) = e.node {
for a in arms {
self.check_unused_mut_pat(cx, &a.pats)
}
}
fn check_arm(&mut self, cx: &LateContext, a: &hir::Arm) {
self.check_unused_mut_pat(cx, &a.pats)
}

fn check_stmt(&mut self, cx: &LateContext, s: &hir::Stmt) {
if let hir::StmtDecl(ref d, _) = s.node {
if let hir::DeclLocal(ref l) = d.node {
self.check_unused_mut_pat(cx, slice::ref_slice(&l.pat));
}
}
fn check_local(&mut self, cx: &LateContext, l: &hir::Local) {
self.check_unused_mut_pat(cx, slice::ref_slice(&l.pat));
}

fn check_fn(&mut self,
Expand Down
8 changes: 8 additions & 0 deletions src/test/compile-fail/lint-unused-mut-variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,11 @@ fn foo(mut a: isize) {
let mut a = 3;
let mut b = vec![2];
}

// make sure the lint attribute can be turned off on let statements
#[deny(unused_mut)]
fn bar() {
#[allow(unused_mut)]
let mut a = 3;
let mut b = vec![2]; //~ ERROR: variable does not need to be mutable
}