Skip to main content

rustc_middle/middle/
resolve.rs

1//! This module contains types that carry name resolution results from `rustc_resolve` to a
2//! consumer in another crate (e.g. AST lowering, metadata, or a query).
3
4use rustc_ast::node_id::NodeMap;
5use rustc_ast::{self as ast, NodeId};
6use rustc_attr_ir::StrippedCfgItem;
7use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
8use rustc_data_structures::steal::Steal;
9use rustc_data_structures::unord::{UnordMap, UnordSet};
10use rustc_errors::{ErrorGuaranteed, LintBuffer};
11use rustc_hir::def::{DefKind, Namespace, PerNS, Res};
12use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap, LocalModId, ModId};
13use rustc_hir::definitions::PerParentDisambiguatorState;
14use rustc_hir::{MissingLifetimeKind, TraitCandidate};
15use rustc_macros::{StableHash, TyDecodable, TyEncodable};
16use rustc_span::{ExpnId, Ident, Span, Symbol};
17use smallvec::SmallVec;
18
19use crate::middle::privacy::EffectiveVisibilities;
20use crate::ty::Visibility;
21
22/// The result of resolving a path before lowering to HIR,
23/// with "module" segments resolved and associated item
24/// segments deferred to type checking.
25/// `base_res` is the resolution of the resolved part of the
26/// path, `unresolved_segments` is the number of unresolved
27/// segments.
28///
29/// ```text
30/// module::Type::AssocX::AssocY::MethodOrAssocType
31/// ^~~~~~~~~~~~  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32/// base_res      unresolved_segments = 3
33///
34/// <T as Trait>::AssocX::AssocY::MethodOrAssocType
35///       ^~~~~~~~~~~~~~  ^~~~~~~~~~~~~~~~~~~~~~~~~
36///       base_res        unresolved_segments = 2
37/// ```
38#[derive(#[automatically_derived]
impl ::core::marker::Copy for PartialRes { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for PartialRes { }
#[automatically_derived]
impl ::core::clone::Clone for PartialRes {
    #[inline]
    fn clone(&self) -> PartialRes {
        let _: ::core::clone::AssertParamIsClone<Res<NodeId>>;
        let _: ::core::clone::AssertParamIsClone<usize>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for PartialRes {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f, "PartialRes",
            "base_res", &self.base_res, "unresolved_segments",
            &&self.unresolved_segments)
    }
}Debug)]
39pub struct PartialRes {
40    base_res: Res<NodeId>,
41    unresolved_segments: usize,
42}
43
44impl PartialRes {
45    #[inline]
46    pub fn new(base_res: Res<NodeId>) -> Self {
47        PartialRes { base_res, unresolved_segments: 0 }
48    }
49
50    #[inline]
51    pub fn with_unresolved_segments(base_res: Res<NodeId>, mut unresolved_segments: usize) -> Self {
52        if base_res == Res::Err {
53            unresolved_segments = 0
54        }
55        PartialRes { base_res, unresolved_segments }
56    }
57
58    #[inline]
59    pub fn base_res(&self) -> Res<NodeId> {
60        self.base_res
61    }
62
63    #[inline]
64    pub fn unresolved_segments(&self) -> usize {
65        self.unresolved_segments
66    }
67
68    #[inline]
69    pub fn full_res(&self) -> Option<Res<NodeId>> {
70        (self.unresolved_segments == 0).then_some(self.base_res)
71    }
72
73    #[inline]
74    pub fn expect_full_res(&self) -> Res<NodeId> {
75        self.full_res().expect("unexpected unresolved segments")
76    }
77}
78
79/// Resolution for a lifetime appearing in a type.
80#[derive(#[automatically_derived]
impl ::core::marker::Copy for LifetimeRes { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for LifetimeRes { }
#[automatically_derived]
impl ::core::clone::Clone for LifetimeRes {
    #[inline]
    fn clone(&self) -> LifetimeRes {
        let _: ::core::clone::AssertParamIsClone<LocalDefId>;
        let _: ::core::clone::AssertParamIsClone<NodeId>;
        let _: ::core::clone::AssertParamIsClone<MissingLifetimeKind>;
        let _: ::core::clone::AssertParamIsClone<ErrorGuaranteed>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for LifetimeRes {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            LifetimeRes::Param { param: __self_0, binder: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f, "Param",
                    "param", __self_0, "binder", &__self_1),
            LifetimeRes::Fresh { param: __self_0, kind: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f, "Fresh",
                    "param", __self_0, "kind", &__self_1),
            LifetimeRes::Infer =>
                ::core::fmt::Formatter::write_str(f, "Infer"),
            LifetimeRes::Static =>
                ::core::fmt::Formatter::write_str(f, "Static"),
            LifetimeRes::Error(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Error",
                    &__self_0),
            LifetimeRes::ElidedAnchor { start: __self_0, end: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f,
                    "ElidedAnchor", "start", __self_0, "end", &__self_1),
        }
    }
}Debug, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for LifetimeRes { }
#[automatically_derived]
impl ::core::cmp::PartialEq for LifetimeRes {
    #[inline]
    fn eq(&self, other: &LifetimeRes) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (LifetimeRes::Param { param: __self_0, binder: __self_1 },
                    LifetimeRes::Param { param: __arg1_0, binder: __arg1_1 }) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                (LifetimeRes::Fresh { param: __self_0, kind: __self_1 },
                    LifetimeRes::Fresh { param: __arg1_0, kind: __arg1_1 }) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                (LifetimeRes::Error(__self_0), LifetimeRes::Error(__arg1_0))
                    => __self_0 == __arg1_0,
                (LifetimeRes::ElidedAnchor { start: __self_0, end: __self_1 },
                    LifetimeRes::ElidedAnchor { start: __arg1_0, end: __arg1_1
                    }) => __self_0 == __arg1_0 && __self_1 == __arg1_1,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for LifetimeRes {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<LocalDefId>;
        let _: ::core::cmp::AssertParamIsEq<NodeId>;
        let _: ::core::cmp::AssertParamIsEq<MissingLifetimeKind>;
        let _: ::core::cmp::AssertParamIsEq<ErrorGuaranteed>;
    }
}Eq, #[automatically_derived]
impl ::core::hash::Hash for LifetimeRes {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state);
        match self {
            LifetimeRes::Param { param: __self_0, binder: __self_1 } => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state)
            }
            LifetimeRes::Fresh { param: __self_0, kind: __self_1 } => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state)
            }
            LifetimeRes::Error(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            LifetimeRes::ElidedAnchor { start: __self_0, end: __self_1 } => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state)
            }
            _ => {}
        }
    }
}Hash)]
81pub enum LifetimeRes {
82    /// Successfully linked the lifetime to a generic parameter.
83    Param {
84        /// Id of the generic parameter that introduced it.
85        param: LocalDefId,
86        /// Id of the introducing place. That can be:
87        /// - an item's id, for the item's generic parameters;
88        /// - a TraitRef's ref_id, identifying the `for<...>` binder;
89        /// - a FnPtr type's id.
90        ///
91        /// This information is used for impl-trait lifetime captures, to know when to or not to
92        /// capture any given lifetime.
93        binder: NodeId,
94    },
95    /// Created a generic parameter for an anonymous lifetime.
96    Fresh {
97        /// Id of the generic parameter that introduced it.
98        ///
99        /// Creating the associated `LocalDefId` is the responsibility of lowering.
100        param: NodeId,
101        /// Kind of elided lifetime
102        kind: MissingLifetimeKind,
103    },
104    /// This variant is used for anonymous lifetimes that we did not resolve during
105    /// late resolution. Those lifetimes will be inferred by typechecking.
106    Infer,
107    /// `'static` lifetime.
108    Static,
109    /// Resolution failure.
110    Error(ErrorGuaranteed),
111    /// HACK: This is used to recover the NodeId of an elided lifetime.
112    ElidedAnchor { start: NodeId, end: NodeId },
113}
114
115/// A simplified version of `ImportKind` from resolve.
116/// `DefId`s here correspond to `use` and `extern crate` items themselves, not their targets.
117#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for Reexport { }
#[automatically_derived]
impl ::core::clone::Clone for Reexport {
    #[inline]
    fn clone(&self) -> Reexport {
        let _: ::core::clone::AssertParamIsClone<DefId>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Reexport { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for Reexport {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Reexport::Single(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Single",
                    &__self_0),
            Reexport::Glob(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Glob",
                    &__self_0),
            Reexport::ExternCrate(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "ExternCrate", &__self_0),
            Reexport::MacroUse =>
                ::core::fmt::Formatter::write_str(f, "MacroUse"),
            Reexport::MacroExport =>
                ::core::fmt::Formatter::write_str(f, "MacroExport"),
        }
    }
}Debug, const _: () =
    {
        impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
            ::rustc_serialize::Encodable<__E> for Reexport {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        Reexport::Single(ref __binding_0) => { 0usize }
                        Reexport::Glob(ref __binding_0) => { 1usize }
                        Reexport::ExternCrate(ref __binding_0) => { 2usize }
                        Reexport::MacroUse => { 3usize }
                        Reexport::MacroExport => { 4usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    Reexport::Single(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    Reexport::Glob(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    Reexport::ExternCrate(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    Reexport::MacroUse => {}
                    Reexport::MacroExport => {}
                }
            }
        }
    };TyEncodable, const _: () =
    {
        impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
            ::rustc_serialize::Decodable<__D> for Reexport {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => {
                        Reexport::Single(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    1usize => {
                        Reexport::Glob(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    2usize => {
                        Reexport::ExternCrate(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    3usize => { Reexport::MacroUse }
                    4usize => { Reexport::MacroExport }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `Reexport`, expected 0..5, actual {0}",
                                n));
                    }
                }
            }
        }
    };TyDecodable, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for Reexport {
            #[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 {
                    Reexport::Single(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    Reexport::Glob(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    Reexport::ExternCrate(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    Reexport::MacroUse => {}
                    Reexport::MacroExport => {}
                }
            }
        }
    };StableHash)]
118pub enum Reexport {
119    Single(DefId),
120    Glob(DefId),
121    ExternCrate(DefId),
122    MacroUse,
123    MacroExport,
124}
125
126impl Reexport {
127    pub fn id(self) -> Option<DefId> {
128        match self {
129            Reexport::Single(id) | Reexport::Glob(id) | Reexport::ExternCrate(id) => Some(id),
130            Reexport::MacroUse | Reexport::MacroExport => None,
131        }
132    }
133}
134
135/// This structure is supposed to keep enough data to re-create `Decl`s for other crates
136/// during name resolution. Right now the bindings are not recreated entirely precisely so we may
137/// need to add more data in the future to correctly support macros 2.0, for example.
138/// Module child can be either a proper item or a reexport (including private imports).
139/// In case of reexport all the fields describe the reexport item itself, not what it refers to.
140#[derive(#[automatically_derived]
impl ::core::fmt::Debug for ModChild {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field4_finish(f, "ModChild",
            "ident", &self.ident, "res", &self.res, "vis", &self.vis,
            "reexport_chain", &&self.reexport_chain)
    }
}Debug, const _: () =
    {
        impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
            ::rustc_serialize::Encodable<__E> for ModChild {
            fn encode(&self, __encoder: &mut __E) {
                let ModChild {
                        ident: ref __binding_0,
                        res: ref __binding_1,
                        vis: ref __binding_2,
                        reexport_chain: ref __binding_3 } = *self;
                ::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);
            }
        }
    };TyEncodable, const _: () =
    {
        impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
            ::rustc_serialize::Decodable<__D> for ModChild {
            fn decode(__decoder: &mut __D) -> Self {
                ModChild {
                    ident: ::rustc_serialize::Decodable::decode(__decoder),
                    res: ::rustc_serialize::Decodable::decode(__decoder),
                    vis: ::rustc_serialize::Decodable::decode(__decoder),
                    reexport_chain: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };TyDecodable, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for ModChild {
            #[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 {
                    ModChild {
                        ident: ref __binding_0,
                        res: ref __binding_1,
                        vis: ref __binding_2,
                        reexport_chain: ref __binding_3 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                        { __binding_2.stable_hash(__hcx, __hasher); }
                        { __binding_3.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash)]
141pub struct ModChild {
142    /// Name of the item.
143    pub ident: Ident,
144    /// Resolution result corresponding to the item.
145    /// Local variables cannot be exported, so this `Res` doesn't need the ID parameter.
146    pub res: Res<!>,
147    /// Visibility of the item.
148    pub vis: Visibility<ModId>,
149    /// Reexport chain linking this module child to its original reexported item.
150    /// Empty if the module child is a proper item.
151    pub reexport_chain: SmallVec<[Reexport; 2]>,
152}
153
154/// Same as `ModChild`, however, it includes ambiguity error.
155#[derive(#[automatically_derived]
impl ::core::fmt::Debug for AmbigModChild {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f, "AmbigModChild",
            "main", &self.main, "second", &&self.second)
    }
}Debug, const _: () =
    {
        impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
            ::rustc_serialize::Encodable<__E> for AmbigModChild {
            fn encode(&self, __encoder: &mut __E) {
                let AmbigModChild {
                        main: ref __binding_0, second: ref __binding_1 } = *self;
                ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                    __encoder);
                ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                    __encoder);
            }
        }
    };TyEncodable, const _: () =
    {
        impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
            ::rustc_serialize::Decodable<__D> for AmbigModChild {
            fn decode(__decoder: &mut __D) -> Self {
                AmbigModChild {
                    main: ::rustc_serialize::Decodable::decode(__decoder),
                    second: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };TyDecodable, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for
            AmbigModChild {
            #[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 {
                    AmbigModChild {
                        main: ref __binding_0, second: ref __binding_1 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash)]
156pub struct AmbigModChild {
157    pub main: ModChild,
158    pub second: ModChild,
159}
160
161#[derive(#[automatically_derived]
impl ::core::fmt::Debug for ResolverGlobalCtxt {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        let names: &'static _ =
            &["visibilities_for_hashing", "expn_that_defined",
                        "effective_visibilities", "macro_reachable_adts",
                        "extern_crate_map", "maybe_unused_trait_imports",
                        "module_children", "ambig_module_children", "glob_map",
                        "main_def", "trait_impls", "proc_macros",
                        "confused_type_with_std_module", "doc_link_resolutions",
                        "doc_link_traits_in_scope", "all_macro_rules",
                        "stripped_cfg_items", "delegation_infos",
                        "delegation_inherent_fn_map"];
        let values: &[&dyn ::core::fmt::Debug] =
            &[&self.visibilities_for_hashing, &self.expn_that_defined,
                        &self.effective_visibilities, &self.macro_reachable_adts,
                        &self.extern_crate_map, &self.maybe_unused_trait_imports,
                        &self.module_children, &self.ambig_module_children,
                        &self.glob_map, &self.main_def, &self.trait_impls,
                        &self.proc_macros, &self.confused_type_with_std_module,
                        &self.doc_link_resolutions, &self.doc_link_traits_in_scope,
                        &self.all_macro_rules, &self.stripped_cfg_items,
                        &self.delegation_infos, &&self.delegation_inherent_fn_map];
        ::core::fmt::Formatter::debug_struct_fields_finish(f,
            "ResolverGlobalCtxt", names, values)
    }
}Debug, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for
            ResolverGlobalCtxt {
            #[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 {
                    ResolverGlobalCtxt {
                        visibilities_for_hashing: ref __binding_0,
                        expn_that_defined: ref __binding_1,
                        effective_visibilities: ref __binding_2,
                        macro_reachable_adts: ref __binding_3,
                        extern_crate_map: ref __binding_4,
                        maybe_unused_trait_imports: ref __binding_5,
                        module_children: ref __binding_6,
                        ambig_module_children: ref __binding_7,
                        glob_map: ref __binding_8,
                        main_def: ref __binding_9,
                        trait_impls: ref __binding_10,
                        proc_macros: ref __binding_11,
                        confused_type_with_std_module: ref __binding_12,
                        doc_link_resolutions: ref __binding_13,
                        doc_link_traits_in_scope: ref __binding_14,
                        all_macro_rules: ref __binding_15,
                        stripped_cfg_items: ref __binding_16,
                        delegation_infos: ref __binding_17,
                        delegation_inherent_fn_map: ref __binding_18 } => {
                        { __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); }
                        { __binding_11.stable_hash(__hcx, __hasher); }
                        { __binding_12.stable_hash(__hcx, __hasher); }
                        { __binding_13.stable_hash(__hcx, __hasher); }
                        { __binding_14.stable_hash(__hcx, __hasher); }
                        { __binding_15.stable_hash(__hcx, __hasher); }
                        { __binding_16.stable_hash(__hcx, __hasher); }
                        { __binding_17.stable_hash(__hcx, __hasher); }
                        { __binding_18.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash)]
162pub struct ResolverGlobalCtxt {
163    pub visibilities_for_hashing: Vec<(LocalDefId, Visibility)>,
164    /// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`.
165    pub expn_that_defined: UnordMap<LocalDefId, ExpnId>,
166    pub effective_visibilities: EffectiveVisibilities,
167    // FIXME: This table contains ADTs reachable from macro 2.0.
168    // Currently, reachability of a definition from a macro is determined by nominal visibility
169    // (see `compute_effective_visibilities`). This is incorrect and leads to the necessity
170    // of traversing ADT fields in `rustc_privacy`. Remove this workaround once the
171    // correct reachability logic is implemented for macros.
172    pub macro_reachable_adts: FxIndexMap<LocalDefId, FxIndexSet<LocalDefId>>,
173    pub extern_crate_map: UnordMap<LocalDefId, CrateNum>,
174    pub maybe_unused_trait_imports: FxIndexSet<LocalDefId>,
175    pub module_children: LocalDefIdMap<Vec<ModChild>>,
176    pub ambig_module_children: LocalDefIdMap<Vec<AmbigModChild>>,
177    pub glob_map: FxIndexMap<LocalDefId, FxIndexSet<Symbol>>,
178    pub main_def: Option<MainDefinition>,
179    pub trait_impls: FxIndexMap<DefId, Vec<LocalDefId>>,
180    /// A list of proc macro LocalDefIds, written out in the order in which
181    /// they are declared in the static array generated by proc_macro_harness.
182    pub proc_macros: Vec<LocalDefId>,
183    /// Mapping from ident span to path span for paths that don't exist as written, but that
184    /// exist under `std`. For example, wrote `str::from_utf8` instead of `std::str::from_utf8`.
185    pub confused_type_with_std_module: FxIndexMap<Span, Span>,
186    pub doc_link_resolutions: FxIndexMap<LocalModId, DocLinkResMap>,
187    pub doc_link_traits_in_scope: FxIndexMap<LocalModId, Vec<DefId>>,
188    pub all_macro_rules: UnordSet<Symbol>,
189    pub stripped_cfg_items: Vec<StrippedCfgItem>,
190    // Information about delegations which is used when handling recursive delegations
191    // and ensures easy access to delegation-only `LocalDefId`s.
192    pub delegation_infos: FxIndexMap<LocalDefId, DelegationInfo>,
193    pub delegation_inherent_fn_map:
194        FxIndexMap<LocalDefId, FxIndexMap<Ident, DelegationInherentFnKind>>,
195}
196
197#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for PerOwnerResolverData<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        let names: &'static _ =
            &["node_id_to_def_id", "lifetime_elision_allowed",
                        "label_res_map", "lifetimes_res_map", "trait_map",
                        "import_res", "extra_lifetime_params_map", "id", "def_id"];
        let values: &[&dyn ::core::fmt::Debug] =
            &[&self.node_id_to_def_id, &self.lifetime_elision_allowed,
                        &self.label_res_map, &self.lifetimes_res_map,
                        &self.trait_map, &self.import_res,
                        &self.extra_lifetime_params_map, &self.id, &&self.def_id];
        ::core::fmt::Formatter::debug_struct_fields_finish(f,
            "PerOwnerResolverData", names, values)
    }
}Debug)]
198pub struct PerOwnerResolverData<'tcx> {
199    pub node_id_to_def_id: NodeMap<LocalDefId> = Default::default(),
200    /// Whether lifetime elision was successful.
201    pub lifetime_elision_allowed: bool = false,
202    /// Resolutions for labels. Maps from NodeId of the break/continue expression to the NodeId of
203    /// their corresponding blocks or loops.
204    pub label_res_map: NodeMap<NodeId> = Default::default(),
205    /// Resolutions for lifetimes.
206    pub lifetimes_res_map: NodeMap<LifetimeRes> = Default::default(),
207
208    pub trait_map: NodeMap<&'tcx [TraitCandidate<'tcx>]> = Default::default(),
209
210    /// Resolution for import nodes, which have multiple resolutions in different namespaces.
211    pub import_res: PerNS<Option<Res<NodeId>>> = Default::default(),
212    /// Lifetime parameters that lowering will have to introduce.
213    pub extra_lifetime_params_map: NodeMap<Vec<(Ident, NodeId, MissingLifetimeKind)>> =
214        Default::default(),
215
216    /// The id of the owner
217    pub id: NodeId,
218    /// The `DefId` of the owner, can't be found in `node_id_to_def_id`.
219    pub def_id: LocalDefId,
220}
221
222impl<'tcx> PerOwnerResolverData<'tcx> {
223    pub fn new(id: NodeId, def_id: LocalDefId) -> PerOwnerResolverData<'tcx> {
224        PerOwnerResolverData { id, def_id, .. }
225    }
226
227    /// Obtains resolution for a label with the given `NodeId`.
228    pub fn get_label_res(&self, id: NodeId) -> Option<NodeId> {
229        self.label_res_map.get(&id).copied()
230    }
231
232    /// Obtains resolution for a lifetime with the given `NodeId`.
233    pub fn get_lifetime_res(&self, id: NodeId) -> Option<LifetimeRes> {
234        self.lifetimes_res_map.get(&id).copied()
235    }
236
237    /// Obtain the list of lifetimes parameters to add to an item.
238    ///
239    /// Extra lifetime parameters should only be added in places that can appear
240    /// as a `binder` in `LifetimeRes`.
241    ///
242    /// The extra lifetimes that appear from the parenthesized `Fn`-trait desugaring
243    /// should appear at the enclosing `PolyTraitRef`.
244    pub fn extra_lifetime_params(&self, id: NodeId) -> &[(Ident, NodeId, MissingLifetimeKind)] {
245        self.extra_lifetime_params_map.get(&id).map_or(&[], |v| &v[..])
246    }
247}
248
249/// Resolutions that should only be used for lowering.
250/// This struct is meant to be consumed by lowering.
251#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ResolverAstLowering<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field5_finish(f,
            "ResolverAstLowering", "partial_res_map", &self.partial_res_map,
            "next_node_id", &self.next_node_id, "owners", &self.owners,
            "lint_buffer", &self.lint_buffer, "disambiguators",
            &&self.disambiguators)
    }
}Debug)]
252pub struct ResolverAstLowering<'tcx> {
253    /// Resolutions for nodes that have a single resolution.
254    pub partial_res_map: NodeMap<PartialRes>,
255
256    pub next_node_id: NodeId,
257
258    pub owners: NodeMap<PerOwnerResolverData<'tcx>>,
259
260    /// Lints that were emitted by the resolver and early lints.
261    pub lint_buffer: Steal<LintBuffer>,
262
263    pub disambiguators: LocalDefIdMap<Steal<PerParentDisambiguatorState>>,
264}
265
266#[derive(#[automatically_derived]
impl ::core::fmt::Debug for DelegationResolution {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            DelegationResolution::Full(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Full",
                    &__self_0),
            DelegationResolution::PartialCall(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "PartialCall", &__self_0),
            DelegationResolution::Partial =>
                ::core::fmt::Formatter::write_str(f, "Partial"),
            DelegationResolution::Error(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Error",
                    &__self_0),
        }
    }
}Debug, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for DelegationResolution { }
#[automatically_derived]
impl ::core::clone::Clone for DelegationResolution {
    #[inline]
    fn clone(&self) -> DelegationResolution {
        let _: ::core::clone::AssertParamIsClone<DefId>;
        let _: ::core::clone::AssertParamIsClone<ErrorGuaranteed>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for DelegationResolution { }Copy, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for
            DelegationResolution {
            #[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 {
                    DelegationResolution::Full(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    DelegationResolution::PartialCall(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    DelegationResolution::Partial => {}
                    DelegationResolution::Error(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash)]
267pub enum DelegationResolution {
268    /// Corresponds to paths that are fully resolved by resolver (i.e., `reuse Trait::foo`).
269    Full(DefId /* Signature and call path resolutions are the same */),
270
271    /// We can encounter cases like delegation to inherent impl function from trait impl,
272    /// in this case we will have resolved signature id, but the call-path itself will
273    /// not be resolved, so we will need to use type-relative resolution routine during
274    /// AST -> HIR lowering.
275    PartialCall(DefId /* Signature resolution, call path is unresolved */),
276
277    /// Corresponds to paths that are partially resolved by resolver (i.e., `reuse Struct::foo`).
278    Partial,
279
280    Error(ErrorGuaranteed),
281}
282
283#[derive(#[automatically_derived]
impl ::core::fmt::Debug for DelegationInfo {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field1_finish(f,
            "DelegationInfo", "resolution", &&self.resolution)
    }
}Debug, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for
            DelegationInfo {
            #[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 {
                    DelegationInfo { resolution: ref __binding_0 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash)]
284pub struct DelegationInfo {
285    // `DefId` (either the resolution at delegation.id or item_id in case of a trait impl) for signature resolution,
286    // for details see https://github.com/rust-lang/rust/issues/118212#issuecomment-2160686914
287    /// Refers to the next element in a delegation resolution chain.
288    /// Usually points to the final resolution, as most "chains" are just
289    /// one step to a trait or an impl.
290    pub resolution: DelegationResolution,
291}
292
293#[derive(#[automatically_derived]
impl ::core::fmt::Debug for TypeRelativeDelegationRes {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            TypeRelativeDelegationRes::Ok(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Ok",
                    &__self_0),
            TypeRelativeDelegationRes::Ambig(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Ambig",
                    &__self_0),
            TypeRelativeDelegationRes::Error(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Error",
                    &__self_0),
        }
    }
}Debug, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for
            TypeRelativeDelegationRes {
            #[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 {
                    TypeRelativeDelegationRes::Ok(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    TypeRelativeDelegationRes::Ambig(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    TypeRelativeDelegationRes::Error(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash)]
294pub enum TypeRelativeDelegationRes {
295    Ok(DefId),
296    Ambig(ErrorGuaranteed),
297    Error(ErrorGuaranteed),
298}
299
300#[derive(#[automatically_derived]
impl ::core::fmt::Debug for DelegationInherentFnKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            DelegationInherentFnKind::Single(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Single",
                    &__self_0),
            DelegationInherentFnKind::Ambig =>
                ::core::fmt::Formatter::write_str(f, "Ambig"),
        }
    }
}Debug, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for
            DelegationInherentFnKind {
            #[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 {
                    DelegationInherentFnKind::Single(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    DelegationInherentFnKind::Ambig => {}
                }
            }
        }
    };StableHash)]
