]> git.lizzy.rs Git - rust.git/commitdiff
Get `allow(unused_mut)` to work on `let` bindings
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Fri, 15 Sep 2017 08:36:14 +0000 (10:36 +0200)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Fri, 15 Sep 2017 08:36:14 +0000 (10:36 +0200)
fixes #40491

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

index 91646ce9f8b963ed58d4698d6ed319c5426f16f5..439cc3a4b844eafe0860a84c02e7d3e2545e03f2 100644 (file)
@@ -85,20 +85,12 @@ fn get_lints(&self) -> LintArray {
 }
 
 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,
index 26d00755da33b0f28d45971354fff0fc0f16cfc4..3c76740d2b5dd3ab8c080170abb0fbcf88588bd3 100644 (file)
@@ -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
+}