Respect lint attributes on match arms
This commit is contained in:
parent
4bfb0453f5
commit
e784595c28
@ -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);
|
||||
|
18
src/test/ui/lint/lint-match-arms.rs
Normal file
18
src/test/ui/lint/lint-match-arms.rs
Normal file
@ -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() {}
|
14
src/test/ui/lint/lint-match-arms.stderr
Normal file
14
src/test/ui/lint/lint-match-arms.stderr
Normal file
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user