Skip to main content

rustc_middle/hir/
mod.rs

1//! HIR datatypes. See the [rustc dev guide] for more info.
2//!
3//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
4
5pub mod map;
6pub mod nested_filter;
7pub mod place;
8
9use rustc_data_structures::fingerprint::Fingerprint;
10use rustc_data_structures::sorted_map::SortedMap;
11use rustc_data_structures::stable_hash::{StableHash, StableHasher};
12use rustc_data_structures::steal::Steal;
13use rustc_data_structures::sync::{DynSend, DynSync, try_par_for_each_in};
14use rustc_hir::attrs::lang_items::LangItem;
15use rustc_hir::def::{DefKind, Res};
16use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap, LocalModId};
17use rustc_hir::lints::DelayedLints;
18use rustc_hir::*;
19use rustc_macros::{Decodable, Encodable, StableHash};
20use rustc_span::{ErrorGuaranteed, ExpnId, Span};
21
22use crate::query::Providers;
23use crate::ty::TyCtxt;
24
25/// Gather the LocalDefId for each item-like within a module, including items contained within
26/// bodies. The Ids are in visitor order. This is used to partition a pass between modules.
27#[derive(#[automatically_derived]
impl ::core::fmt::Debug for ModuleItems {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        let names: &'static _ =
            &["add_root", "submodules", "free_items", "trait_items",
                        "impl_items", "foreign_items", "opaques", "body_owners",
                        "nested_bodies", "eiis", "proc_macro_decls"];
        let values: &[&dyn ::core::fmt::Debug] =
            &[&self.add_root, &self.submodules, &self.free_items,
                        &self.trait_items, &self.impl_items, &self.foreign_items,
                        &self.opaques, &self.body_owners, &self.nested_bodies,
                        &self.eiis, &&self.proc_macro_decls];
        ::core::fmt::Formatter::debug_struct_fields_finish(f, "ModuleItems",
            names, values)
    }
}Debug, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for ModuleItems
            {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    ModuleItems {
                        add_root: ref __binding_0,
                        submodules: ref __binding_1,
                        free_items: ref __binding_2,
                        trait_items: ref __binding_3,
                        impl_items: ref __binding_4,
                        foreign_items: ref __binding_5,
                        opaques: ref __binding_6,
                        body_owners: ref __binding_7,
                        nested_bodies: ref __binding_8,
                        eiis: ref __binding_9,
                        proc_macro_decls: ref __binding_10 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                        { __binding_2.stable_hash(__hcx, __hasher); }
                        { __binding_3.stable_hash(__hcx, __hasher); }
                        { __binding_4.stable_hash(__hcx, __hasher); }
                        { __binding_5.stable_hash(__hcx, __hasher); }
                        { __binding_6.stable_hash(__hcx, __hasher); }
                        { __binding_7.stable_hash(__hcx, __hasher); }
                        { __binding_8.stable_hash(__hcx, __hasher); }
                        { __binding_9.stable_hash(__hcx, __hasher); }
                        { __binding_10.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for ModuleItems {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    ModuleItems {
                        add_root: ref __binding_0,
                        submodules: ref __binding_1,
                        free_items: ref __binding_2,
                        trait_items: ref __binding_3,
                        impl_items: ref __binding_4,
                        foreign_items: ref __binding_5,
                        opaques: ref __binding_6,
                        body_owners: ref __binding_7,
                        nested_bodies: ref __binding_8,
                        eiis: ref __binding_9,
                        proc_macro_decls: ref __binding_10 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_2,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_3,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_4,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_5,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_6,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_7,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_8,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_9,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_10,
                            __encoder);
                    }
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for ModuleItems {
            fn decode(__decoder: &mut __D) -> Self {
                ModuleItems {
                    add_root: ::rustc_serialize::Decodable::decode(__decoder),
                    submodules: ::rustc_serialize::Decodable::decode(__decoder),
                    free_items: ::rustc_serialize::Decodable::decode(__decoder),
                    trait_items: ::rustc_serialize::Decodable::decode(__decoder),
                    impl_items: ::rustc_serialize::Decodable::decode(__decoder),
                    foreign_items: ::rustc_serialize::Decodable::decode(__decoder),
                    opaques: ::rustc_serialize::Decodable::decode(__decoder),
                    body_owners: ::rustc_serialize::Decodable::decode(__decoder),
                    nested_bodies: ::rustc_serialize::Decodable::decode(__decoder),
                    eiis: ::rustc_serialize::Decodable::decode(__decoder),
                    proc_macro_decls: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable)]
28pub struct ModuleItems {
29    /// Whether this represents the whole crate, in which case we need to add `CRATE_OWNER_ID` to
30    /// the iterators if we want to account for the crate root.
31    add_root: bool,
32    submodules: Box<[LocalModId]>,
33    free_items: Box<[ItemId]>,
34    trait_items: Box<[TraitItemId]>,
35    impl_items: Box<[ImplItemId]>,
36    foreign_items: Box<[ForeignItemId]>,
37    opaques: Box<[LocalDefId]>,
38    body_owners: Box<[LocalDefId]>,
39    nested_bodies: Box<[LocalDefId]>,
40
41    /// Statics and functions with an `EiiImpls` or `EiiExternTarget` attribute
42    eiis: Box<[LocalDefId]>,
43
44    // only filled with hir_crate_items, not with hir_module_items
45    proc_macro_decls: Option<LocalDefId>,
46}
47
48impl ModuleItems {
49    /// Returns all non-associated locally defined items in all modules.
50    ///
51    /// Note that this does *not* include associated items of `impl` blocks! It also does not
52    /// include foreign items. If you want to e.g. get all functions, use `definitions()` below.
53    ///
54    /// However, this does include the `impl` blocks themselves.
55    pub fn free_items(&self) -> impl Iterator<Item = ItemId> {
56        self.free_items.iter().copied()
57    }
58
59    pub fn trait_items(&self) -> impl Iterator<Item = TraitItemId> {
60        self.trait_items.iter().copied()
61    }
62
63    #[inline]
64    pub fn proc_macro_decls(&self) -> Option<LocalDefId> {
65        self.proc_macro_decls
66    }
67
68    pub fn eiis(&self) -> impl Iterator<Item = LocalDefId> {
69        self.eiis.iter().copied()
70    }
71
72    /// Returns all items that are associated with some `impl` block (both inherent and trait impl
73    /// blocks).
74    pub fn impl_items(&self) -> impl Iterator<Item = ImplItemId> {
75        self.impl_items.iter().copied()
76    }
77
78    pub fn foreign_items(&self) -> impl Iterator<Item = ForeignItemId> {
79        self.foreign_items.iter().copied()
80    }
81
82    pub fn owners(&self) -> impl Iterator<Item = OwnerId> {
83        self.add_root
84            .then_some(CRATE_OWNER_ID)
85            .into_iter()
86            .chain(self.free_items.iter().map(|id| id.owner_id))
87            .chain(self.trait_items.iter().map(|id| id.owner_id))
88            .chain(self.impl_items.iter().map(|id| id.owner_id))
89            .chain(self.foreign_items.iter().map(|id| id.owner_id))
90    }
91
92    pub fn opaques(&self) -> impl Iterator<Item = LocalDefId> {
93        self.opaques.iter().copied()
94    }
95
96    /// Closures and inline consts
97    pub fn nested_bodies(&self) -> impl Iterator<Item = LocalDefId> {
98        self.nested_bodies.iter().copied()
99    }
100
101    pub fn definitions(&self) -> impl Iterator<Item = LocalDefId> {
102        self.owners().map(|id| id.def_id)
103    }
104
105    /// Closures and inline consts
106    pub fn par_nested_bodies(
107        &self,
108        f: impl Fn(LocalDefId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
109    ) -> Result<(), ErrorGuaranteed> {
110        try_par_for_each_in(&self.nested_bodies[..], |&&id| f(id))
111    }
112
113    pub fn par_items(
114        &self,
115        f: impl Fn(ItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
116    ) -> Result<(), ErrorGuaranteed> {
117        try_par_for_each_in(&self.free_items[..], |&&id| f(id))
118    }
119
120    pub fn par_trait_items(
121        &self,
122        f: impl Fn(TraitItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
123    ) -> Result<(), ErrorGuaranteed> {
124        try_par_for_each_in(&self.trait_items[..], |&&id| f(id))
125    }
126
127    pub fn par_impl_items(
128        &self,
129        f: impl Fn(ImplItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
130    ) -> Result<(), ErrorGuaranteed> {
131        try_par_for_each_in(&self.impl_items[..], |&&id| f(id))
132    }
133
134    pub fn par_foreign_items(
135        &self,
136        f: impl Fn(ForeignItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
137    ) -> Result<(), ErrorGuaranteed> {
138        try_par_for_each_in(&self.foreign_items[..], |&&id| f(id))
139    }
140
141    pub fn par_opaques(
142        &self,
143        f: impl Fn(LocalDefId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
144    ) -> Result<(), ErrorGuaranteed> {
145        try_par_for_each_in(&self.opaques[..], |&&id| f(id))
146    }
147}
148
149impl<'tcx> TyCtxt<'tcx> {
150    pub fn parent_module(self, id: HirId) -> LocalModId {
151        if !id.is_owner() && self.def_kind(id.owner) == DefKind::Mod {
152            LocalModId::new_unchecked(id.owner.def_id)
153        } else {
154            self.parent_module_from_def_id(id.owner.def_id)
155        }
156    }
157
158    pub fn parent_module_from_def_id(self, mut id: LocalDefId) -> LocalModId {
159        while let Some(parent) = self.opt_local_parent(id) {
160            id = parent;
161            if self.def_kind(id) == DefKind::Mod {
162                break;
163            }
164        }
165        LocalModId::new_unchecked(id)
166    }
167
168    /// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
169    pub fn is_foreign_item(self, def_id: impl Into<DefId>) -> bool {
170        self.opt_parent(def_id.into())
171            .is_some_and(|parent| #[allow(non_exhaustive_omitted_patterns)] match self.def_kind(parent) {
    DefKind::ForeignMod => true,
    _ => false,
}matches!(self.def_kind(parent), DefKind::ForeignMod))
172    }
173
174    pub fn hash_owner_nodes(
175        self,
176        node: OwnerNode<'_>,
177        bodies: &SortedMap<ItemLocalId, &Body<'_>>,
178        attrs: &SortedMap<ItemLocalId, &[Attribute]>,
179        define_opaque: Option<&[(Span, LocalDefId)]>,
180    ) -> Hashes {
181        if !self.needs_hir_hash() {
182            return Hashes { bodies_hash: None, attrs_hash: None };
183        }
184
185        self.with_stable_hashing_context(|mut hcx| {
186            let mut stable_hasher = StableHasher::new();
187            node.stable_hash(&mut hcx, &mut stable_hasher);
188            // Bodies are stored out of line, so we need to pull them explicitly in the hash.
189            bodies.stable_hash(&mut hcx, &mut stable_hasher);
190            let h1 = stable_hasher.finish();
191
192            let mut stable_hasher = StableHasher::new();
193            attrs.stable_hash(&mut hcx, &mut stable_hasher);
194
195            // Hash the defined opaque types, which are not present in the attrs.
196            define_opaque.stable_hash(&mut hcx, &mut stable_hasher);
197
198            let h2 = stable_hasher.finish();
199
200            Hashes { bodies_hash: Some(h1), attrs_hash: Some(h2) }
201        })
202    }
203
204    pub fn qpath_is_lang_item(self, qpath: QPath<'_>, lang_item: LangItem) -> bool {
205        self.qpath_lang_item(qpath) == Some(lang_item)
206    }
207
208    /// This does not use typeck results since this is intended to be used with generated code.
209    pub fn qpath_lang_item(self, qpath: QPath<'_>) -> Option<LangItem> {
210        if let QPath::Resolved(_, path) = qpath
211            && let Res::Def(_, def_id) = path.res
212        {
213            return self.lang_items().from_def_id(def_id);
214        }
215        None
216    }
217
218    /// Whether this expression constitutes a read of value of the type that
219    /// it evaluates to.
220    ///
221    /// This is used to determine if we should consider the block to diverge
222    /// if the expression evaluates to `!`, and if we should insert a `NeverToAny`
223    /// coercion for values of type `!`.
224    ///
225    /// This function generally returns `false` if the expression is a place
226    /// expression and the *parent* expression is the scrutinee of a match or
227    /// the pointee of an `&` addr-of expression, since both of those parent
228    /// expressions take a *place* and not a value.
229    pub fn expr_guaranteed_to_constitute_read_for_never(self, expr: &Expr<'_>) -> bool {
230        // We only care about place exprs. Anything else returns an immediate
231        // which would constitute a read. We don't care about distinguishing
232        // "syntactic" place exprs since if the base of a field projection is
233        // not a place then it would've been UB to read from it anyways since
234        // that constitutes a read.
235        if !expr.is_syntactic_place_expr() {
236            return true;
237        }
238
239        let parent_node = self.parent_hir_node(expr.hir_id);
240        match parent_node {
241            Node::Expr(parent_expr) => {
242                match parent_expr.kind {
243                    // Addr-of, field projections, and LHS of assignment don't constitute reads.
244                    // Assignment does call `drop_glue`, though, but its safety requirements are
245                    // not the same.
246                    ExprKind::AddrOf(..) | ExprKind::Field(..) => false,
247
248                    // Place-preserving expressions only constitute reads if their
249                    // parent expression constitutes a read.
250                    ExprKind::Type(..) | ExprKind::UnsafeBinderCast(..) => {
251                        self.expr_guaranteed_to_constitute_read_for_never(parent_expr)
252                    }
253
254                    ExprKind::Assign(lhs, _, _) => {
255                        // Only the LHS does not constitute a read
256                        expr.hir_id != lhs.hir_id
257                    }
258
259                    // See note on `PatKind::Or` in `Pat::is_guaranteed_to_constitute_read_for_never`
260                    // for why this is `all`.
261                    ExprKind::Match(scrutinee, arms, _) => {
262                        {
    match (&scrutinee.hir_id, &expr.hir_id) {
        (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);
            }
        }
    }
};assert_eq!(scrutinee.hir_id, expr.hir_id);
263                        arms.iter().all(|arm| arm.pat.is_guaranteed_to_constitute_read_for_never())
264                    }
265                    ExprKind::Let(LetExpr { init, pat, .. }) => {
266                        {
    match (&init.hir_id, &expr.hir_id) {
        (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);
            }
        }
    }
};assert_eq!(init.hir_id, expr.hir_id);
267                        pat.is_guaranteed_to_constitute_read_for_never()
268                    }
269
270                    // Any expression child of these expressions constitute reads.
271                    ExprKind::Array(_)
272                    | ExprKind::Call(_, _)
273                    | ExprKind::Use(_, _)
274                    | ExprKind::MethodCall(_, _, _, _)
275                    | ExprKind::Tup(_)
276                    | ExprKind::Binary(_, _, _)
277                    | ExprKind::Unary(_, _)
278                    | ExprKind::Cast(_, _)
279                    | ExprKind::DropTemps(_)
280                    | ExprKind::If(_, _, _)
281                    | ExprKind::Closure(_)
282                    | ExprKind::Block(_, _)
283                    | ExprKind::AssignOp(_, _, _)
284                    | ExprKind::Index(_, _, _)
285                    | ExprKind::Break(_, _)
286                    | ExprKind::Ret(_)
287                    | ExprKind::Become(_)
288                    | ExprKind::InlineAsm(_)
289                    | ExprKind::Struct(_, _, _)
290                    | ExprKind::Repeat(_, _)
291                    | ExprKind::Yield(_, _) => true,
292
293                    // These expressions have no (direct) sub-exprs.
294                    ExprKind::ConstBlock(_)
295                    | ExprKind::Loop(_, _, _, _)
296                    | ExprKind::Lit(_)
297                    | ExprKind::Path(_)
298                    | ExprKind::Continue(_)
299                    | ExprKind::OffsetOf(_, _)
300                    | ExprKind::Err(_) => {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("no sub-expr expected for {0:?}", expr.kind)));
}unreachable!("no sub-expr expected for {:?}", expr.kind),
301                }
302            }
303
304            // If we have a subpattern that performs a read, we want to consider this
305            // to diverge for compatibility to support something like `let x: () = *never_ptr;`.
306            Node::LetStmt(LetStmt { init: Some(target), pat, .. }) => {
307                {
    match (&target.hir_id, &expr.hir_id) {
        (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);
            }
        }
    }
};assert_eq!(target.hir_id, expr.hir_id);
308                pat.is_guaranteed_to_constitute_read_for_never()
309            }
310
311            // These nodes (if they have a sub-expr) do constitute a read.
312            Node::Block(_)
313            | Node::Arm(_)
314            | Node::ExprField(_)
315            | Node::AnonConst(_)
316            | Node::ConstBlock(_)
317            | Node::ConstArg(_)
318            | Node::Stmt(_)
319            | Node::Item(Item { kind: ItemKind::Const(..) | ItemKind::Static(..), .. })
320            | Node::TraitItem(TraitItem { kind: TraitItemKind::Const(..), .. })
321            | Node::ImplItem(ImplItem { kind: ImplItemKind::Const(..), .. }) => true,
322
323            Node::TyPat(_) | Node::Pat(_) => {
324                self.dcx().span_delayed_bug(expr.span, "place expr not allowed in pattern");
325                true
326            }
327
328            // These nodes do not have direct sub-exprs.
329            Node::Param(_)
330            | Node::Item(_)
331            | Node::ForeignItem(_)
332            | Node::TraitItem(_)
333            | Node::ImplItem(_)
334            | Node::Variant(_)
335            | Node::Field(_)
336            | Node::PathSegment(_)
337            | Node::Ty(_)
338            | Node::AssocItemConstraint(_)
339            | Node::TraitRef(_)
340            | Node::PatField(_)
341            | Node::PatExpr(_)
342            | Node::LetStmt(_)
343            | Node::Synthetic
344            | Node::Err(_)
345            | Node::Ctor(_)
346            | Node::Lifetime(_)
347            | Node::GenericParam(_)
348            | Node::Crate(_)
349            | Node::Infer(_)
350            | Node::WherePredicate(_)
351            | Node::PreciseCapturingNonLifetimeArg(_)
352            | Node::ConstArgExprField(_)
353            | Node::OpaqueTy(_) => {
354                {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("no sub-expr expected for {0:?}", parent_node)));
}unreachable!("no sub-expr expected for {parent_node:?}")
355            }
356        }
357    }
358
359    #[inline]
360    fn hir_owner_parent_impl(self, owner_id: OwnerId) -> HirId {
361        self.opt_local_parent(owner_id.def_id).map_or(CRATE_HIR_ID, |parent_def_id| {
362            let parent_owner_id = self.local_def_id_to_hir_id(parent_def_id).owner;
363            HirId {
364                owner: parent_owner_id,
365                local_id: self
366                    .hir_owner(parent_owner_id.def_id)
367                    .unwrap()
368                    .parenting
369                    .get(&owner_id.def_id)
370                    .copied()
371                    .unwrap_or(ItemLocalId::ZERO),
372            }
373        })
374    }
375
376    /// Optimization of `hir_owner_parent` query as an inlined function
377    /// in case of non-incremental build. The query itself renamed to `hir_owner_parent_q`.
378    #[inline]
379    pub fn hir_owner_parent(self, owner_id: OwnerId) -> HirId {
380        if self.dep_graph.is_fully_enabled() {
381            self.hir_owner_parent_q(owner_id)
382        } else {
383            self.hir_owner_parent_impl(owner_id)
384        }
385    }
386}
387
388/// Hashes computed by [`TyCtxt::hash_owner_nodes`] if necessary.
389#[derive(#[automatically_derived]
impl ::core::clone::Clone for Hashes {
    #[inline]
    fn clone(&self) -> Hashes {
        let _: ::core::clone::AssertParamIsClone<Option<Fingerprint>>;
        let _: ::core::clone::AssertParamIsClone<Option<Fingerprint>>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Hashes { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for Hashes {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f, "Hashes",
            "bodies_hash", &self.bodies_hash, "attrs_hash", &&self.attrs_hash)
    }
}Debug)]
390pub struct Hashes {
391    pub bodies_hash: Option<Fingerprint>,
392    pub attrs_hash: Option<Fingerprint>,
393}
394
395/// Unites some of `OwnerInfo`'s fields into same struct that is used by `hir_owner` query.
396/// `AttributeMap` is handled separately as placing it in this struct led to perf regressions:
397/// <https://github.com/rust-lang/rust/pull/155678#issuecomment-4304597871>.
398/// This struct is created mainly for uniting/splitting fields of `OwnerInfo` so they are
399/// stored/invalidated together in incremental compilation.
400/// For comments about each field see `OwnerInfo` struct.
401#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for ProjectedOwnerInfo<'tcx> {
    #[inline]
    fn clone(&self) -> ProjectedOwnerInfo<'tcx> {
        let _: ::core::clone::AssertParamIsClone<&'tcx OwnerNodes<'tcx>>;
        let _:
                ::core::clone::AssertParamIsClone<&'tcx LocalDefIdMap<ItemLocalId>>;
        let _:
                ::core::clone::AssertParamIsClone<&'tcx ItemLocalMap<&'tcx [TraitCandidate<'tcx>]>>;
        let _: ::core::clone::AssertParamIsClone<&'tcx Steal<DelayedLints>>;
        *self
    }
}Clone, #[automatically_derived]
impl<'tcx> ::core::marker::Copy for ProjectedOwnerInfo<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ProjectedOwnerInfo<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field4_finish(f,
            "ProjectedOwnerInfo", "nodes", &self.nodes, "parenting",
            &self.parenting, "trait_map", &self.trait_map, "delayed_lints",
            &&self.delayed_lints)
    }
}Debug, const _: () =
    {
        impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
            ProjectedOwnerInfo<'tcx> {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    ProjectedOwnerInfo {
                        nodes: ref __binding_0,
                        parenting: ref __binding_1,
                        trait_map: ref __binding_2,
                        delayed_lints: ref __binding_3 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                        { __binding_2.stable_hash(__hcx, __hasher); }
                        {}
                    }
                }
            }
        }
    };StableHash)]
