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::{DUMMY_SP, Span, span_bug};
10use tracing::{debug, instrument};
11
12/// A visitor that walks over the HIR and collects `Node`s into a HIR map.
13struct NodeCollector<'a, 'hir> {
14    tcx: TyCtxt<'hir>,
15
16    bodies: &'a SortedMap<ItemLocalId, &'hir Body<'hir>>,
17
18    /// Outputs
19    nodes: IndexVec<ItemLocalId, ParentedNode<'hir>>,
20    parenting: LocalDefIdMap<ItemLocalId>,
21
22    /// The parent of this node
23    parent_node: ItemLocalId,
24
25    owner: OwnerId,
26}
27
28{}
#[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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ast_lowering/src/index.rs"),
                                    ::tracing_core::__macro_support::Option::Some(28u32),
                                    ::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,
                        hir::CRATE_HIR_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))]
29pub(super) fn index_hir<'hir>(
30    tcx: TyCtxt<'hir>,
31    item: hir::OwnerNode<'hir>,
32    bodies: &SortedMap<ItemLocalId, &'hir Body<'hir>>,
33    num_nodes: usize,
34) -> (IndexVec<ItemLocalId, ParentedNode<'hir>>, LocalDefIdMap<ItemLocalId>) {
35    let err_node = ParentedNode { parent: ItemLocalId::ZERO, node: Node::Err(item.span()) };
36    let mut nodes = IndexVec::from_elem_n(err_node, num_nodes);
37    // This node's parent should never be accessed: the owner's parent is computed by the
38    // hir_owner_parent query. Make it invalid (= ItemLocalId::MAX) to force an ICE whenever it is
39    // used.
40    nodes[ItemLocalId::ZERO] = ParentedNode { parent: ItemLocalId::INVALID, node: item.into() };
41    let mut collector = NodeCollector {
42        tcx,
43        owner: item.def_id(),
44        parent_node: ItemLocalId::ZERO,
45        nodes,
46        bodies,
47        parenting: Default::default(),
48    };
49
50    match item {
51        OwnerNode::Crate(citem) => {
52            collector.visit_mod(citem, citem.spans.inner_span, hir::CRATE_HIR_ID)
53        }
54        OwnerNode::Item(item) => collector.visit_item(item),
55        OwnerNode::TraitItem(item) => collector.visit_trait_item(item),
56        OwnerNode::ImplItem(item) => collector.visit_impl_item(item),
57        OwnerNode::ForeignItem(item) => collector.visit_foreign_item(item),
58        OwnerNode::Synthetic => unreachable!(),
59    };
60
61    for (local_id, node) in collector.nodes.iter_enumerated() {
62        if let Node::Err(span) = node.node {
63            let hir_id = HirId { owner: item.def_id(), local_id };
64            let msg = format!("ID {hir_id} not encountered when visiting item HIR");
65            tcx.dcx().span_delayed_bug(span, msg);
66        }
67    }
68
69    (collector.nodes, collector.parenting)
70}
71
72impl<'a, 'hir> NodeCollector<'a, 'hir> {
73    {}
#[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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ast_lowering/src/index.rs"),
                                    ::tracing_core::__macro_support::Option::Some(73u32),
                                    ::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 {
                    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() {
                    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))]
