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