Skip to content

Commit 1b571a0

Browse files
committed
Get allow(unused_mut) to work on let bindings
fixes #40491
1 parent d86a7f7 commit 1b571a0

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/librustc_lint/unused.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,12 @@ impl LintPass for UnusedMut {
8585
}
8686

8787
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedMut {
88-
fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) {
89-
if let hir::ExprMatch(_, ref arms, _) = e.node {
90-
for a in arms {
91-
self.check_unused_mut_pat(cx, &a.pats)
92-
}
93-
}
88+
fn check_arm(&mut self, cx: &LateContext, a: &hir::Arm) {
89+
self.check_unused_mut_pat(cx, &a.pats)
9490
}
9591

96-
fn check_stmt(&mut self, cx: &LateContext, s: &hir::Stmt) {
97-
if let hir::StmtDecl(ref d, _) = s.node {
98-
if let hir::DeclLocal(ref l) = d.node {
99-
self.check_unused_mut_pat(cx, slice::ref_slice(&l.pat));
100-
}
101-
}
92+
fn check_local(&mut self, cx: &LateContext, l: &hir::Local) {
93+
self.check_unused_mut_pat(cx, slice::ref_slice(&l.pat));
10294
}
10395

10496
fn check_fn(&mut self,

src/test/compile-fail/lint-unused-mut-variables.rs

+8
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,11 @@ fn foo(mut a: isize) {
110110
let mut a = 3;
111111
let mut b = vec![2];
112112
}
113+
114+
// make sure the lint attribute can be turned off on let statements
115+
#[deny(unused_mut)]
116+
fn bar() {
117+
#[allow(unused_mut)]
118+
let mut a = 3;
119+
let mut b = vec![2]; //~ ERROR: variable does not need to be mutable
120+
}

0 commit comments

Comments
 (0)