74    fn insert(&mut self, span: Span, hir_id: HirId, node: Node<'hir>) {
75        debug_assert_eq!(self.owner, hir_id.owner);
76        debug_assert_ne!(hir_id.local_id.as_u32(), 0);
77        debug_assert_ne!(hir_id.local_id, self.parent_node);
78
79        // Make sure that the DepNode of some node coincides with the HirId
80        // owner of that node.
81        if cfg!(debug_assertions) {
82            if hir_id.owner != self.owner {
83                span_bug!(
84                    span,
85                    "inconsistent HirId at `{:?}` for `{node:?}`: \
86                     current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})",
87                    self.tcx.sess.source_map().span_to_diagnostic_string(span),
88                    self.tcx
89                        .definitions_untracked()
90                        .def_path(self.owner.def_id)
91                        .to_string_no_crate_verbose(),
92                    self.owner,
93                    self.tcx
94                        .definitions_untracked()
95                        .def_path(hir_id.owner.def_id)
96                        .to_string_no_crate_verbose(),
97                    hir_id.owner,
98                )
99            }
100            if self.tcx.sess.opts.incremental.is_some()
101                && span.parent().is_none()
102                && !span.is_dummy()
103            {
104                span_bug!(span, "span without a parent: {:#?}, {node:?}", span.data())
105            }
106        }
107
108        self.nodes[hir_id.local_id] = ParentedNode { parent: self.parent_node, node };
109    }
110
111    fn with_parent<F: FnOnce(&mut Self)>(&mut self, parent_node_id: HirId, f: F) {
112        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);
113        let parent_node = self.parent_node;
114        self.parent_node = parent_node_id.local_id;
115        f(self);
116        self.parent_node = parent_node;
117    }
118
119    fn insert_nested(&mut self, item: LocalDefId) {
120        if self.parent_node != ItemLocalId::ZERO {
121            self.parenting.insert(item, self.parent_node);
122        }
123    }
124}
125
126impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
127    // Because we want to track parent items and so forth, enable
128    // deep walking so that we walk nested items in the context of
129    // their outer items.
130
131    fn visit_nested_item(&mut self, item: ItemId) {
132        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ast_lowering/src/index.rs:132",
                        "rustc_ast_lowering::index", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ast_lowering/src/index.rs"),
                        ::tracing_core::__macro_support::Option::Some(132u32),
                        ::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);
133        self.insert_nested(item.owner_id.def_id);
134    }
135
136    fn visit_nested_trait_item(&mut self, item_id: TraitItemId) {
137        self.insert_nested(item_id.owner_id.def_id);
138    }
139
140    fn visit_nested_impl_item(&mut self, item_id: ImplItemId) {
141        self.insert_nested(item_id.owner_id.def_id);
142    }
143
144    fn visit_nested_foreign_item(&mut self, foreign_id: ForeignItemId) {
145        self.insert_nested(foreign_id.owner_id.def_id);
146    }
147
148    fn visit_nested_body(&mut self, id: BodyId) {
149        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);
150        let body = self.bodies[&id.hir_id.local_id];
151        self.visit_body(body);
152    }
153
154    fn visit_param(&mut self, param: &'hir Param<'hir>) {
155        let node = Node::Param(param);
156        self.insert(param.pat.span, param.hir_id, node);
157        self.with_parent(param.hir_id, |this| {
158            intravisit::walk_param(this, param);
159        });
160    }
161
162    {}
#[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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ast_lowering/src/index.rs"),
                                    ::tracing_core::__macro_support::Option::Some(162u32),
                                    ::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))]
163    fn visit_item(&mut self, i: &'hir Item<'hir>) {
164        debug_assert_eq!(i.owner_id, self.owner);
165        self.with_parent(i.hir_id(), |this| {
166            if let ItemKind::Struct(_, _, struct_def) = &i.kind
167                // If this is a tuple or unit-like struct, register the constructor.
168                && let Some(ctor_hir_id) = struct_def.ctor_hir_id()
169            {
170                this.insert(i.span, ctor_hir_id, Node::Ctor(struct_def));
171            }
172            intravisit::walk_item(this, i);
173        });
174    }
175
176    {}
#[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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ast_lowering/src/index.rs"),
                                    ::tracing_core::__macro_support::Option::Some(176u32),
                                    ::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))]
