diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2025-03-14 01:37:34 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-14 01:37:34 -0400 |
| commit | fb2a7fa209709545bd7f8458ff8618da03ab00eb (patch) | |
| tree | bdd6720f53c083bcca5b908cd16ff94ca5146444 | |
| parent | e928a8f4a05c63ca5e9031741b0ee51e2254f92d (diff) | |
| parent | 8bf33c213fe752a5a9f6fbc2594316dcbdd5a262 (diff) | |
| download | rust-fb2a7fa209709545bd7f8458ff8618da03ab00eb.tar.gz rust-fb2a7fa209709545bd7f8458ff8618da03ab00eb.zip | |
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.
| -rw-r--r-- | compiler/rustc_lint/src/levels.rs | 5 | ||||
| -rw-r--r-- | tests/ui/lint/unused/unused-field-in-pat-field.rs | 21 |
2 files changed, 26 insertions, 0 deletions
diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index aa6eef906ea..8718fb807ec 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -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); diff --git a/tests/ui/lint/unused/unused-field-in-pat-field.rs b/tests/ui/lint/unused/unused-field-in-pat-field.rs new file mode 100644 index 00000000000..34959a1023f --- /dev/null +++ b/tests/ui/lint/unused/unused-field-in-pat-field.rs @@ -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() {} |
