1
Fork 0

Rollup merge of #138434 - compiler-errors:lint-level-pat-field, r=jieyouxu

Visit `PatField` when collecting lint levels

Fixes #138428

Side-note, I vaguely skimmed over the other nodes we could be visiting here and it doesn't *seem* to me that we're missing anything, though I may be mistaken given recent(?) support for attrs in where clauses(??). Can be fixed in a follow-up PR.
This commit is contained in:
Jacob Pratt 2025-03-14 01:37:34 -04:00 committed by GitHub
commit fb2a7fa209
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 0 deletions

View file

@ -299,6 +299,11 @@ impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, LintLevelQueryMap<'tcx>> {
intravisit::walk_expr(self, e);
}
fn visit_pat_field(&mut self, f: &'tcx hir::PatField<'tcx>) -> Self::Result {
self.add_id(f.hir_id);
intravisit::walk_pat_field(self, f);
}
fn visit_expr_field(&mut self, f: &'tcx hir::ExprField<'tcx>) {
self.add_id(f.hir_id);
intravisit::walk_expr_field(self, f);

View file

@ -0,0 +1,21 @@
//@ check-pass
// Ensure we collect lint levels from pat fields in structs.
#![deny(unused_variables)]
pub struct Foo {
bar: u32,
baz: u32,
}
pub fn test(foo: Foo) {
let Foo {
#[allow(unused_variables)]
bar,
#[allow(unused_variables)]
baz,
} = foo;
}
fn main() {}