Skip to main content

rustc_ast_lowering/
index.rs

1use intravisit::InferKind;
2use rustc_data_structures::sorted_map::SortedMap;
3use rustc_hir as hir;
4use rustc_hir::def_id::{LocalDefId, LocalDefIdMap};
5use rustc_hir::intravisit::Visitor;
6use rustc_hir::*;
7use rustc_index::IndexVec;
8use rustc_middle::ty::TyCtxt;
9use rustc_span::def_id::CRATE_MOD_ID;
10use rustc_span::{DUMMY_SP, Span, span_bug};
11use tracing::{debug, instrument};
12
13/// A visitor that walks over the HIR and collects `Node`s into a HIR map.
14struct NodeCollector<'a, 'hir> {
15    tcx: TyCtxt<'hir>,
16
17    bodies: &'a SortedMap<ItemLocalId, &'hir Body<'hir>>,
18
19    /// Outputs
20    nodes: IndexVec<ItemLocalId, ParentedNode<'hir>>,
21    parenting: LocalDefIdMap<ItemLocalId>,
22
23    /// The parent of this node
24    parent_node: ItemLocalId,
25
26    owner: OwnerId,
27}
28
29{}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("index_hir",
                                    "rustc_ast_lowering::index", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/ea137335b78829b4514bf1b4c16302f74fab8581/compiler/rustc_ast_lowering/src/index.rs"),
                                    ::tracing_core::__macro_support::Option::Some(29u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_ast_lowering::index"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("item")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("item");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("num_nodes")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("num_nodes");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&item)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&num_nodes as
                                                            &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return:
                    (IndexVec<ItemLocalId, ParentedNode<'hir>>,
                    LocalDefIdMap<ItemLocalId>) = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let err_node =
                ParentedNode {
                    parent: ItemLocalId::ZERO,
                    node: Node::Err(item.span()),
                };
            let mut nodes = IndexVec::from_elem_n(err_node, num_nodes);
            nodes[ItemLocalId::ZERO] =
                ParentedNode {
                    parent: ItemLocalId::INVALID,
                    node: item.into(),
                };
            let mut collector =
                NodeCollector {
                    tcx,
                    owner: item.def_id(),
                    parent_node: ItemLocalId::ZERO,
                    nodes,
                    bodies,
                    parenting: Default::default(),
                };
            match item {
                OwnerNode::Crate(citem) =>
                    collector.visit_mod(citem, citem.spans.inner_span,
                        CRATE_MOD_ID),
                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),
                OwnerNode::Synthetic =>
                    ::core::panicking::panic("internal error: entered unreachable code"),
            };
            for (local_id, node) in collector.nodes.iter_enumerated() {
                if let Node::Err(span) = node.node {
                    let hir_id = HirId { owner: item.def_id(), local_id };
                    let msg =
                        ::alloc::__export::must_use({
                                ::alloc::fmt::format(format_args!("ID {0} not encountered when visiting item HIR",
                                        hir_id))
                            });
                    tcx.dcx().span_delayed_bug(span, msg);
                }
            }
            (collector.nodes, collector.parenting)
        }
    }
}#[instrument(level = "debug", skip(tcx, bodies))]
30pub(super) fn index_hir<'hir>(
31    tcx: TyCtxt<'hir>,
32    item: hir::OwnerNode<'hir>,
33    bodies: &SortedMap<ItemLocalId, &'hir Body<'hir>>,
34    num_nodes: usize,
35) -> (IndexVec<ItemLocalId, ParentedNode<'hir>>, LocalDefIdMap<ItemLocalId>) {
36    let err_node = ParentedNode { parent: ItemLocalId::ZERO, node: Node::Err(item.span()) };
37    let mut nodes = IndexVec::from_elem_n(err_node, num_nodes);
38    // This node's parent should never be accessed: the owner's parent is computed by the
39    // hir_owner_parent query. Make it invalid (= ItemLocalId::MAX) to force an ICE whenever it is
40    // used.
41    nodes[ItemLocalId::ZERO] = ParentedNode { parent: ItemLocalId::INVALID, node: item.into() };
42    let mut collector = NodeCollector {
43        tcx,
44        owner: item.def_id(),
45        parent_node: ItemLocalId::ZERO,
46        nodes,
47        bodies,
48        parenting: Default::default(),
49    };
50
51    match item {
52        OwnerNode::Crate(citem) => collector.visit_mod(citem, citem.spans.inner_span, CRATE_MOD_ID),
53        OwnerNode::Item(item) => collector.visit_item(item),
54        OwnerNode::TraitItem(item) => collector.visit_trait_item(item),
55        OwnerNode::ImplItem(item) => collector.visit_impl_item(item),
56        OwnerNode::ForeignItem(item) => collector.visit_foreign_item(item),
57        OwnerNode::Synthetic => unreachable!(),
58    };
59
60    for (local_id, node) in collector.nodes.iter_enumerated() {
61        if let Node::Err(span) = node.node {
62            let hir_id = HirId { owner: item.def_id(), local_id };
63            let msg = format!("ID {hir_id} not encountered when visiting item HIR");
64            tcx.dcx().span_delayed_bug(span, msg);
65        }
66    }
67
68    (collector.nodes, collector.parenting)
69}
70
71impl<'a, 'hir> NodeCollector<'a, 'hir> {
72    {}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("insert",
                                    "rustc_ast_lowering::index", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/ea137335b78829b4514bf1b4c16302f74fab8581/compiler/rustc_ast_lowering/src/index.rs"),
                                    ::tracing_core::__macro_support::Option::Some(72u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_ast_lowering::index"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("span")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("span");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("hir_id")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("hir_id");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("node")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("node");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_id)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&node)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            if true {
                {
                    match (&self.owner, &hir_id.owner) {
                        (left_val, right_val) => {
                            if !(*left_val == *right_val) {
                                let kind = ::core::panicking::AssertKind::Eq;
                                ::core::panicking::assert_failed(kind, &*left_val,
                                    &*right_val, ::core::option::Option::None);
                            }
                        }
                    }
                };
            };
            if true {
                {
                    match (&hir_id.local_id.as_u32(), &0) {
                        (left_val, right_val) => {
                            if *left_val == *right_val {
                                let kind = ::core::panicking::AssertKind::Ne;
                                ::core::panicking::assert_failed(kind, &*left_val,
                                    &*right_val, ::core::option::Option::None);
                            }
                        }
                    }
                };
            };
            if true {
                {
                    match (&hir_id.local_id, &self.parent_node) {
                        (left_val, right_val) => {
                            if *left_val == *right_val {
                                let kind = ::core::panicking::AssertKind::Ne;
                                ::core::panicking::assert_failed(kind, &*left_val,
                                    &*right_val, ::core::option::Option::None);
                            }
                        }
                    }
                };
            };
            if true {
                if hir_id.owner != self.owner {
                    ::rustc_span::macros::bug_impl(Some(span),
                        format_args!("inconsistent HirId at `{0:?}` for `{5:?}`: current_dep_node_owner={1} ({2:?}), hir_id.owner={3} ({4:?})",
                            self.tcx.sess.source_map().span_to_diagnostic_string(span),
                            self.tcx.definitions_untracked().def_path(self.owner.def_id).to_string_no_crate_verbose(),
                            self.owner,
                            self.tcx.definitions_untracked().def_path(hir_id.owner.def_id).to_string_no_crate_verbose(),
                            hir_id.owner, node), Location::caller())
                }
                if self.tcx.sess.opts.incremental.is_some() &&
                            span.parent().is_none() && !span.is_dummy() {
                    ::rustc_span::macros::bug_impl(Some(span),
                        format_args!("span without a parent: {0:#?}, {1:?}",
                            span.data(), node), Location::caller())
                }
            }
            self.nodes[hir_id.local_id] =
                ParentedNode { parent: self.parent_node, node };
        }
    }
}#[instrument(level = "debug", skip(self))]
73    fn insert(&mut self, span: Span, hir_id: HirId, node: Node<'hir>) {
74        debug_assert_eq!(self.owner, hir_id.owner);
75        debug_assert_ne!(hir_id.local_id.as_u32(), 0);
76        debug_assert_ne!(hir_id.local_id, self.parent_node);
77
78        // Make sure that the DepNode of some node coincides with the HirId
79        // owner of that node.
80        if cfg!(debug_assertions) {
81            if hir_id.owner != self.owner {
82                span_bug!(
83                    span,
84                    "inconsistent HirId at `{:?}` for `{node:?}`: \
85                     current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})",
86                    self.tcx.sess.source_map().span_to_diagnostic_string(span),
87                    self.tcx
88                        .definitions_untracked()
89                        .def_path(self.owner.def_id)
90                        .to_string_no_crate_verbose(),
91                    self.owner,
92                    self.tcx
93                        .definitions_untracked()
94                        .def_path(hir_id.owner.def_id)
95                        .to_string_no_crate_verbose(),
96                    hir_id.owner,
97                )
98            }
99            if self.tcx.sess.opts.incremental.is_some()
100                && span.parent().is_none()
101                && !span.is_dummy()
102            {
103                span_bug!(span, "span without a parent: {:#?}, {node:?}", span.data())
104            }
105        }
106
107        self.nodes[hir_id.local_id] = ParentedNode { parent: self.parent_node, node };
108    }
109
110    fn with_parent<F: FnOnce(&mut Self)>(&mut self, parent_node_id: HirId, f: F) {
111        if true {
    {
        match (&parent_node_id.owner, &self.owner) {
            (left_val, right_val) => {
                if !(*left_val == *right_val) {
                    let kind = ::core::panicking::AssertKind::Eq;
                    ::core::panicking::assert_failed(kind, &*left_val,
                        &*right_val, ::core::option::Option::None);
                }
            }
        }
    };
};debug_assert_eq!(parent_node_id.owner, self.owner);
112        let parent_node = self.parent_node;
113        self.parent_node = parent_node_id.local_id;
114        f(self);
115        self.parent_node = parent_node;
116    }
117
118    fn insert_nested(&mut self, item: LocalDefId) {
119        if self.parent_node != ItemLocalId::ZERO {
120            self.parenting.insert(item, self.parent_node);
121        }
122    }
123}
124
125impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
126    // Because we want to track parent items and so forth, enable
127    // deep walking so that we walk nested items in the context of
128    // their outer items.
129
130    fn visit_nested_item(&mut self, item: ItemId) {
131        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/ea137335b78829b4514bf1b4c16302f74fab8581/compiler/rustc_ast_lowering/src/index.rs:131",
                        "rustc_ast_lowering::index", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/ea137335b78829b4514bf1b4c16302f74fab8581/compiler/rustc_ast_lowering/src/index.rs"),
                        ::tracing_core::__macro_support::Option::Some(131u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_ast_lowering::index"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("visit_nested_item: {0:?}",
                                                    item) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("visit_nested_item: {:?}", item);
132        self.insert_nested(item.owner_id.def_id);
133    }
134
135    fn visit_nested_trait_item(&mut self, item_id: TraitItemId) {
136        self.insert_nested(item_id.owner_id.def_id);
137    }
138
139    fn visit_nested_impl_item(&mut self, item_id: ImplItemId) {
140        self.insert_nested(item_id.owner_id.def_id);
141    }
142
143    fn visit_nested_foreign_item(&mut self, foreign_id: ForeignItemId) {
144        self.insert_nested(foreign_id.owner_id.def_id);
145    }
146
147    fn visit_nested_body(&mut self, id: BodyId) {
148        if true {
    {
        match (&id.hir_id.owner, &self.owner) {
            (left_val, right_val) => {
                if !(*left_val == *right_val) {
                    let kind = ::core::panicking::AssertKind::Eq;
                    ::core::panicking::assert_failed(kind, &*left_val,
                        &*right_val, ::core::option::Option::None);
                }
            }
        }
    };
};debug_assert_eq!(id.hir_id.owner, self.owner);
149        let body = self.bodies[&id.hir_id.local_id];
150        self.visit_body(body);
151    }
152
153    fn visit_use(&mut self, tree: &'hir UseTree<'hir>, hir_id: HirId, _def_id: LocalDefId) {
154        if !hir_id.is_owner() {
155            self.insert(tree.prefix.span, hir_id, Node::NestedUseTree(tree));
156        }
157        intravisit::walk_use(self, tree, hir_id);
158    }
159
160    fn visit_param(&mut self, param: &'hir Param<'hir>) {
161        let node = Node::Param(param);
162        self.insert(param.pat.span, param.hir_id, node);
163        self.with_parent(param.hir_id, |this| {
164            intravisit::walk_param(this, param);
165        });
166    }
167
168    {}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("visit_item",
                                    "rustc_ast_lowering::index", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/ea137335b78829b4514bf1b4c16302f74fab8581/compiler/rustc_ast_lowering/src/index.rs"),
                                    ::tracing_core::__macro_support::Option::Some(168u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_ast_lowering::index"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("i")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("i");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&i)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            if true {
                {
                    match (&i.owner_id, &self.owner) {
                        (left_val, right_val) => {
                            if !(*left_val == *right_val) {
                                let kind = ::core::panicking::AssertKind::Eq;
                                ::core::panicking::assert_failed(kind, &*left_val,
                                    &*right_val, ::core::option::Option::None);
                            }
                        }
                    }
                };
            };
            self.with_parent(i.hir_id(),
                |this|
                    {
                        if let ItemKind::Struct(_, _, struct_def) = &i.kind &&
                                let Some(ctor_hir_id) = struct_def.ctor_hir_id() {
                            this.insert(i.span, ctor_hir_id, Node::Ctor(struct_def));
                        }
                        intravisit::walk_item(this, i);
                    });
        }
    }
}#[instrument(level = "debug", skip(self))]
169    fn visit_item(&mut self, i: &'hir Item<'hir>) {
170        debug_assert_eq!(i.owner_id, self.owner);
171        self.with_parent(i.hir_id(), |this| {
172            if let ItemKind::Struct(_, _, struct_def) = &i.kind
173                // If this is a tuple or unit-like struct, register the constructor.
174                && let Some(ctor_hir_id) = struct_def.ctor_hir_id()
175            {
176                this.insert(i.span, ctor_hir_id, Node::Ctor(struct_def));
177            }
178            intravisit::walk_item(this, i);
179        });
180    }
181
182    {}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("visit_foreign_item",
                                    "rustc_ast_lowering::index", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/ea137335b78829b4514bf1b4c16302f74fab8581/compiler/rustc_ast_lowering/src/index.rs"),
                                    ::tracing_core::__macro_support::Option::Some(182u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_ast_lowering::index"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("fi")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("fi");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fi)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            if true {
                {
                    match (&fi.owner_id, &self.owner) {
                        (left_val, right_val) => {
                            if !(*left_val == *right_val) {
                                let kind = ::core::panicking::AssertKind::Eq;
                                ::core::panicking::assert_failed(kind, &*left_val,
                                    &*right_val, ::core::option::Option::None);
                            }
                        }
                    }
                };
            };
            self.with_parent(fi.hir_id(),
                |this| { intravisit::walk_foreign_item(this, fi); });
        }
    }
}#[instrument(level = "debug", skip(self))]
183    fn visit_foreign_item(&mut self, fi: &'hir ForeignItem<'hir>) {
184        debug_assert_eq!(fi.owner_id, self.owner);
185        self.with_parent(fi.hir_id(), |this| {
186            intravisit::walk_foreign_item(this, fi);
187        });
188    }
189
190    fn visit_generic_param(&mut self, param: &'hir GenericParam<'hir>) {
191        self.insert(param.span, param.hir_id, Node::GenericParam(param));
192        intravisit::walk_generic_param(self, param);
193    }
194
195    fn visit_const_param_default(&mut self, param: HirId, ct: &'hir ConstArg<'hir>) {
196        self.with_parent(param, |this| {
197            intravisit::walk_const_param_default(this, ct);
198        })
199    }
200
201    {}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("visit_trait_item",
                                    "rustc_ast_lowering::index", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/ea137335b78829b4514bf1b4c16302f74fab8581/compiler/rustc_ast_lowering/src/index.rs"),
                                    ::tracing_core::__macro_support::Option::Some(201u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_ast_lowering::index"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("ti")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("ti");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ti)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            if true {
                {
                    match (&ti.owner_id, &self.owner) {
                        (left_val, right_val) => {
                            if !(*left_val == *right_val) {
                                let kind = ::core::panicking::AssertKind::Eq;
                                ::core::panicking::assert_failed(kind, &*left_val,
                                    &*right_val, ::core::option::Option::None);
                            }
                        }
                    }
                };
            };
            self.with_parent(ti.hir_id(),
                |this| { intravisit::walk_trait_item(this, ti); });
        }
    }
}#[instrument(level = "debug", skip(self))]
202    fn visit_trait_item(&mut self, ti: &'hir TraitItem<'hir>) {
203        debug_assert_eq!(ti.owner_id, self.owner);
204        self.with_parent(ti.hir_id(), |this| {
205            intravisit::walk_trait_item(this, ti);
206        });
207    }
208
209    {}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("visit_impl_item",
                                    "rustc_ast_lowering::index", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/ea137335b78829b4514bf1b4c16302f74fab8581/compiler/rustc_ast_lowering/src/index.rs"),
                                    ::tracing_core::__macro_support::Option::Some(209u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_ast_lowering::index"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("ii")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("ii");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ii)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            if true {
                {
                    match (&ii.owner_id, &self.owner) {
                        (left_val, right_val) => {
                            if !(*left_val == *right_val) {
                                let kind = ::core::panicking::AssertKind::Eq;
                                ::core::panicking::assert_failed(kind, &*left_val,
                                    &*right_val, ::core::option::Option::None);
                            }
                        }
                    }
                };
            };
            self.with_parent(ii.hir_id(),
                |this| { intravisit::walk_impl_item(this, ii); });
        }
    }
}#[instrument(level = "debug", skip(self))]
210    fn visit_impl_item(&mut self, ii: &'hir ImplItem<'hir>) {
211        debug_assert_eq!(ii.owner_id, self.owner);
212        self.with_parent(ii.hir_id(), |this| {
213            intravisit::walk_impl_item(this, ii);
214        });
215    }
216
217    fn visit_pat(&mut self, pat: &'hir Pat<'hir>) {
218        self.insert(pat.span, pat.hir_id, Node::Pat(pat));
219
220        self.with_parent(pat.hir_id, |this| {
221            intravisit::walk_pat(this, pat);
222        });
223    }
224
225    fn visit_pat_expr(&mut self, expr: &'hir PatExpr<'hir>) {
226        self.insert(expr.span, expr.hir_id, Node::PatExpr(expr));
227
228        self.with_parent(expr.hir_id, |this| {
229            intravisit::walk_pat_expr(this, expr);
230        });
231    }
232
233    fn visit_pat_field(&mut self, field: &'hir PatField<'hir>) {
234        self.insert(field.span, field.hir_id, Node::PatField(field));
235        self.with_parent(field.hir_id, |this| {
236            intravisit::walk_pat_field(this, field);
237        });
238    }
239
240    fn visit_arm(&mut self, arm: &'hir Arm<'hir>) {
241        let node = Node::Arm(arm);
242
243        self.insert(arm.span, arm.hir_id, node);
244
245        self.with_parent(arm.hir_id, |this| {
246            intravisit::walk_arm(this, arm);
247        });
248    }
249
250    fn visit_opaque_ty(&mut self, opaq: &'hir OpaqueTy<'hir>) {
251        self.insert(opaq.span, opaq.hir_id, Node::OpaqueTy(opaq));
252
253        self.with_parent(opaq.hir_id, |this| {
254            intravisit::walk_opaque_ty(this, opaq);
255        });
256    }
257
258    fn visit_anon_const(&mut self, constant: &'hir AnonConst) {
259        self.insert(constant.span, constant.hir_id, Node::AnonConst(constant));
260
261        self.with_parent(constant.hir_id, |this| {
262            intravisit::walk_anon_const(this, constant);
263        });
264    }
265
266    fn visit_inline_const(&mut self, constant: &'hir ConstBlock) {
267        self.insert(DUMMY_SP, constant.hir_id, Node::ConstBlock(constant));
268
269        self.with_parent(constant.hir_id, |this| {
270            intravisit::walk_inline_const(this, constant);
271        });
272    }
273
274    fn visit_expr(&mut self, expr: &'hir Expr<'hir>) {
275        self.insert(expr.span, expr.hir_id, Node::Expr(expr));
276
277        self.with_parent(expr.hir_id, |this| {
278            intravisit::walk_expr(this, expr);
279        });
280    }
281
282    fn visit_expr_field(&mut self, field: &'hir ExprField<'hir>) {
283        self.insert(field.span, field.hir_id, Node::ExprField(field));
284        self.with_parent(field.hir_id, |this| {
285            intravisit::walk_expr_field(this, field);
286        });
287    }
288
289    fn visit_const_arg_expr_field(&mut self, field: &'hir ConstArgExprField<'hir>) {
290        self.insert(field.span, field.hir_id, Node::ConstArgExprField(field));
291        self.with_parent(field.hir_id, |this| {
292            intravisit::walk_const_arg_expr_field(this, field);
293        })
294    }
295
296    fn visit_stmt(&mut self, stmt: &'hir Stmt<'hir>) {
297        self.insert(stmt.span, stmt.hir_id, Node::Stmt(stmt));
298
299        self.with_parent(stmt.hir_id, |this| {
300            intravisit::walk_stmt(this, stmt);
301        });
302    }
303
304    fn visit_path_segment(&mut self, path_segment: &'hir PathSegment<'hir>) {
305        // FIXME: walk path segment with `path_segment.hir_id` parent.
306        self.insert(path_segment.ident.span, path_segment.hir_id, Node::PathSegment(path_segment));
307        intravisit::walk_path_segment(self, path_segment);
308    }
309
310    fn visit_ty(&mut self, ty: &'hir Ty<'hir, AmbigArg>) {
311        self.insert(ty.span, ty.hir_id, Node::Ty(ty.as_unambig_ty()));
312
313        self.with_parent(ty.hir_id, |this| {
314            intravisit::walk_ty(this, ty);
315        });
316    }
317
318    fn visit_const_arg(&mut self, const_arg: &'hir ConstArg<'hir, AmbigArg>) {
319        self.insert(
320            const_arg.as_unambig_ct().span,
321            const_arg.hir_id,
322            Node::ConstArg(const_arg.as_unambig_ct()),
323        );
324
325        self.with_parent(const_arg.hir_id, |this| {
326            intravisit::walk_const_arg(this, const_arg);
327        });
328    }
329
330    fn visit_infer(
331        &mut self,
332        inf_id: HirId,
333        inf_span: Span,
334        kind: InferKind<'hir>,
335    ) -> Self::Result {
336        match kind {
337            InferKind::Ty(ty) => self.insert(inf_span, inf_id, Node::Ty(ty)),
338            InferKind::Const(ct) => self.insert(inf_span, inf_id, Node::ConstArg(ct)),
339            InferKind::Ambig(inf) => self.insert(inf_span, inf_id, Node::Infer(inf)),
340        }
341
342        self.visit_id(inf_id);
343    }
344
345    fn visit_trait_ref(&mut self, tr: &'hir TraitRef<'hir>) {
346        self.insert(tr.path.span, tr.hir_ref_id, Node::TraitRef(tr));
347
348        self.with_parent(tr.hir_ref_id, |this| {
349            intravisit::walk_trait_ref(this, tr);
350        });
351    }
352
353    fn visit_block(&mut self, block: &'hir Block<'hir>) {
354        self.insert(block.span, block.hir_id, Node::Block(block));
355        self.with_parent(block.hir_id, |this| {
356            intravisit::walk_block(this, block);
357        });
358    }
359
360    fn visit_local(&mut self, l: &'hir LetStmt<'hir>) {
361        self.insert(l.span, l.hir_id, Node::LetStmt(l));
362        self.with_parent(l.hir_id, |this| {
363            intravisit::walk_local(this, l);
364        })
365    }
366
367    fn visit_lifetime(&mut self, lifetime: &'hir Lifetime) {
368        self.insert(lifetime.ident.span, lifetime.hir_id, Node::Lifetime(lifetime));
369    }
370
371    fn visit_variant(&mut self, v: &'hir Variant<'hir>) {
372        self.insert(v.span, v.hir_id, Node::Variant(v));
373        self.with_parent(v.hir_id, |this| {
374            // Register the constructor of this variant.
375            if let Some(ctor_hir_id) = v.data.ctor_hir_id() {
376                this.insert(v.span, ctor_hir_id, Node::Ctor(&v.data));
377            }
378            intravisit::walk_variant(this, v);
379        });
380    }
381
382    fn visit_field_def(&mut self, field: &'hir FieldDef<'hir>) {
383        self.insert(field.span, field.hir_id, Node::Field(field));
384        self.with_parent(field.hir_id, |this| {
385            intravisit::walk_field_def(this, field);
386        });
387    }
388
389    fn visit_assoc_item_constraint(&mut self, constraint: &'hir AssocItemConstraint<'hir>) {
390        self.insert(constraint.span, constraint.hir_id, Node::AssocItemConstraint(constraint));
391        self.with_parent(constraint.hir_id, |this| {
392            intravisit::walk_assoc_item_constraint(this, constraint)
393        })
394    }
395
396    fn visit_trait_item_ref(&mut self, id: &'hir TraitItemId) {
397        self.visit_nested_trait_item(*id);
398    }
399
400    fn visit_impl_item_ref(&mut self, id: &'hir ImplItemId) {
401        self.visit_nested_impl_item(*id);
402    }
403
404    fn visit_foreign_item_ref(&mut self, id: &'hir ForeignItemId) {
405        self.visit_nested_foreign_item(*id);
406    }
407
408    fn visit_where_predicate(&mut self, predicate: &'hir WherePredicate<'hir>) {
409        self.insert(predicate.span, predicate.hir_id, Node::WherePredicate(predicate));
410        self.with_parent(predicate.hir_id, |this| {
411            intravisit::walk_where_predicate(this, predicate)
412        });
413    }
414
415    fn visit_pattern_type_pattern(&mut self, pat: &'hir hir::TyPat<'hir>) {
416        self.insert(pat.span, pat.hir_id, Node::TyPat(pat));
417
418        self.with_parent(pat.hir_id, |this| {
419            intravisit::walk_ty_pat(this, pat);
420        });
421    }
422
423    fn visit_precise_capturing_arg(
424        &mut self,
425        arg: &'hir PreciseCapturingArg<'hir>,
426    ) -> Self::Result {
427        match arg {
428            PreciseCapturingArg::Lifetime(_) => {
429                // This is represented as a `Node::Lifetime`, intravisit will get to it below.
430            }
431            PreciseCapturingArg::Param(param) => self.insert(
432                param.ident.span,
433                param.hir_id,
434                Node::PreciseCapturingNonLifetimeArg(param),
435            ),
436        }
437        intravisit::walk_precise_capturing_arg(self, arg);
438    }
439
440    fn visit_test_binder_forall(&mut self, forall: &'hir TestBinderForall<'hir>) {
441        self.insert(forall.span, forall.hir_id, Node::TestBinderForall(forall));
442        self.with_parent(forall.hir_id, |this| intravisit::walk_test_binder_forall(this, forall))
443    }
444
445    fn visit_test_binder_exists(&mut self, exists: &'hir TestBinderExists<'hir>) {
446        self.insert(exists.span, exists.hir_id, Node::TestBinderExists(exists));
447        self.with_parent(exists.hir_id, |this| intravisit::walk_test_binder_exists(this, exists))
448    }
449
450    fn visit_test_binder_bound_type_constraint(
451        &mut self,
452        bound_type: &'hir TestBinderBoundTypeConstraint<'hir>,
453    ) {
454        self.insert(
455            bound_type.span,
456            bound_type.hir_id,
457            Node::TestBinderBoundTypeConstraint(bound_type),
458        );
459        self.with_parent(bound_type.hir_id, |this| {
460            intravisit::walk_test_binder_bound_type_constraint(this, bound_type)
461        })
462    }
463}