]> git.lizzy.rs Git - rust.git/commitdiff
Respect lint attributes on match arms
authorMatthew Jasper <mjjasper1@gmail.com>
Sat, 30 Mar 2019 23:00:07 +0000 (23:00 +0000)
committerMatthew Jasper <mjjasper1@gmail.com>
Tue, 21 May 2019 18:37:38 +0000 (19:37 +0100)
src/librustc/lint/mod.rs
src/test/ui/lint/lint-match-arms.rs [new file with mode: 0644]
src/test/ui/lint/lint-match-arms.stderr [new file with mode: 0644]

index 9c4683e094634eea384d348ff8c2b9785a6c6dfe..512e4d434434ce892a52f9050036e9ba0ac8359e 100644 (file)
@@ -852,6 +852,12 @@ fn visit_local(&mut self, l: &'tcx hir::Local) {
         })
     }
 
+    fn visit_arm(&mut self, a: &'tcx hir::Arm) {
+        self.with_lint_attrs(a.hir_id, &a.attrs, |builder| {
+            intravisit::walk_arm(builder, a);
+        })
+    }
+
     fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) {
         self.with_lint_attrs(trait_item.hir_id, &trait_item.attrs, |builder| {
             intravisit::walk_trait_item(builder, trait_item);
diff --git a/src/test/ui/lint/lint-match-arms.rs b/src/test/ui/lint/lint-match-arms.rs
new file mode 100644 (file)
index 0000000..2c471a6
--- /dev/null
@@ -0,0 +1,18 @@
+fn deny_on_arm() {
+    match 0 {
+        #[deny(unused_variables)]
+        //~^ NOTE lint level defined here
+        y => (),
+        //~^ ERROR unused variable
+    }
+}
+
+#[deny(unused_variables)]
+fn allow_on_arm() {
+    match 0 {
+        #[allow(unused_variables)]
+        y => (), // OK
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/lint/lint-match-arms.stderr b/src/test/ui/lint/lint-match-arms.stderr
new file mode 100644 (file)
index 0000000..e4e3ada
--- /dev/null
@@ -0,0 +1,14 @@
+error: unused variable: `y`
+  --> $DIR/lint-match-arms.rs:5:9
+   |
+LL |         y => (),
+   |         ^ help: consider prefixing with an underscore: `_y`
+   |
+note: lint level defined here
+  --> $DIR/lint-match-arms.rs:3:16
+   |
+LL |         #[deny(unused_variables)]
+   |                ^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+