1
Fork 0

Check attributes on pattern fields.

Attributes on pattern struct fields were not being checked for validity.
This adds the fields as HIR nodes so that the `CheckAttrVisitor` can
visit those nodes to check their attributes.
This commit is contained in:
Eric Huss 2022-05-03 11:52:53 -07:00
parent b998821e4c
commit 1b464c73b7
10 changed files with 64 additions and 22 deletions

View file

@ -193,6 +193,11 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
fn visit_pat(&mut self, pat: &'hir Pat<'hir>) {
self.insert(pat.span, pat.hir_id, Node::Pat(pat));
if let PatKind::Struct(_, fields, _) = pat.kind {
for field in fields {
self.insert(field.span, field.hir_id, Node::PatField(field));
}
}
self.with_parent(pat.hir_id, |this| {
intravisit::walk_pat(this, pat);

View file

@ -64,12 +64,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
);
let fs = self.arena.alloc_from_iter(fields.iter().map(|f| hir::PatField {
hir_id: self.next_id(),
ident: self.lower_ident(f.ident),
pat: self.lower_pat(&f.pat),
is_shorthand: f.is_shorthand,
span: self.lower_span(f.span),
let fs = self.arena.alloc_from_iter(fields.iter().map(|f| {
let hir_id = self.lower_node_id(f.id);
self.lower_attrs(hir_id, &f.attrs);
hir::PatField {
hir_id,
ident: self.lower_ident(f.ident),
pat: self.lower_pat(&f.pat),
is_shorthand: f.is_shorthand,
span: self.lower_span(f.span),
}
}));
break hir::PatKind::Struct(qpath, fs, etc);
}