diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2017-09-16 09:16:58 -0500 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2017-09-16 17:09:40 -0700 |
| commit | c4f29d4cc5276b052801ccf2f7f2bd80fa5c050d (patch) | |
| tree | c34cd1776b72e18ad387f8b12c91f580fec143e0 | |
| parent | 0d88bb9c7fb4a0d1b0731103d07aad364d7aea2b (diff) | |
| parent | 1b571a0cfcf666c1365c51a2a78be7becf0ce5ba (diff) | |
| download | rust-c4f29d4cc5276b052801ccf2f7f2bd80fa5c050d.tar.gz rust-c4f29d4cc5276b052801ccf2f7f2bd80fa5c050d.zip | |
Rollup merge of #44590 - oli-obk:allow_unused_mut_on_vars, r=eddyb
Get `allow(unused_mut)` to work on `let` bindings fixes #40491
| -rw-r--r-- | src/librustc_lint/unused.rs | 16 | ||||
| -rw-r--r-- | src/test/compile-fail/lint-unused-mut-variables.rs | 8 |
2 files changed, 12 insertions, 12 deletions
diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index 91646ce9f8b..439cc3a4b84 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -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, diff --git a/src/test/compile-fail/lint-unused-mut-variables.rs b/src/test/compile-fail/lint-unused-mut-variables.rs index 26d00755da3..3c76740d2b5 100644 --- a/src/test/compile-fail/lint-unused-mut-variables.rs +++ b/src/test/compile-fail/lint-unused-mut-variables.rs @@ -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 +} |
