inline associated_body

Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
This commit is contained in:
Miguel Guarniz 2022-07-06 18:23:38 -04:00
parent c6e7c0514f
commit b599cf45d6

View File

@ -39,6 +39,7 @@ pub fn fn_sig<'hir>(node: Node<'hir>) -> Option<&'hir FnSig<'hir>> {
}
}
#[inline]
pub fn associated_body<'hir>(node: Node<'hir>) -> Option<BodyId> {
match node {
Node::Item(Item {
@ -1292,27 +1293,19 @@ pub(super) fn hir_module_items(tcx: TyCtxt<'_>, module_id: LocalDefId) -> Module
}
fn visit_foreign_item(&mut self, item: &'hir ForeignItem<'hir>) {
if associated_body(Node::ForeignItem(item)).is_some() {
self.body_owners.push(item.def_id);
}
self.foreign_items.push(item.foreign_item_id());
intravisit::walk_foreign_item(self, item)
}
fn visit_expr(&mut self, ex: &'hir Expr<'hir>) {
if matches!(ex.kind, ExprKind::Closure { .. })
&& associated_body(Node::Expr(ex)).is_some()
{
if matches!(ex.kind, ExprKind::Closure { .. }) {
self.body_owners.push(self.tcx.hir().local_def_id(ex.hir_id));
}
intravisit::walk_expr(self, ex)
}
fn visit_anon_const(&mut self, c: &'hir AnonConst) {
if associated_body(Node::AnonConst(c)).is_some() {
self.body_owners.push(self.tcx.hir().local_def_id(c.hir_id));
}
self.body_owners.push(self.tcx.hir().local_def_id(c.hir_id));
intravisit::walk_anon_const(self, c)
}
}
@ -1382,10 +1375,6 @@ pub(crate) fn hir_crate_items(tcx: TyCtxt<'_>, _: ()) -> ModuleItems {
}
fn visit_foreign_item(&mut self, item: &'hir ForeignItem<'hir>) {
if associated_body(Node::ForeignItem(item)).is_some() {
self.body_owners.push(item.def_id);
}
self.foreign_items.push(item.foreign_item_id());
intravisit::walk_foreign_item(self, item)
}
@ -1409,18 +1398,14 @@ pub(crate) fn hir_crate_items(tcx: TyCtxt<'_>, _: ()) -> ModuleItems {
}
fn visit_expr(&mut self, ex: &'hir Expr<'hir>) {
if matches!(ex.kind, ExprKind::Closure { .. })
&& associated_body(Node::Expr(ex)).is_some()
{
if matches!(ex.kind, ExprKind::Closure { .. }) {
self.body_owners.push(self.tcx.hir().local_def_id(ex.hir_id));
}
intravisit::walk_expr(self, ex)
}
fn visit_anon_const(&mut self, c: &'hir AnonConst) {
if associated_body(Node::AnonConst(c)).is_some() {
self.body_owners.push(self.tcx.hir().local_def_id(c.hir_id));
}
self.body_owners.push(self.tcx.hir().local_def_id(c.hir_id));
intravisit::walk_anon_const(self, c)
}
}