402pub struct ProjectedOwnerInfo<'tcx> {
403    nodes: &'tcx OwnerNodes<'tcx>,
404    parenting: &'tcx LocalDefIdMap<ItemLocalId>,
405    trait_map: &'tcx ItemLocalMap<&'tcx [TraitCandidate<'tcx>]>,
406
407    #[stable_hash(ignore)]
408    delayed_lints: &'tcx Steal<DelayedLints>,
409}
410
411impl<'tcx> ProjectedOwnerInfo<'tcx> {
412    pub fn new(
413        nodes: &'tcx OwnerNodes<'tcx>,
414        parenting: &'tcx LocalDefIdMap<ItemLocalId>,
415        trait_map: &'tcx ItemLocalMap<&'tcx [TraitCandidate<'tcx>]>,
416        delayed_lints: &'tcx Steal<DelayedLints>,
417    ) -> ProjectedOwnerInfo<'tcx> {
418        ProjectedOwnerInfo { nodes, parenting, trait_map, delayed_lints }
419    }
420}
421
422#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for ProjectedMaybeOwner<'tcx> {
    #[inline]
    fn clone(&self) -> ProjectedMaybeOwner<'tcx> {
        let _: ::core::clone::AssertParamIsClone<ProjectedOwnerInfo<'tcx>>;
        let _: ::core::clone::AssertParamIsClone<HirId>;
        *self
    }
}Clone, #[automatically_derived]
impl<'tcx> ::core::marker::Copy for ProjectedMaybeOwner<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ProjectedMaybeOwner<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            ProjectedMaybeOwner::Owner(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Owner",
                    &__self_0),
            ProjectedMaybeOwner::NonOwner(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "NonOwner", &__self_0),
        }
    }
}Debug, const _: () =
    {
        impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
            ProjectedMaybeOwner<'tcx> {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                ::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
                match *self {
                    ProjectedMaybeOwner::Owner(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    ProjectedMaybeOwner::NonOwner(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash)]
423pub enum ProjectedMaybeOwner<'tcx> {
424    Owner(ProjectedOwnerInfo<'tcx>),
425    NonOwner(HirId),
426}
427
428impl<'tcx> ProjectedMaybeOwner<'tcx> {
429    pub fn new(value: MaybeOwner<'tcx>) -> Self {
430        match value {
431            MaybeOwner::Owner(o) => ProjectedMaybeOwner::Owner(ProjectedOwnerInfo {
432                nodes: &o.nodes,
433                parenting: &o.parenting,
434                trait_map: &o.trait_map,
435                delayed_lints: &o.delayed_lints,
436            }),
437            MaybeOwner::NonOwner(hir_id) => ProjectedMaybeOwner::NonOwner(hir_id),
438        }
439    }
440
441    pub fn as_owner(&self) -> Option<&ProjectedOwnerInfo<'tcx>> {
442        match self {
443            ProjectedMaybeOwner::Owner(i) => Some(i),
444            ProjectedMaybeOwner::NonOwner(_) => None,
445        }
446    }
447
448    pub fn unwrap(&'tcx self) -> &'tcx ProjectedOwnerInfo<'tcx> {
449        self.as_owner().unwrap_or_else(|| { ::core::panicking::panic_fmt(format_args!("Not a HIR owner")); }panic!("Not a HIR owner"))
450    }
451}
452
453pub fn provide(providers: &mut Providers) {
454    providers.hir_crate_items = map::hir_crate_items;
455    providers.crate_hash = map::crate_hash;
456    providers.hir_module_items = map::hir_module_items;
457    providers.hir_attr_map =
458        |tcx, id| tcx.lower_to_hir(id).as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs);
459    providers.hir_owner = |tcx, def_id| ProjectedMaybeOwner::new(tcx.lower_to_hir(def_id));
460    providers.hir_owner_parent_q = |tcx, owner_id| tcx.hir_owner_parent_impl(owner_id);
461    providers.def_span = |tcx, def_id| tcx.hir_span(tcx.local_def_id_to_hir_id(def_id));
462    providers.def_ident_span = |tcx, def_id| {
463        let hir_id = tcx.local_def_id_to_hir_id(def_id);
464        tcx.hir_opt_ident_span(hir_id)
465    };
466    providers.ty_span = |tcx, def_id| {
467        let node = tcx.hir_node_by_def_id(def_id);
468        match node.ty() {
469            Some(ty) => ty.span,
470            None => crate::util::bug::bug_fmt(format_args!("{0:?} doesn\'t have a type: {1:#?}",
        def_id, node))bug!("{def_id:?} doesn't have a type: {node:#?}"),
471        }
472    };
473    providers.fn_arg_idents = |tcx, def_id| {
474        let node = tcx.hir_node_by_def_id(def_id);
475        if let Some(body_id) = node.body_id() {
476            tcx.arena.alloc_from_iter(tcx.hir_body_param_idents(body_id))
477        } else if let Node::TraitItem(&TraitItem {
478            kind: TraitItemKind::Fn(_, TraitFn::Required(idents)),
479            ..
480        })
481        | Node::ForeignItem(&ForeignItem {
482            kind: ForeignItemKind::Fn(_, idents, _),
483            ..
484        }) = node
485        {
486            idents
487        } else {
488            crate::util::bug::span_bug_fmt(tcx.hir_span(tcx.local_def_id_to_hir_id(def_id)),
    format_args!("fn_arg_idents: unexpected item {0:?}", def_id));span_bug!(
489                tcx.hir_span(tcx.local_def_id_to_hir_id(def_id)),
490                "fn_arg_idents: unexpected item {:?}",
491                def_id
492            );
493        }
494    };
495    providers.all_local_trait_impls = |tcx, ()| &tcx.resolutions(()).trait_impls;
496    providers.local_trait_impls =
497        |tcx, trait_id| tcx.resolutions(()).trait_impls.get(&trait_id).map_or(&[], |xs| &xs[..]);
498    providers.expn_that_defined =
499        |tcx, id| tcx.resolutions(()).expn_that_defined.get(&id).copied().unwrap_or(ExpnId::root());
500}