Skip to content

Commit e784595

Browse files
committed
Respect lint attributes on match arms
1 parent 4bfb045 commit e784595

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

src/librustc/lint/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,12 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for LintLevelMapBuilder<'a, 'tcx> {
852852
})
853853
}
854854

855+
fn visit_arm(&mut self, a: &'tcx hir::Arm) {
856+
self.with_lint_attrs(a.hir_id, &a.attrs, |builder| {
857+
intravisit::walk_arm(builder, a);
858+
})
859+
}
860+
855861
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) {
856862
self.with_lint_attrs(trait_item.hir_id, &trait_item.attrs, |builder| {
857863
intravisit::walk_trait_item(builder, trait_item);

src/test/ui/lint/lint-match-arms.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
fn deny_on_arm() {
2+
match 0 {
3+
#[deny(unused_variables)]
4+
//~^ NOTE lint level defined here
5+
y => (),
6+
//~^ ERROR unused variable
7+
}
8+
}
9+
10+
#[deny(unused_variables)]
11+
fn allow_on_arm() {
12+
match 0 {
13+
#[allow(unused_variables)]
14+
y => (), // OK
15+
}
16+
}
17+
18+
fn main() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: unused variable: `y`
2+
--> $DIR/lint-match-arms.rs:5:9
3+
|
4+
LL | y => (),
5+
| ^ help: consider prefixing with an underscore: `_y`
6+
|
7+
note: lint level defined here
8+
--> $DIR/lint-match-arms.rs:3:16
9+
|
10+
LL | #[deny(unused_variables)]
11+
| ^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+

0 commit comments

Comments
 (0)