rustc_middle/
metadata.rs

1use rustc_hir::def::Res;
2use rustc_macros::{HashStable, TyDecodable, TyEncodable};
3use rustc_span::Ident;
4use rustc_span::def_id::DefId;
5use smallvec::SmallVec;
6
7use crate::ty;
8
9/// A simplified version of `ImportKind` from resolve.
10/// `DefId`s here correspond to `use` and `extern crate` items themselves, not their targets.
11#[derive(#[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<'__ctx>
            ::rustc_data_structures::stable_hasher::HashStable<::rustc_query_system::ich::StableHashingContext<'__ctx>>
            for Reexport {
            #[inline]
            fn hash_stable(&self,
                __hcx:
                    &mut ::rustc_query_system::ich::StableHashingContext<'__ctx>,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    Reexport::Single(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    Reexport::Glob(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    Reexport::ExternCrate(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    Reexport::MacroUse => {}
                    Reexport::MacroExport => {}
                }
            }
        }
    };HashStable)]
12pub enum Reexport {
13    Single(DefId),
14    Glob(DefId),
15    ExternCrate(DefId),
16    MacroUse,
17    MacroExport,
18}
19
20impl Reexport {
21    pub fn id(self) -> Option<DefId> {
22        match self {
23            Reexport::Single(id) | Reexport::Glob(id) | Reexport::ExternCrate(id) => Some(id),
24            Reexport::MacroUse | Reexport::MacroExport => None,
25        }
26    }
27}
28
29/// This structure is supposed to keep enough data to re-create `Decl`s for other crates
30/// during name resolution. Right now the bindings are not recreated entirely precisely so we may
31/// need to add more data in the future to correctly support macros 2.0, for example.
32/// Module child can be either a proper item or a reexport (including private imports).
33/// In case of reexport all the fields describe the reexport item itself, not what it refers to.
34#[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) {
                match *self {
                    ModChild {
                        ident: ref __binding_0,
                        res: ref __binding_1,
                        vis: ref __binding_2,
                        reexport_chain: ref __binding_3 } => {
                        ::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<'__ctx>
            ::rustc_data_structures::stable_hasher::HashStable<::rustc_query_system::ich::StableHashingContext<'__ctx>>
            for ModChild {
            #[inline]
            fn hash_stable(&self,
                __hcx:
                    &mut ::rustc_query_system::ich::StableHashingContext<'__ctx>,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    ModChild {
                        ident: ref __binding_0,
                        res: ref __binding_1,
                        vis: ref __binding_2,
                        reexport_chain: ref __binding_3 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                        { __binding_2.hash_stable(__hcx, __hasher); }
                        { __binding_3.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable)]
35pub struct ModChild {
36    /// Name of the item.
37    pub ident: Ident,
38    /// Resolution result corresponding to the item.
39    /// Local variables cannot be exported, so this `Res` doesn't need the ID parameter.
40    pub res: Res<!>,
41    /// Visibility of the item.
42    pub vis: ty::Visibility<DefId>,
43    /// Reexport chain linking this module child to its original reexported item.
44    /// Empty if the module child is a proper item.
45    pub reexport_chain: SmallVec<[Reexport; 2]>,
46}
47
48/// Same as `ModChild`, however, it includes ambiguity error.
49#[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) {
                match *self {
                    AmbigModChild {
                        main: ref __binding_0, second: ref __binding_1 } => {
                        ::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<'__ctx>
            ::rustc_data_structures::stable_hasher::HashStable<::rustc_query_system::ich::StableHashingContext<'__ctx>>
            for AmbigModChild {
            #[inline]
            fn hash_stable(&self,
                __hcx:
                    &mut ::rustc_query_system::ich::StableHashingContext<'__ctx>,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    AmbigModChild {
                        main: ref __binding_0, second: ref __binding_1 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable)]
50pub struct AmbigModChild {
51    pub main: ModChild,
52    pub second: ModChild,
53}