177    fn visit_foreign_item(&mut self, fi: &'hir ForeignItem<'hir>) {
178        debug_assert_eq!(fi.owner_id, self.owner);
179        self.with_parent(fi.hir_id(), |this| {
180            intravisit::walk_foreign_item(this, fi);
181        });
182    }
183
184    fn visit_generic_param(&mut self, param: &'hir GenericParam<'hir>) {
185        self.insert(param.span, param.hir_id, Node::GenericParam(param));
186        intravisit::walk_generic_param(self, param);
187    }
188
189    fn visit_const_param_default(&mut self, param: HirId, ct: &'hir ConstArg<'hir>) {
190        self.with_parent(param, |this| {
191            intravisit::walk_const_param_default(this, ct);
192        })
193    }
194
195    {}
#[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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ast_lowering/src/index.rs"),
                                    ::tracing_core::__macro_support::Option::Some(195u32),
                                    ::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))]
196    fn visit_trait_item(&mut self, ti: &'hir TraitItem<'hir>) {
197        debug_assert_eq!(ti.owner_id, self.owner);
198        self.with_parent(ti.hir_id(), |this| {
199            intravisit::walk_trait_item(this, ti);
200        });
201    }
202
203    {}
#[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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_ast_lowering/src/index.rs"),
                                    ::tracing_core::__macro_support::Option::Some(203u32),
                                    ::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))]
