Skip to content

Commit c655f17

Browse files
committed
Add missing visit_pat_field in early lint visitor.
This ensures that lint attributes on pattern fields can control early lints.
1 parent 7b36047 commit c655f17

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

compiler/rustc_lint/src/early.rs

+6
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
101101
run_early_pass!(self, check_pat_post, p);
102102
}
103103

104+
fn visit_pat_field(&mut self, field: &'a ast::PatField) {
105+
self.with_lint_attrs(field.id, &field.attrs, |cx| {
106+
ast_visit::walk_pat_field(cx, field);
107+
});
108+
}
109+
104110
fn visit_anon_const(&mut self, c: &'a ast::AnonConst) {
105111
self.check_id(c.id);
106112
ast_visit::walk_anon_const(self, c);

src/test/ui/lint/lint-attr-everywhere-early.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,18 @@ fn expressions() {
159159

160160
// ################## Patterns
161161
fn patterns() {
162-
// There aren't any early lints that I can find that apply to pattern fields.
163-
//
164-
// struct PatField{f1: i32, f2: i32};
165-
// let f = PatField{f1: 1, f2: 2};
166-
// let PatField{#[deny()]f1, #[deny()]..} = f;
162+
struct PatField{f1: i32, f2: i32};
163+
let f = PatField{f1: 1, f2: 2};
164+
match f {
165+
PatField {
166+
#[deny(ellipsis_inclusive_range_patterns)]
167+
f1: 0...100,
168+
//~^ ERROR range patterns are deprecated
169+
//~| WARNING this is accepted in the current edition
170+
..
171+
} => {}
172+
_ => {}
173+
}
167174
}
168175

169176
fn main() {}

src/test/ui/lint/lint-attr-everywhere-early.stderr

+15-1
Original file line numberDiff line numberDiff line change
@@ -468,5 +468,19 @@ note: the lint level is defined here
468468
LL | TupleStruct(#[deny(unsafe_code)] unsafe {123});
469469
| ^^^^^^^^^^^
470470

471-
error: aborting due to 35 previous errors
471+
error: `...` range patterns are deprecated
472+
--> $DIR/lint-attr-everywhere-early.rs:167:18
473+
|
474+
LL | f1: 0...100,
475+
| ^^^ help: use `..=` for an inclusive range
476+
|
477+
note: the lint level is defined here
478+
--> $DIR/lint-attr-everywhere-early.rs:166:20
479+
|
480+
LL | #[deny(ellipsis_inclusive_range_patterns)]
481+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
482+
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
483+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
484+
485+
error: aborting due to 36 previous errors
472486

0 commit comments

Comments
 (0)