1
Fork 0

ast: Generalize item kind visiting

And avoid duplicating logic for visiting `Item`s with different kinds (regular, associated, foreign).
This commit is contained in:
Vadim Petrochenkov 2024-04-24 20:31:51 +03:00
parent 38dd569150
commit 5be9fdd636
18 changed files with 410 additions and 382 deletions

View file

@ -1339,7 +1339,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
}
self.build_reduced_graph_for_foreign_item(foreign_item);
visit::walk_foreign_item(self, foreign_item);
visit::walk_item(self, foreign_item);
}
fn visit_block(&mut self, block: &'b Block) {

View file

@ -224,7 +224,7 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
let def = self.create_def(fi.id, fi.ident.name, def_kind, fi.span);
self.with_parent(def, |this| visit::walk_foreign_item(this, fi));
self.with_parent(def, |this| visit::walk_item(this, fi));
}
fn visit_variant(&mut self, v: &'a Variant) {

View file

@ -886,7 +886,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
kind: LifetimeBinderKind::Item,
span: generics.span,
},
|this| visit::walk_foreign_item(this, foreign_item),
|this| visit::walk_item(this, foreign_item),
);
}
ForeignItemKind::Fn(box Fn { ref generics, .. }) => {
@ -898,13 +898,11 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
kind: LifetimeBinderKind::Function,
span: generics.span,
},
|this| visit::walk_foreign_item(this, foreign_item),
|this| visit::walk_item(this, foreign_item),
);
}
ForeignItemKind::Static(..) => {
self.with_static_rib(def_kind, |this| {
visit::walk_foreign_item(this, foreign_item);
});
self.with_static_rib(def_kind, |this| visit::walk_item(this, foreign_item))
}
ForeignItemKind::MacCall(..) => {
panic!("unexpanded macro in resolve!")