301pub enum DelegationInherentFnKind {
302    Single(LocalDefId),
303    Ambig,
304}
305
306#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for MainDefinition { }
#[automatically_derived]
impl ::core::clone::Clone for MainDefinition {
    #[inline]
    fn clone(&self) -> MainDefinition {
        let _: ::core::clone::AssertParamIsClone<Res<NodeId>>;
        let _: ::core::clone::AssertParamIsClone<bool>;
        let _: ::core::clone::AssertParamIsClone<Span>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for MainDefinition { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for MainDefinition {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field3_finish(f,
            "MainDefinition", "res", &self.res, "is_import", &self.is_import,
            "span", &&self.span)
    }
}Debug, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for
            MainDefinition {
            #[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 {
                    MainDefinition {
                        res: ref __binding_0,
                        is_import: ref __binding_1,
                        span: ref __binding_2 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                        { __binding_2.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash)]
307pub struct MainDefinition {
308    pub res: Res<NodeId>,
309    pub is_import: bool,
310    pub span: Span,
311}
312
313impl MainDefinition {
314    pub fn opt_fn_def_id(self) -> Option<DefId> {
315        if let Res::Def(DefKind::Fn, def_id) = self.res { Some(def_id) } else { None }
316    }
317}
318
319// FxIndexMap is necessary because its data ends up in .rmeta files,
320// so its iteration order must be consistent. See #159677 for context.
321pub type DocLinkResMap = FxIndexMap<(Symbol, Namespace), Option<Res<NodeId>>>;
322
323/// Fragment of the AST according to "HIR owner" semantics.
324///
325/// This is used to map each `LocalDefId` to its content's AST.
326///
327/// This type isn't produced by name resolution but it is paired with `ResolverAstLowering` so this
328/// is as good a place as any for it.
329#[derive(#[automatically_derived]
impl ::core::fmt::Debug for AstOwner {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            AstOwner::NonOwner =>
                ::core::fmt::Formatter::write_str(f, "NonOwner"),
            AstOwner::NestedUseTree(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "NestedUseTree", &__self_0),
            AstOwner::Crate(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Crate",
                    &__self_0),
            AstOwner::Item(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Item",
                    &__self_0),
            AstOwner::TraitItem(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "TraitItem", &__self_0),
            AstOwner::ImplItem(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "ImplItem", &__self_0),
            AstOwner::ForeignItem(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "ForeignItem", &__self_0),
        }
    }
}Debug)]
330pub enum AstOwner {
331    /// This definition does not correspond to a HIR owner.
332    NonOwner,
333    /// This definition corresponds to a nested `use` tree.
334    /// The `LocalDefId` points to its HIR owner.
335    NestedUseTree(LocalDefId),
336    Crate(Box<ast::Crate>),
337    Item(Box<ast::Item>),
338    TraitItem(Box<ast::AssocItem>),
339    ImplItem(Box<ast::AssocItem>),
340    ForeignItem(Box<ast::ForeignItem>),
341}