1
Fork 0

Add missing visit_pat_field in early lint visitor.

This ensures that lint attributes on pattern fields can control
early lints.
This commit is contained in:
Eric Huss 2022-07-05 18:27:21 -07:00
parent 7b36047239
commit c655f17bce
3 changed files with 33 additions and 6 deletions

View file

@ -101,6 +101,12 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
run_early_pass!(self, check_pat_post, p);
}
fn visit_pat_field(&mut self, field: &'a ast::PatField) {
self.with_lint_attrs(field.id, &field.attrs, |cx| {
ast_visit::walk_pat_field(cx, field);
});
}
fn visit_anon_const(&mut self, c: &'a ast::AnonConst) {
self.check_id(c.id);
ast_visit::walk_anon_const(self, c);

View file

@ -159,11 +159,18 @@ fn expressions() {
// ################## Patterns
fn patterns() {
// There aren't any early lints that I can find that apply to pattern fields.
//
// struct PatField{f1: i32, f2: i32};
// let f = PatField{f1: 1, f2: 2};
// let PatField{#[deny()]f1, #[deny()]..} = f;
struct PatField{f1: i32, f2: i32};
let f = PatField{f1: 1, f2: 2};
match f {
PatField {
#[deny(ellipsis_inclusive_range_patterns)]
f1: 0...100,
//~^ ERROR range patterns are deprecated
//~| WARNING this is accepted in the current edition
..
} => {}
_ => {}
}
}
fn main() {}

View file

@ -468,5 +468,19 @@ note: the lint level is defined here
LL | TupleStruct(#[deny(unsafe_code)] unsafe {123});
| ^^^^^^^^^^^
error: aborting due to 35 previous errors
error: `...` range patterns are deprecated
--> $DIR/lint-attr-everywhere-early.rs:167:18
|
LL | f1: 0...100,
| ^^^ help: use `..=` for an inclusive range
|
note: the lint level is defined here
--> $DIR/lint-attr-everywhere-early.rs:166:20
|
LL | #[deny(ellipsis_inclusive_range_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
error: aborting due to 36 previous errors