about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthew Jasper <mjjasper1@gmail.com>2019-03-30 23:00:07 +0000
committerMatthew Jasper <mjjasper1@gmail.com>2019-05-21 19:37:38 +0100
commite784595c280da04c98e76a5ce9d603b58f6a88e2 (patch)
tree3e9f3f6f4ce545e9adeddba2cfde48b6e2b8b9fb
parent4bfb0453f537b2927574f29bdf90c9a22ea98add (diff)
Respect lint attributes on match arms
-rw-r--r--src/librustc/lint/mod.rs6
-rw-r--r--src/test/ui/lint/lint-match-arms.rs18
-rw-r--r--src/test/ui/lint/lint-match-arms.stderr14
3 files changed, 38 insertions, 0 deletions
diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs
index 9c4683e0946..512e4d43443 100644
--- a/src/librustc/lint/mod.rs
+++ b/src/librustc/lint/mod.rs
@@ -852,6 +852,12 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for LintLevelMapBuilder<'a, 'tcx> {
         })
     }
 
+    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
index 00000000000..2c471a61054
--- /dev/null
+++ b/src/test/ui/lint/lint-match-arms.rs
@@ -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
index 00000000000..e4e3adab0a9
--- /dev/null
+++ b/src/test/ui/lint/lint-match-arms.stderr
@@ -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
+