2019-12-23 22:02:53 -06:00
|
|
|
use rustc_data_structures::fx::FxHashMap;
|
2021-10-21 16:08:57 -05:00
|
|
|
use rustc_data_structures::sorted_map::SortedMap;
|
2020-01-04 19:37:57 -06:00
|
|
|
use rustc_hir as hir;
|
2021-02-28 11:58:50 -06:00
|
|
|
use rustc_hir::def_id::LocalDefId;
|
|
|
|
use rustc_hir::definitions;
|
2021-11-03 18:03:12 -05:00
|
|
|
use rustc_hir::intravisit::{self, Visitor};
|
2020-01-07 07:38:27 -06:00
|
|
|
use rustc_hir::*;
|
2020-02-10 10:00:49 -06:00
|
|
|
use rustc_index::vec::{Idx, IndexVec};
|
2021-07-05 15:26:23 -05:00
|
|
|
use rustc_middle::span_bug;
|
2021-02-28 11:58:50 -06:00
|
|
|
use rustc_session::Session;
|
2020-01-01 12:25:28 -06:00
|
|
|
use rustc_span::source_map::SourceMap;
|
2021-02-28 11:58:50 -06:00
|
|
|
use rustc_span::{Span, DUMMY_SP};
|
2015-09-10 14:53:08 -05:00
|
|
|
|
2021-09-11 20:19:18 -05:00
|
|
|
use tracing::debug;
|
2017-09-14 10:43:03 -05:00
|
|
|
|
2019-02-28 16:43:53 -06:00
|
|
|
/// A visitor that walks over the HIR and collects `Node`s into a HIR map.
|
2017-08-18 13:24:19 -05:00
|
|
|
pub(super) struct NodeCollector<'a, 'hir> {
|
2018-11-21 12:35:14 -06:00
|
|
|
/// Source map
|
|
|
|
source_map: &'a SourceMap,
|
2021-10-21 16:08:57 -05:00
|
|
|
bodies: &'a SortedMap<ItemLocalId, &'hir Body<'hir>>,
|
2018-11-21 12:35:14 -06:00
|
|
|
|
2021-09-11 20:19:18 -05:00
|
|
|
/// Outputs
|
|
|
|
nodes: IndexVec<ItemLocalId, Option<ParentedNode<'hir>>>,
|
2021-02-28 13:23:10 -06:00
|
|
|
parenting: FxHashMap<LocalDefId, ItemLocalId>,
|
2020-02-07 04:45:04 -06:00
|
|
|
|
2015-12-21 15:24:15 -06:00
|
|
|
/// The parent of this node
|
2021-02-28 13:23:10 -06:00
|
|
|
parent_node: hir::ItemLocalId,
|
2019-02-03 02:14:31 -06:00
|
|
|
|
2021-02-28 13:23:10 -06:00
|
|
|
owner: LocalDefId,
|
2017-08-18 13:24:19 -05:00
|
|
|
|
|
|
|
definitions: &'a definitions::Definitions,
|
2018-12-22 05:40:23 -06:00
|
|
|
}
|
|
|
|
|
2022-04-07 13:54:13 -05:00
|
|
|
#[tracing::instrument(level = "debug", skip(sess, definitions, bodies))]
|
2021-09-11 20:19:18 -05:00
|
|
|
pub(super) fn index_hir<'hir>(
|
|
|
|
sess: &Session,
|
|
|
|
definitions: &definitions::Definitions,
|
|
|
|
item: hir::OwnerNode<'hir>,
|
2021-10-21 16:08:57 -05:00
|
|
|
bodies: &SortedMap<ItemLocalId, &'hir Body<'hir>>,
|
2021-09-11 20:19:18 -05:00
|
|
|
) -> (IndexVec<ItemLocalId, Option<ParentedNode<'hir>>>, FxHashMap<LocalDefId, ItemLocalId>) {
|
2021-02-28 13:23:10 -06:00
|
|
|
let mut nodes = IndexVec::new();
|
2021-10-12 01:34:38 -05:00
|
|
|
// This node's parent should never be accessed: the owner's parent is computed by the
|
|
|
|
// hir_owner_parent query. Make it invalid (= ItemLocalId::MAX) to force an ICE whenever it is
|
|
|
|
// used.
|
|
|
|
nodes.push(Some(ParentedNode { parent: ItemLocalId::INVALID, node: item.into() }));
|
2021-02-28 13:23:10 -06:00
|
|
|
let mut collector = NodeCollector {
|
|
|
|
source_map: sess.source_map(),
|
|
|
|
definitions,
|
2021-09-11 20:19:18 -05:00
|
|
|
owner: item.def_id(),
|
|
|
|
parent_node: ItemLocalId::new(0),
|
|
|
|
nodes,
|
|
|
|
bodies,
|
2021-02-28 13:23:10 -06:00
|
|
|
parenting: FxHashMap::default(),
|
|
|
|
};
|
|
|
|
|
|
|
|
match item {
|
2022-03-18 16:13:38 -05:00
|
|
|
OwnerNode::Crate(citem) => {
|
|
|
|
collector.visit_mod(&citem, citem.spans.inner_span, hir::CRATE_HIR_ID)
|
|
|
|
}
|
2021-02-28 13:23:10 -06:00
|
|
|
OwnerNode::Item(item) => collector.visit_item(item),
|
|
|
|
OwnerNode::TraitItem(item) => collector.visit_trait_item(item),
|
|
|
|
OwnerNode::ImplItem(item) => collector.visit_impl_item(item),
|
|
|
|
OwnerNode::ForeignItem(item) => collector.visit_foreign_item(item),
|
|
|
|
};
|
|
|
|
|
2021-09-11 20:19:18 -05:00
|
|
|
(collector.nodes, collector.parenting)
|
2021-02-28 13:23:10 -06:00
|
|
|
}
|
2016-04-13 18:55:34 -05:00
|
|
|
|
2021-02-28 13:23:10 -06:00
|
|
|
impl<'a, 'hir> NodeCollector<'a, 'hir> {
|
2022-04-07 13:54:13 -05:00
|
|
|
#[tracing::instrument(level = "debug", skip(self))]
|
2019-02-15 03:30:44 -06:00
|
|
|
fn insert(&mut self, span: Span, hir_id: HirId, node: Node<'hir>) {
|
2021-02-28 13:23:10 -06:00
|
|
|
debug_assert_eq!(self.owner, hir_id.owner);
|
2021-03-27 07:21:26 -05:00
|
|
|
debug_assert_ne!(hir_id.local_id.as_u32(), 0);
|
2017-08-18 13:24:19 -05:00
|
|
|
|
|
|
|
// Make sure that the DepNode of some node coincides with the HirId
|
|
|
|
// owner of that node.
|
|
|
|
if cfg!(debug_assertions) {
|
2021-02-28 13:23:10 -06:00
|
|
|
if hir_id.owner != self.owner {
|
2021-07-05 15:26:23 -05:00
|
|
|
span_bug!(
|
|
|
|
span,
|
2021-09-11 20:19:18 -05:00
|
|
|
"inconsistent DepNode at `{:?}` for `{:?}`: \
|
2020-04-13 11:52:40 -05:00
|
|
|
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})",
|
2021-05-02 19:14:25 -05:00
|
|
|
self.source_map.span_to_diagnostic_string(span),
|
2021-09-11 20:19:18 -05:00
|
|
|
node,
|
2021-02-28 13:23:10 -06:00
|
|
|
self.definitions.def_path(self.owner).to_string_no_crate_verbose(),
|
|
|
|
self.owner,
|
2020-09-23 17:38:38 -05:00
|
|
|
self.definitions.def_path(hir_id.owner).to_string_no_crate_verbose(),
|
2018-10-11 03:15:18 -05:00
|
|
|
hir_id.owner,
|
2018-11-21 12:35:14 -06:00
|
|
|
)
|
2017-08-18 13:24:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-21 16:08:57 -05:00
|
|
|
self.nodes.insert(hir_id.local_id, ParentedNode { parent: self.parent_node, node: node });
|
2016-04-13 18:55:34 -05:00
|
|
|
}
|
2016-04-14 00:24:30 -05:00
|
|
|
|
2019-02-06 07:16:11 -06:00
|
|
|
fn with_parent<F: FnOnce(&mut Self)>(&mut self, parent_node_id: HirId, f: F) {
|
2021-02-28 13:23:10 -06:00
|
|
|
debug_assert_eq!(parent_node_id.owner, self.owner);
|
2019-02-15 08:21:56 -06:00
|
|
|
let parent_node = self.parent_node;
|
2021-02-28 13:23:10 -06:00
|
|
|
self.parent_node = parent_node_id.local_id;
|
2016-04-14 00:24:30 -05:00
|
|
|
f(self);
|
2019-02-15 08:21:56 -06:00
|
|
|
self.parent_node = parent_node;
|
2016-04-14 00:24:30 -05:00
|
|
|
}
|
2017-08-18 13:24:19 -05:00
|
|
|
|
2021-03-05 13:09:33 -06:00
|
|
|
fn insert_nested(&mut self, item: LocalDefId) {
|
2021-09-11 20:19:18 -05:00
|
|
|
self.parenting.insert(item, self.parent_node);
|
2021-03-05 13:09:33 -06:00
|
|
|
}
|
2016-04-13 18:55:34 -05:00
|
|
|
}
|
|
|
|
|
2021-02-28 13:23:10 -06:00
|
|
|
impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
2016-04-13 18:55:34 -05:00
|
|
|
/// Because we want to track parent items and so forth, enable
|
|
|
|
/// deep walking so that we walk nested items in the context of
|
|
|
|
/// their outer items.
|
2016-11-09 15:45:26 -06:00
|
|
|
|
2016-04-13 18:55:34 -05:00
|
|
|
fn visit_nested_item(&mut self, item: ItemId) {
|
|
|
|
debug!("visit_nested_item: {:?}", item);
|
2021-03-05 13:09:33 -06:00
|
|
|
self.insert_nested(item.def_id);
|
2016-04-13 18:55:34 -05:00
|
|
|
}
|
|
|
|
|
2016-12-03 20:21:06 -06:00
|
|
|
fn visit_nested_trait_item(&mut self, item_id: TraitItemId) {
|
2021-03-05 13:09:33 -06:00
|
|
|
self.insert_nested(item_id.def_id);
|
2016-12-03 20:21:06 -06:00
|
|
|
}
|
|
|
|
|
2016-11-04 17:20:15 -05:00
|
|
|
fn visit_nested_impl_item(&mut self, item_id: ImplItemId) {
|
2021-03-05 13:09:33 -06:00
|
|
|
self.insert_nested(item_id.def_id);
|
2016-11-04 17:20:15 -05:00
|
|
|
}
|
|
|
|
|
2020-11-11 14:57:54 -06:00
|
|
|
fn visit_nested_foreign_item(&mut self, foreign_id: ForeignItemId) {
|
2021-03-05 13:09:33 -06:00
|
|
|
self.insert_nested(foreign_id.def_id);
|
2020-11-11 14:57:54 -06:00
|
|
|
}
|
|
|
|
|
2016-12-21 04:32:59 -06:00
|
|
|
fn visit_nested_body(&mut self, id: BodyId) {
|
2021-02-28 13:23:10 -06:00
|
|
|
debug_assert_eq!(id.hir_id.owner, self.owner);
|
2021-10-21 16:08:57 -05:00
|
|
|
let body = self.bodies[&id.hir_id.local_id];
|
2021-02-28 13:23:10 -06:00
|
|
|
self.visit_body(body);
|
2016-10-28 15:58:32 -05:00
|
|
|
}
|
|
|
|
|
2019-11-29 06:43:03 -06:00
|
|
|
fn visit_param(&mut self, param: &'hir Param<'hir>) {
|
2019-08-27 06:24:32 -05:00
|
|
|
let node = Node::Param(param);
|
|
|
|
self.insert(param.pat.span, param.hir_id, node);
|
|
|
|
self.with_parent(param.hir_id, |this| {
|
|
|
|
intravisit::walk_param(this, param);
|
2019-07-26 17:52:37 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-07 13:54:13 -05:00
|
|
|
#[tracing::instrument(level = "debug", skip(self))]
|
2019-11-28 12:28:50 -06:00
|
|
|
fn visit_item(&mut self, i: &'hir Item<'hir>) {
|
2021-02-28 13:23:10 -06:00
|
|
|
debug_assert_eq!(i.def_id, self.owner);
|
|
|
|
self.with_parent(i.hir_id(), |this| {
|
2021-03-27 07:21:26 -05:00
|
|
|
if let ItemKind::Struct(ref struct_def, _) = i.kind {
|
|
|
|
// If this is a tuple or unit-like struct, register the constructor.
|
|
|
|
if let Some(ctor_hir_id) = struct_def.ctor_hir_id() {
|
|
|
|
this.insert(i.span, ctor_hir_id, Node::Ctor(struct_def));
|
2016-04-13 18:55:34 -05:00
|
|
|
}
|
2021-03-27 07:21:26 -05:00
|
|
|
}
|
|
|
|
intravisit::walk_item(this, i);
|
2016-04-14 00:24:30 -05:00
|
|
|
});
|
2016-04-13 18:55:34 -05:00
|
|
|
}
|
|
|
|
|
2022-04-07 13:54:13 -05:00
|
|
|
#[tracing::instrument(level = "debug", skip(self))]
|
2020-11-11 14:57:54 -06:00
|
|
|
fn visit_foreign_item(&mut self, fi: &'hir ForeignItem<'hir>) {
|
2021-02-28 13:23:10 -06:00
|
|
|
debug_assert_eq!(fi.def_id, self.owner);
|
|
|
|
self.with_parent(fi.hir_id(), |this| {
|
2021-03-27 07:21:26 -05:00
|
|
|
intravisit::walk_foreign_item(this, fi);
|
2016-04-14 00:24:30 -05:00
|
|
|
});
|
2016-04-13 18:55:34 -05:00
|
|
|
}
|
|
|
|
|
2019-11-30 10:46:46 -06:00
|
|
|
fn visit_generic_param(&mut self, param: &'hir GenericParam<'hir>) {
|
2021-03-23 16:47:22 -05:00
|
|
|
self.insert(param.span, param.hir_id, Node::GenericParam(param));
|
|
|
|
intravisit::walk_generic_param(self, param);
|
2016-04-13 18:55:34 -05:00
|
|
|
}
|
|
|
|
|
2021-03-01 05:50:09 -06:00
|
|
|
fn visit_const_param_default(&mut self, param: HirId, ct: &'hir AnonConst) {
|
2021-03-27 07:21:26 -05:00
|
|
|
self.with_parent(param, |this| {
|
|
|
|
intravisit::walk_const_param_default(this, ct);
|
|
|
|
})
|
2021-03-01 05:50:09 -06:00
|
|
|
}
|
|
|
|
|
2022-04-07 13:54:13 -05:00
|
|
|
#[tracing::instrument(level = "debug", skip(self))]
|
2019-11-28 14:47:10 -06:00
|
|
|
fn visit_trait_item(&mut self, ti: &'hir TraitItem<'hir>) {
|
2021-02-28 13:23:10 -06:00
|
|
|
debug_assert_eq!(ti.def_id, self.owner);
|
|
|
|
self.with_parent(ti.hir_id(), |this| {
|
2021-03-27 07:21:26 -05:00
|
|
|
intravisit::walk_trait_item(this, ti);
|
2016-04-14 00:24:30 -05:00
|
|
|
});
|
2016-04-13 18:55:34 -05:00
|
|
|
}
|
|
|
|
|
2022-04-07 13:54:13 -05:00
|
|
|
#[tracing::instrument(level = "debug", skip(self))]
|
2019-11-28 15:16:44 -06:00
|
|
|
fn visit_impl_item(&mut self, ii: &'hir ImplItem<'hir>) {
|
2021-02-28 13:23:10 -06:00
|
|
|
debug_assert_eq!(ii.def_id, self.owner);
|
|
|
|
self.with_parent(ii.hir_id(), |this| {
|
2021-03-27 07:21:26 -05:00
|
|
|
intravisit::walk_impl_item(this, ii);
|
2016-04-14 00:24:30 -05:00
|
|
|
});
|
2016-04-13 18:55:34 -05:00
|
|
|
}
|
|
|
|
|
2019-11-29 06:43:03 -06:00
|
|
|
fn visit_pat(&mut self, pat: &'hir Pat<'hir>) {
|
2022-06-28 13:15:30 -05:00
|
|
|
self.insert(pat.span, pat.hir_id, Node::Pat(pat));
|
2015-09-10 14:53:08 -05:00
|
|
|
|
2019-02-15 05:14:36 -06:00
|
|
|
self.with_parent(pat.hir_id, |this| {
|
2016-04-14 00:24:30 -05:00
|
|
|
intravisit::walk_pat(this, pat);
|
|
|
|
});
|
2015-09-10 14:53:08 -05:00
|
|
|
}
|
|
|
|
|
2019-11-29 06:43:03 -06:00
|
|
|
fn visit_arm(&mut self, arm: &'hir Arm<'hir>) {
|
2019-03-30 17:54:29 -05:00
|
|
|
let node = Node::Arm(arm);
|
|
|
|
|
|
|
|
self.insert(arm.span, arm.hir_id, node);
|
|
|
|
|
|
|
|
self.with_parent(arm.hir_id, |this| {
|
|
|
|
intravisit::walk_arm(this, arm);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-05-17 13:28:50 -05:00
|
|
|
fn visit_anon_const(&mut self, constant: &'hir AnonConst) {
|
2019-02-15 03:30:44 -06:00
|
|
|
self.insert(DUMMY_SP, constant.hir_id, Node::AnonConst(constant));
|
2018-05-17 13:28:50 -05:00
|
|
|
|
2019-02-15 05:14:36 -06:00
|
|
|
self.with_parent(constant.hir_id, |this| {
|
2018-05-17 13:28:50 -05:00
|
|
|
intravisit::walk_anon_const(this, constant);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-11-29 06:43:03 -06:00
|
|
|
fn visit_expr(&mut self, expr: &'hir Expr<'hir>) {
|
2019-02-15 03:30:44 -06:00
|
|
|
self.insert(expr.span, expr.hir_id, Node::Expr(expr));
|
2015-09-10 14:53:08 -05:00
|
|
|
|
2019-02-15 05:14:36 -06:00
|
|
|
self.with_parent(expr.hir_id, |this| {
|
2016-04-14 00:24:30 -05:00
|
|
|
intravisit::walk_expr(this, expr);
|
|
|
|
});
|
2015-09-10 14:53:08 -05:00
|
|
|
}
|
|
|
|
|
2019-11-29 06:43:03 -06:00
|
|
|
fn visit_stmt(&mut self, stmt: &'hir Stmt<'hir>) {
|
2019-02-15 03:30:44 -06:00
|
|
|
self.insert(stmt.span, stmt.hir_id, Node::Stmt(stmt));
|
2016-04-14 00:24:30 -05:00
|
|
|
|
2019-02-15 05:14:36 -06:00
|
|
|
self.with_parent(stmt.hir_id, |this| {
|
2016-04-14 00:24:30 -05:00
|
|
|
intravisit::walk_stmt(this, stmt);
|
|
|
|
});
|
2015-09-10 14:53:08 -05:00
|
|
|
}
|
|
|
|
|
2019-11-30 10:46:46 -06:00
|
|
|
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'hir PathSegment<'hir>) {
|
2019-02-15 08:21:56 -06:00
|
|
|
if let Some(hir_id) = path_segment.hir_id {
|
2019-02-15 03:30:44 -06:00
|
|
|
self.insert(path_span, hir_id, Node::PathSegment(path_segment));
|
2018-09-10 22:08:47 -05:00
|
|
|
}
|
|
|
|
intravisit::walk_path_segment(self, path_span, path_segment);
|
|
|
|
}
|
|
|
|
|
2019-11-30 10:46:46 -06:00
|
|
|
fn visit_ty(&mut self, ty: &'hir Ty<'hir>) {
|
2019-02-15 03:30:44 -06:00
|
|
|
self.insert(ty.span, ty.hir_id, Node::Ty(ty));
|
2016-08-05 19:12:20 -05:00
|
|
|
|
2019-02-15 05:14:36 -06:00
|
|
|
self.with_parent(ty.hir_id, |this| {
|
2016-08-05 19:12:20 -05:00
|
|
|
intravisit::walk_ty(this, ty);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-24 16:41:57 -05:00
|
|
|
fn visit_infer(&mut self, inf: &'hir InferArg) {
|
|
|
|
self.insert(inf.span, inf.hir_id, Node::Infer(inf));
|
|
|
|
|
|
|
|
self.with_parent(inf.hir_id, |this| {
|
|
|
|
intravisit::walk_inf(this, inf);
|
|
|
|
});
|
2016-08-05 19:12:20 -05:00
|
|
|
}
|
|
|
|
|
2019-11-30 10:46:46 -06:00
|
|
|
fn visit_trait_ref(&mut self, tr: &'hir TraitRef<'hir>) {
|
2019-02-15 03:30:44 -06:00
|
|
|
self.insert(tr.path.span, tr.hir_ref_id, Node::TraitRef(tr));
|
2016-10-30 01:04:52 -05:00
|
|
|
|
2019-02-15 05:14:36 -06:00
|
|
|
self.with_parent(tr.hir_ref_id, |this| {
|
2016-10-30 01:04:52 -05:00
|
|
|
intravisit::walk_trait_ref(this, tr);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-01-25 19:21:50 -06:00
|
|
|
fn visit_fn(
|
|
|
|
&mut self,
|
|
|
|
fk: intravisit::FnKind<'hir>,
|
2019-11-30 10:46:46 -06:00
|
|
|
fd: &'hir FnDecl<'hir>,
|
2019-02-06 07:16:11 -06:00
|
|
|
b: BodyId,
|
|
|
|
s: Span,
|
|
|
|
id: HirId,
|
|
|
|
) {
|
2021-02-28 13:23:10 -06:00
|
|
|
assert_eq!(self.owner, id.owner);
|
|
|
|
assert_eq!(self.parent_node, id.local_id);
|
2016-07-28 04:58:45 -05:00
|
|
|
intravisit::walk_fn(self, fk, fd, b, s, id);
|
2015-09-10 14:53:08 -05:00
|
|
|
}
|
|
|
|
|
2019-11-29 06:43:03 -06:00
|
|
|
fn visit_block(&mut self, block: &'hir Block<'hir>) {
|
2019-02-15 03:30:44 -06:00
|
|
|
self.insert(block.span, block.hir_id, Node::Block(block));
|
2019-02-15 05:14:36 -06:00
|
|
|
self.with_parent(block.hir_id, |this| {
|
2016-04-14 00:24:30 -05:00
|
|
|
intravisit::walk_block(this, block);
|
|
|
|
});
|
2015-09-10 14:53:08 -05:00
|
|
|
}
|
|
|
|
|
2019-11-29 06:43:03 -06:00
|
|
|
fn visit_local(&mut self, l: &'hir Local<'hir>) {
|
2019-02-15 03:30:44 -06:00
|
|
|
self.insert(l.span, l.hir_id, Node::Local(l));
|
2021-03-27 07:21:26 -05:00
|
|
|
self.with_parent(l.hir_id, |this| {
|
|
|
|
intravisit::walk_local(this, l);
|
|
|
|
})
|
2017-08-18 01:56:11 -05:00
|
|
|
}
|
|
|
|
|
2017-01-25 19:21:50 -06:00
|
|
|
fn visit_lifetime(&mut self, lifetime: &'hir Lifetime) {
|
2019-02-15 03:30:44 -06:00
|
|
|
self.insert(lifetime.span, lifetime.hir_id, Node::Lifetime(lifetime));
|
2015-09-10 14:53:08 -05:00
|
|
|
}
|
2016-10-28 01:52:45 -05:00
|
|
|
|
2019-11-30 10:46:46 -06:00
|
|
|
fn visit_variant(&mut self, v: &'hir Variant<'hir>, g: &'hir Generics<'hir>, item_id: HirId) {
|
2019-08-13 19:40:21 -05:00
|
|
|
self.insert(v.span, v.id, Node::Variant(v));
|
|
|
|
self.with_parent(v.id, |this| {
|
2019-03-21 17:38:50 -05:00
|
|
|
// Register the constructor of this variant.
|
2019-08-13 19:40:21 -05:00
|
|
|
if let Some(ctor_hir_id) = v.data.ctor_hir_id() {
|
|
|
|
this.insert(v.span, ctor_hir_id, Node::Ctor(&v.data));
|
2019-03-21 17:38:50 -05:00
|
|
|
}
|
2016-12-21 04:32:59 -06:00
|
|
|
intravisit::walk_variant(this, v, g, item_id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-03-15 16:36:07 -05:00
|
|
|
fn visit_field_def(&mut self, field: &'hir FieldDef<'hir>) {
|
2019-02-15 03:30:44 -06:00
|
|
|
self.insert(field.span, field.hir_id, Node::Field(field));
|
2019-02-15 05:14:36 -06:00
|
|
|
self.with_parent(field.hir_id, |this| {
|
2021-03-15 16:36:07 -05:00
|
|
|
intravisit::walk_field_def(this, field);
|
2016-11-09 12:57:48 -06:00
|
|
|
});
|
|
|
|
}
|
2017-08-18 13:24:19 -05:00
|
|
|
|
2022-05-07 15:41:53 -05:00
|
|
|
fn visit_assoc_type_binding(&mut self, type_binding: &'hir TypeBinding<'hir>) {
|
|
|
|
self.insert(type_binding.span, type_binding.hir_id, Node::TypeBinding(type_binding));
|
|
|
|
self.with_parent(type_binding.hir_id, |this| {
|
|
|
|
intravisit::walk_assoc_type_binding(this, type_binding)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-08-18 13:24:19 -05:00
|
|
|
fn visit_trait_item_ref(&mut self, ii: &'hir TraitItemRef) {
|
|
|
|
// Do not visit the duplicate information in TraitItemRef. We want to
|
|
|
|
// map the actual nodes, not the duplicate ones in the *Ref.
|
2022-03-12 12:36:11 -06:00
|
|
|
let TraitItemRef { id, ident: _, kind: _, span: _ } = *ii;
|
2017-08-18 13:24:19 -05:00
|
|
|
|
|
|
|
self.visit_nested_trait_item(id);
|
|
|
|
}
|
|
|
|
|
2021-07-15 15:19:39 -05:00
|
|
|
fn visit_impl_item_ref(&mut self, ii: &'hir ImplItemRef) {
|
2017-08-18 13:24:19 -05:00
|
|
|
// Do not visit the duplicate information in ImplItemRef. We want to
|
|
|
|
// map the actual nodes, not the duplicate ones in the *Ref.
|
2022-03-12 12:36:11 -06:00
|
|
|
let ImplItemRef { id, ident: _, kind: _, span: _, trait_item_def_id: _ } = *ii;
|
2017-08-18 13:24:19 -05:00
|
|
|
|
|
|
|
self.visit_nested_impl_item(id);
|
|
|
|
}
|
2020-11-28 11:08:11 -06:00
|
|
|
|
2021-07-15 15:19:39 -05:00
|
|
|
fn visit_foreign_item_ref(&mut self, fi: &'hir ForeignItemRef) {
|
2020-11-28 11:08:11 -06:00
|
|
|
// Do not visit the duplicate information in ForeignItemRef. We want to
|
|
|
|
// map the actual nodes, not the duplicate ones in the *Ref.
|
2021-07-15 15:19:39 -05:00
|
|
|
let ForeignItemRef { id, ident: _, span: _ } = *fi;
|
2020-11-28 11:08:11 -06:00
|
|
|
|
|
|
|
self.visit_nested_foreign_item(id);
|
|
|
|
}
|
2015-09-10 14:53:08 -05:00
|
|
|
}
|