204    fn visit_impl_item(&mut self, ii: &'hir ImplItem<'hir>) {
205        debug_assert_eq!(ii.owner_id, self.owner);
206        self.with_parent(ii.hir_id(), |this| {
207            intravisit::walk_impl_item(this, ii);
208        });
209    }
210
211    fn visit_pat(&mut self, pat: &'hir Pat<'hir>) {
212        self.insert(pat.span, pat.hir_id, Node::Pat(pat));
213
214        self.with_parent(pat.hir_id, |this| {
215            intravisit::walk_pat(this, pat);
216        });
217    }
218
219    fn visit_pat_expr(&mut self, expr: &'hir PatExpr<'hir>) {
220        self.insert(expr.span, expr.hir_id, Node::PatExpr(expr));
221
222        self.with_parent(expr.hir_id, |this| {
223            intravisit::walk_pat_expr(this, expr);
224        });
225    }
226
227    fn visit_pat_field(&mut self, field: &'hir PatField<'hir>) {
228        self.insert(field.span, field.hir_id, Node::PatField(field));
229        self.with_parent(field.hir_id, |this| {
230            intravisit::walk_pat_field(this, field);
231        });
232    }
233
234    fn visit_arm(&mut self, arm: &'hir Arm<'hir>) {
235        let node = Node::Arm(arm);
236
237        self.insert(arm.span, arm.hir_id, node);
238
239        self.with_parent(arm.hir_id, |this| {
240            intravisit::walk_arm(this, arm);
241        });
242    }
243
244    fn visit_opaque_ty(&mut self, opaq: &'hir OpaqueTy<'hir>) {
245        self.insert(opaq.span, opaq.hir_id, Node::OpaqueTy(opaq));
246
247        self.with_parent(opaq.hir_id, |this| {
248            intravisit::walk_opaque_ty(this, opaq);
249        });
250    }
251
252    fn visit_anon_const(&mut self, constant: &'hir AnonConst) {
253        self.insert(constant.span, constant.hir_id, Node::AnonConst(constant));
254
255        self.with_parent(constant.hir_id, |this| {
256            intravisit::walk_anon_const(this, constant);
257        });
258    }
259
260    fn visit_inline_const(&mut self, constant: &'hir ConstBlock) {
261        self.insert(DUMMY_SP, constant.hir_id, Node::ConstBlock(constant));
262
263        self.with_parent(constant.hir_id, |this| {
264            intravisit::walk_inline_const(this, constant);
265        });
266    }
267
268    fn visit_expr(&mut self, expr: &'hir Expr<'hir>) {
269        self.insert(expr.span, expr.hir_id, Node::Expr(expr));
270
271        self.with_parent(expr.hir_id, |this| {
272            intravisit::walk_expr(this, expr);
273        });
274    }
275
276    fn visit_expr_field(&mut self, field: &'hir ExprField<'hir>) {
277        self.insert(field.span, field.hir_id, Node::ExprField(field));
278        self.with_parent(field.hir_id, |this| {
279            intravisit::walk_expr_field(this, field);
280        });
281    }
282
283    fn visit_const_arg_expr_field(&mut self, field: &'hir ConstArgExprField<'hir>) {
284        self.insert(field.span, field.hir_id, Node::ConstArgExprField(field));
285        self.with_parent(field.hir_id, |this| {
286            intravisit::walk_const_arg_expr_field(this, field);
287        })
288    }
289
290    fn visit_stmt(&mut self, stmt: &'hir Stmt<'hir>) {
291        self.insert(stmt.span, stmt.hir_id, Node::Stmt(stmt));
292
293        self.with_parent(stmt.hir_id, |this| {
294            intravisit::walk_stmt(this, stmt);
295        });
296    }
297
298    fn visit_path_segment(&mut self, path_segment: &'hir PathSegment<'hir>) {
299        // FIXME: walk path segment with `path_segment.hir_id` parent.
300        self.insert(path_segment.ident.span, path_segment.hir_id, Node::PathSegment(path_segment));
301        intravisit::walk_path_segment(self, path_segment);
302    }
303
304    fn visit_ty(&mut self, ty: &'hir Ty<'hir, AmbigArg>) {
305        self.insert(ty.span, ty.hir_id, Node::Ty(ty.as_unambig_ty()));
306
307        self.with_parent(ty.hir_id, |this| {
308            intravisit::walk_ty(this, ty);
309        });
310    }
311
312    fn visit_const_arg(&mut self, const_arg: &'hir ConstArg<'hir, AmbigArg>) {
313        self.insert(
314            const_arg.as_unambig_ct().span,
315            const_arg.hir_id,
316            Node::ConstArg(const_arg.as_unambig_ct()),
317        );
318
319        self.with_parent(const_arg.hir_id, |this| {
320            intravisit::walk_const_arg(this, const_arg);
321        });
322    }
323
324    fn visit_infer(
325        &mut self,
326        inf_id: HirId,
327        inf_span: Span,
328        kind: InferKind<'hir>,
329    ) -> Self::Result {
330        match kind {
331            InferKind::Ty(ty) => self.insert(inf_span, inf_id, Node::Ty(ty)),
332            InferKind::Const(ct) => self.insert(inf_span, inf_id, Node::ConstArg(ct)),
333            InferKind::Ambig(inf) => self.insert(inf_span, inf_id, Node::Infer(inf)),
334        }
335
336        self.visit_id(inf_id);
337    }
338
339    fn visit_trait_ref(&mut self, tr: &'hir TraitRef<'hir>) {
340        self.insert(tr.path.span, tr.hir_ref_id, Node::TraitRef(tr));
341
342        self.with_parent(tr.hir_ref_id, |this| {
343            intravisit::walk_trait_ref(this, tr);
344        });
345    }
346
347    fn visit_block(&mut self, block: &'hir Block<'hir>) {
348        self.insert(block.span, block.hir_id, Node::Block(block));
349        self.with_parent(block.hir_id, |this| {
350            intravisit::walk_block(this, block);
351        });
352    }
353
354    fn visit_local(&mut self, l: &'hir LetStmt<'hir>) {
355        self.insert(l.span, l.hir_id, Node::LetStmt(l));
356        self.with_parent(l.hir_id, |this| {
357            intravisit::walk_local(this, l);
358        })
359    }
360
361    fn visit_lifetime(&mut self, lifetime: &'hir Lifetime) {
362        self.insert(lifetime.ident.span, lifetime.hir_id, Node::Lifetime(lifetime));
363    }
364
365    fn visit_variant(&mut self, v: &'hir Variant<'hir>) {
366        self.insert(v.span, v.hir_id, Node::Variant(v));
367        self.with_parent(v.hir_id, |this| {
368            // Register the constructor of this variant.
369            if let Some(ctor_hir_id) = v.data.ctor_hir_id() {
370                this.insert(v.span, ctor_hir_id, Node::Ctor(&v.data));
371            }
372            intravisit::walk_variant(this, v);
373        });
374    }
375
376    fn visit_field_def(&mut self, field: &'hir FieldDef<'hir>) {
377        self.insert(field.span, field.hir_id, Node::Field(field));
378        self.with_parent(field.hir_id, |this| {
379            intravisit::walk_field_def(this, field);
380        });
381    }
382
383    fn visit_assoc_item_constraint(&mut self, constraint: &'hir AssocItemConstraint<'hir>) {
384        self.insert(constraint.span, constraint.hir_id, Node::AssocItemConstraint(constraint));
385        self.with_parent(constraint.hir_id, |this| {
386            intravisit::walk_assoc_item_constraint(this, constraint)
387        })
388    }
389
390    fn visit_trait_item_ref(&mut self, id: &'hir TraitItemId) {
391        self.visit_nested_trait_item(*id);
392    }
393
394    fn visit_impl_item_ref(&mut self, id: &'hir ImplItemId) {
395        self.visit_nested_impl_item(*id);
396    }
397
398    fn visit_foreign_item_ref(&mut self, id: &'hir ForeignItemId) {
399        self.visit_nested_foreign_item(*id);
400    }
401
402    fn visit_where_predicate(&mut self, predicate: &'hir WherePredicate<'hir>) {
403        self.insert(predicate.span, predicate.hir_id, Node::WherePredicate(predicate));
404        self.with_parent(predicate.hir_id, |this| {
405            intravisit::walk_where_predicate(this, predicate)
406        });
407    }
408
409    fn visit_pattern_type_pattern(&mut self, pat: &'hir hir::TyPat<'hir>) {
410        self.insert(pat.span, pat.hir_id, Node::TyPat(pat));
411
412        self.with_parent(pat.hir_id, |this| {
413            intravisit::walk_ty_pat(this, pat);
414        });
415    }
416
417    fn visit_precise_capturing_arg(
418        &mut self,
419        arg: &'hir PreciseCapturingArg<'hir>,
420    ) -> Self::Result {
421        match arg {
422            PreciseCapturingArg::Lifetime(_) => {
423                // This is represented as a `Node::Lifetime`, intravisit will get to it below.
424            }
425            PreciseCapturingArg::Param(param) => self.insert(
426                param.ident.span,
427                param.hir_id,
428                Node::PreciseCapturingNonLifetimeArg(param),
429            ),
430        }
431        intravisit::walk_precise_capturing_arg(self, arg);
432    }
433
434    fn visit_test_binder_forall(&mut self, forall: &'hir TestBinderForall<'hir>) {
435        self.insert(forall.span, forall.hir_id, Node::TestBinderForall(forall));
436        self.with_parent(forall.hir_id, |this| intravisit::walk_test_binder_forall(this, forall))
437    }
438
439    fn visit_test_binder_exists(&mut self, exists: &'hir TestBinderExists<'hir>) {
440        self.insert(exists.span, exists.hir_id, Node::TestBinderExists(exists));
441        self.with_parent(exists.hir_id, |this| intravisit::walk_test_binder_exists(this, exists))
442    }
443
444    fn visit_test_binder_bound_type_constraint(
445        &mut self,
446        bound_type: &'hir TestBinderBoundTypeConstraint<'hir>,
447    ) {
448        self.insert(
449            bound_type.span,
450            bound_type.hir_id,
451            Node::TestBinderBoundTypeConstraint(bound_type),
452        );
453        self.with_parent(bound_type.hir_id, |this| {
454            intravisit::walk_test_binder_bound_type_constraint(this, bound_type)
455        })
456    }
457}