rustc_hir/
def.rs

1use std::array::IntoIter;
2use std::borrow::Cow;
3use std::fmt::Debug;
4
5use rustc_ast as ast;
6use rustc_ast::NodeId;
7use rustc_data_structures::stable_hasher::ToStableHashKey;
8use rustc_data_structures::unord::UnordMap;
9use rustc_error_messages::{DiagArgValue, IntoDiagArg};
10use rustc_macros::{Decodable, Encodable, HashStable_Generic};
11use rustc_span::Symbol;
12use rustc_span::def_id::{DefId, LocalDefId};
13use rustc_span::hygiene::MacroKind;
14
15use crate::definitions::DefPathData;
16use crate::hir;
17
18/// Encodes if a `DefKind::Ctor` is the constructor of an enum variant or a struct.
19#[derive(#[automatically_derived]
impl ::core::clone::Clone for CtorOf {
    #[inline]
    fn clone(&self) -> CtorOf { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for CtorOf { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for CtorOf {
    #[inline]
    fn eq(&self, other: &CtorOf) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for CtorOf {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) -> () {}
}Eq, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for CtorOf {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        CtorOf::Struct => { 0usize }
                        CtorOf::Variant => { 1usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self { CtorOf::Struct => {} CtorOf::Variant => {} }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for CtorOf {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { CtorOf::Struct }
                    1usize => { CtorOf::Variant }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `CtorOf`, expected 0..2, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable, #[automatically_derived]
impl ::core::hash::Hash for CtorOf {
    #[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)
    }
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for CtorOf {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                CtorOf::Struct => "Struct",
                CtorOf::Variant => "Variant",
            })
    }
}Debug, const _: () =
    {
        impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            for CtorOf where __CTX: crate::HashStableContext {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self { CtorOf::Struct => {} CtorOf::Variant => {} }
            }
        }
    };HashStable_Generic)]
20pub enum CtorOf {
21    /// This `DefKind::Ctor` is a synthesized constructor of a tuple or unit struct.
22    Struct,
23    /// This `DefKind::Ctor` is a synthesized constructor of a tuple or unit variant.
24    Variant,
25}
26
27/// What kind of constructor something is.
28#[derive(#[automatically_derived]
impl ::core::clone::Clone for CtorKind {
    #[inline]
    fn clone(&self) -> CtorKind { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for CtorKind { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for CtorKind {
    #[inline]
    fn eq(&self, other: &CtorKind) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for CtorKind {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) -> () {}
}Eq, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for CtorKind {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        CtorKind::Fn => { 0usize }
                        CtorKind::Const => { 1usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self { CtorKind::Fn => {} CtorKind::Const => {} }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for CtorKind {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { CtorKind::Fn }
                    1usize => { CtorKind::Const }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `CtorKind`, expected 0..2, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable, #[automatically_derived]
impl ::core::hash::Hash for CtorKind {
    #[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)
    }
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for CtorKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self { CtorKind::Fn => "Fn", CtorKind::Const => "Const", })
    }
}Debug, const _: () =
    {
        impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            for CtorKind where __CTX: crate::HashStableContext {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self { CtorKind::Fn => {} CtorKind::Const => {} }
            }
        }
    };HashStable_Generic)]
29pub enum CtorKind {
30    /// Constructor function automatically created by a tuple struct/variant.
31    Fn,
32    /// Constructor constant automatically created by a unit struct/variant.
33    Const,
34}
35
36/// A set of macro kinds, for macros that can have more than one kind
37#[derive(#[automatically_derived]
impl ::core::clone::Clone for MacroKinds {
    #[inline]
    fn clone(&self) -> MacroKinds {
        let _: ::core::clone::AssertParamIsClone<u8>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for MacroKinds { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for MacroKinds {
    #[inline]
    fn eq(&self, other: &MacroKinds) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for MacroKinds {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) -> () {
        let _: ::core::cmp::AssertParamIsEq<u8>;
    }
}Eq, #[automatically_derived]
impl ::core::cmp::PartialOrd for MacroKinds {
    #[inline]
    fn partial_cmp(&self, other: &MacroKinds)
        -> ::core::option::Option<::core::cmp::Ordering> {
        ::core::cmp::PartialOrd::partial_cmp(&self.0, &other.0)
    }
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for MacroKinds {
    #[inline]
    fn cmp(&self, other: &MacroKinds) -> ::core::cmp::Ordering {
        ::core::cmp::Ord::cmp(&self.0, &other.0)
    }
}Ord, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for MacroKinds {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    MacroKinds(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for MacroKinds {
            fn decode(__decoder: &mut __D) -> Self {
                MacroKinds(::rustc_serialize::Decodable::decode(__decoder))
            }
        }
    };Decodable, #[automatically_derived]
impl ::core::hash::Hash for MacroKinds {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
        ::core::hash::Hash::hash(&self.0, state)
    }
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for MacroKinds {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_tuple_field1_finish(f, "MacroKinds",
            &&self.0)
    }
}Debug)]
38#[derive(const _: () =
    {
        impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            for MacroKinds where __CTX: crate::HashStableContext {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    MacroKinds(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_Generic)]
39pub struct MacroKinds(u8);
40impl MacroKinds {
    #[allow(deprecated, non_upper_case_globals,)]
    pub const BANG: Self = Self::from_bits_retain(1 << 0);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const ATTR: Self = Self::from_bits_retain(1 << 1);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const DERIVE: Self = Self::from_bits_retain(1 << 2);
}
impl ::bitflags::Flags for MacroKinds {
    const FLAGS: &'static [::bitflags::Flag<MacroKinds>] =
        &[{

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("BANG", MacroKinds::BANG)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("ATTR", MacroKinds::ATTR)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("DERIVE", MacroKinds::DERIVE)
                    }];
    type Bits = u8;
    fn bits(&self) -> u8 { MacroKinds::bits(self) }
    fn from_bits_retain(bits: u8) -> MacroKinds {
        MacroKinds::from_bits_retain(bits)
    }
}
#[allow(dead_code, deprecated, unused_doc_comments, unused_attributes,
unused_mut, unused_imports, non_upper_case_globals, clippy ::
assign_op_pattern, clippy :: iter_without_into_iter,)]
const _: () =
    {
        #[allow(dead_code, deprecated, unused_attributes)]
        impl MacroKinds {
            /// Get a flags value with all bits unset.
            #[inline]
            pub const fn empty() -> Self {
                Self(<u8 as ::bitflags::Bits>::EMPTY)
            }
            /// Get a flags value with all known bits set.
            #[inline]
            pub const fn all() -> Self {
                let mut truncated = <u8 as ::bitflags::Bits>::EMPTY;
                let mut i = 0;
                {
                    {
                        let flag =
                            <MacroKinds as ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <MacroKinds as ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <MacroKinds as ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                let _ = i;
                Self(truncated)
            }
            /// Get the underlying bits value.
            ///
            /// The returned value is exactly the bits set in this flags value.
            #[inline]
            pub const fn bits(&self) -> u8 { self.0 }
            /// Convert from a bits value.
            ///
            /// This method will return `None` if any unknown bits are set.
            #[inline]
            pub const fn from_bits(bits: u8)
                -> ::bitflags::__private::core::option::Option<Self> {
                let truncated = Self::from_bits_truncate(bits).0;
                if truncated == bits {
                    ::bitflags::__private::core::option::Option::Some(Self(bits))
                } else { ::bitflags::__private::core::option::Option::None }
            }
            /// Convert from a bits value, unsetting any unknown bits.
            #[inline]
            pub const fn from_bits_truncate(bits: u8) -> Self {
                Self(bits & Self::all().0)
            }
            /// Convert from a bits value exactly.
            #[inline]
            pub const fn from_bits_retain(bits: u8) -> Self { Self(bits) }
            /// Get a flags value with the bits of a flag with the given name set.
            ///
            /// This method will return `None` if `name` is empty or doesn't
            /// correspond to any named flag.
            #[inline]
            pub fn from_name(name: &str)
                -> ::bitflags::__private::core::option::Option<Self> {
                {
                    if name == "BANG" {
                        return ::bitflags::__private::core::option::Option::Some(Self(MacroKinds::BANG.bits()));
                    }
                };
                ;
                {
                    if name == "ATTR" {
                        return ::bitflags::__private::core::option::Option::Some(Self(MacroKinds::ATTR.bits()));
                    }
                };
                ;
                {
                    if name == "DERIVE" {
                        return ::bitflags::__private::core::option::Option::Some(Self(MacroKinds::DERIVE.bits()));
                    }
                };
                ;
                let _ = name;
                ::bitflags::__private::core::option::Option::None
            }
            /// Whether all bits in this flags value are unset.
            #[inline]
            pub const fn is_empty(&self) -> bool {
                self.0 == <u8 as ::bitflags::Bits>::EMPTY
            }
            /// Whether all known bits in this flags value are set.
            #[inline]
            pub const fn is_all(&self) -> bool {
                Self::all().0 | self.0 == self.0
            }
            /// Whether any set bits in a source flags value are also set in a target flags value.
            #[inline]
            pub const fn intersects(&self, other: Self) -> bool {
                self.0 & other.0 != <u8 as ::bitflags::Bits>::EMPTY
            }
            /// Whether all set bits in a source flags value are also set in a target flags value.
            #[inline]
            pub const fn contains(&self, other: Self) -> bool {
                self.0 & other.0 == other.0
            }
            /// The bitwise or (`|`) of the bits in two flags values.
            #[inline]
            pub fn insert(&mut self, other: Self) {
                *self = Self(self.0).union(other);
            }
            /// The intersection of a source flags value with the complement of a target flags
            /// value (`&!`).
            ///
            /// This method is not equivalent to `self & !other` when `other` has unknown bits set.
            /// `remove` won't truncate `other`, but the `!` operator will.
            #[inline]
            pub fn remove(&mut self, other: Self) {
                *self = Self(self.0).difference(other);
            }
            /// The bitwise exclusive-or (`^`) of the bits in two flags values.
            #[inline]
            pub fn toggle(&mut self, other: Self) {
                *self = Self(self.0).symmetric_difference(other);
            }
            /// Call `insert` when `value` is `true` or `remove` when `value` is `false`.
            #[inline]
            pub fn set(&mut self, other: Self, value: bool) {
                if value { self.insert(other); } else { self.remove(other); }
            }
            /// The bitwise and (`&`) of the bits in two flags values.
            #[inline]
            #[must_use]
            pub const fn intersection(self, other: Self) -> Self {
                Self(self.0 & other.0)
            }
            /// The bitwise or (`|`) of the bits in two flags values.
            #[inline]
            #[must_use]
            pub const fn union(self, other: Self) -> Self {
                Self(self.0 | other.0)
            }
            /// The intersection of a source flags value with the complement of a target flags
            /// value (`&!`).
            ///
            /// This method is not equivalent to `self & !other` when `other` has unknown bits set.
            /// `difference` won't truncate `other`, but the `!` operator will.
            #[inline]
            #[must_use]
            pub const fn difference(self, other: Self) -> Self {
                Self(self.0 & !other.0)
            }
            /// The bitwise exclusive-or (`^`) of the bits in two flags values.
            #[inline]
            #[must_use]
            pub const fn symmetric_difference(self, other: Self) -> Self {
                Self(self.0 ^ other.0)
            }
            /// The bitwise negation (`!`) of the bits in a flags value, truncating the result.
            #[inline]
            #[must_use]
            pub const fn complement(self) -> Self {
                Self::from_bits_truncate(!self.0)
            }
        }
        impl ::bitflags::__private::core::fmt::Binary for MacroKinds {
            fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
                -> ::bitflags::__private::core::fmt::Result {
                let inner = self.0;
                ::bitflags::__private::core::fmt::Binary::fmt(&inner, f)
            }
        }
        impl ::bitflags::__private::core::fmt::Octal for MacroKinds {
            fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
                -> ::bitflags::__private::core::fmt::Result {
                let inner = self.0;
                ::bitflags::__private::core::fmt::Octal::fmt(&inner, f)
            }
        }
        impl ::bitflags::__private::core::fmt::LowerHex for MacroKinds {
            fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
                -> ::bitflags::__private::core::fmt::Result {
                let inner = self.0;
                ::bitflags::__private::core::fmt::LowerHex::fmt(&inner, f)
            }
        }
        impl ::bitflags::__private::core::fmt::UpperHex for MacroKinds {
            fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
                -> ::bitflags::__private::core::fmt::Result {
                let inner = self.0;
                ::bitflags::__private::core::fmt::UpperHex::fmt(&inner, f)
            }
        }
        impl ::bitflags::__private::core::ops::BitOr for MacroKinds {
            type Output = Self;
            /// The bitwise or (`|`) of the bits in two flags values.
            #[inline]
            fn bitor(self, other: MacroKinds) -> Self { self.union(other) }
        }
        impl ::bitflags::__private::core::ops::BitOrAssign for MacroKinds {
            /// The bitwise or (`|`) of the bits in two flags values.
            #[inline]
            fn bitor_assign(&mut self, other: Self) { self.insert(other); }
        }
        impl ::bitflags::__private::core::ops::BitXor for MacroKinds {
            type Output = Self;
            /// The bitwise exclusive-or (`^`) of the bits in two flags values.
            #[inline]
            fn bitxor(self, other: Self) -> Self {
                self.symmetric_difference(other)
            }
        }
        impl ::bitflags::__private::core::ops::BitXorAssign for MacroKinds {
            /// The bitwise exclusive-or (`^`) of the bits in two flags values.
            #[inline]
            fn bitxor_assign(&mut self, other: Self) { self.toggle(other); }
        }
        impl ::bitflags::__private::core::ops::BitAnd for MacroKinds {
            type Output = Self;
            /// The bitwise and (`&`) of the bits in two flags values.
            #[inline]
            fn bitand(self, other: Self) -> Self { self.intersection(other) }
        }
        impl ::bitflags::__private::core::ops::BitAndAssign for MacroKinds {
            /// The bitwise and (`&`) of the bits in two flags values.
            #[inline]
            fn bitand_assign(&mut self, other: Self) {
                *self =
                    Self::from_bits_retain(self.bits()).intersection(other);
            }
        }
        impl ::bitflags::__private::core::ops::Sub for MacroKinds {
            type Output = Self;
            /// The intersection of a source flags value with the complement of a target flags value (`&!`).
            ///
            /// This method is not equivalent to `self & !other` when `other` has unknown bits set.
            /// `difference` won't truncate `other`, but the `!` operator will.
            #[inline]
            fn sub(self, other: Self) -> Self { self.difference(other) }
        }
        impl ::bitflags::__private::core::ops::SubAssign for MacroKinds {
            /// The intersection of a source flags value with the complement of a target flags value (`&!`).
            ///
            /// This method is not equivalent to `self & !other` when `other` has unknown bits set.
            /// `difference` won't truncate `other`, but the `!` operator will.
            #[inline]
            fn sub_assign(&mut self, other: Self) { self.remove(other); }
        }
        impl ::bitflags::__private::core::ops::Not for MacroKinds {
            type Output = Self;
            /// The bitwise negation (`!`) of the bits in a flags value, truncating the result.
            #[inline]
            fn not(self) -> Self { self.complement() }
        }
        impl ::bitflags::__private::core::iter::Extend<MacroKinds> for
            MacroKinds {
            /// The bitwise or (`|`) of the bits in each flags value.
            fn extend<T: ::bitflags::__private::core::iter::IntoIterator<Item
                = Self>>(&mut self, iterator: T) {
                for item in iterator { self.insert(item) }
            }
        }
        impl ::bitflags::__private::core::iter::FromIterator<MacroKinds> for
            MacroKinds {
            /// The bitwise or (`|`) of the bits in each flags value.
            fn from_iter<T: ::bitflags::__private::core::iter::IntoIterator<Item
                = Self>>(iterator: T) -> Self {
                use ::bitflags::__private::core::iter::Extend;
                let mut result = Self::empty();
                result.extend(iterator);
                result
            }
        }
        impl MacroKinds {
            /// Yield a set of contained flags values.
            ///
            /// Each yielded flags value will correspond to a defined named flag. Any unknown bits
            /// will be yielded together as a final flags value.
            #[inline]
            pub const fn iter(&self) -> ::bitflags::iter::Iter<MacroKinds> {
                ::bitflags::iter::Iter::__private_const_new(<MacroKinds as
                        ::bitflags::Flags>::FLAGS,
                    MacroKinds::from_bits_retain(self.bits()),
                    MacroKinds::from_bits_retain(self.bits()))
            }
            /// Yield a set of contained named flags values.
            ///
            /// This method is like [`iter`](#method.iter), except only yields bits in contained named flags.
            /// Any unknown bits, or bits not corresponding to a contained flag will not be yielded.
            #[inline]
            pub const fn iter_names(&self)
                -> ::bitflags::iter::IterNames<MacroKinds> {
                ::bitflags::iter::IterNames::__private_const_new(<MacroKinds
                        as ::bitflags::Flags>::FLAGS,
                    MacroKinds::from_bits_retain(self.bits()),
                    MacroKinds::from_bits_retain(self.bits()))
            }
        }
        impl ::bitflags::__private::core::iter::IntoIterator for MacroKinds {
            type Item = MacroKinds;
            type IntoIter = ::bitflags::iter::Iter<MacroKinds>;
            fn into_iter(self) -> Self::IntoIter { self.iter() }
        }
    };bitflags::bitflags! {
41    impl MacroKinds: u8 {
42        const BANG = 1 << 0;
43        const ATTR = 1 << 1;
44        const DERIVE = 1 << 2;
45    }
46}
47
48impl From<MacroKind> for MacroKinds {
49    fn from(kind: MacroKind) -> Self {
50        match kind {
51            MacroKind::Bang => Self::BANG,
52            MacroKind::Attr => Self::ATTR,
53            MacroKind::Derive => Self::DERIVE,
54        }
55    }
56}
57
58impl MacroKinds {
59    /// Convert the MacroKinds to a static string.
60    ///
61    /// This hardcodes all the possibilities, in order to return a static string.
62    pub fn descr(self) -> &'static str {
63        match self {
64            // FIXME: change this to "function-like macro" and fix all tests
65            Self::BANG => "macro",
66            Self::ATTR => "attribute macro",
67            Self::DERIVE => "derive macro",
68            _ if self == (Self::ATTR | Self::BANG) => "attribute/function macro",
69            _ if self == (Self::DERIVE | Self::BANG) => "derive/function macro",
70            _ if self == (Self::ATTR | Self::DERIVE) => "attribute/derive macro",
71            _ if self.is_all() => "attribute/derive/function macro",
72            _ if self.is_empty() => "useless macro",
73            _ => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
74        }
75    }
76
77    /// Return an indefinite article (a/an) for use with `descr()`
78    pub fn article(self) -> &'static str {
79        if self.contains(Self::ATTR) { "an" } else { "a" }
80    }
81}
82
83/// An attribute that is not a macro; e.g., `#[inline]` or `#[rustfmt::skip]`.
84#[derive(#[automatically_derived]
impl ::core::clone::Clone for NonMacroAttrKind {
    #[inline]
    fn clone(&self) -> NonMacroAttrKind {
        let _: ::core::clone::AssertParamIsClone<Symbol>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for NonMacroAttrKind { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for NonMacroAttrKind {
    #[inline]
    fn eq(&self, other: &NonMacroAttrKind) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (NonMacroAttrKind::Builtin(__self_0),
                    NonMacroAttrKind::Builtin(__arg1_0)) =>
                    __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for NonMacroAttrKind {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) -> () {
        let _: ::core::cmp::AssertParamIsEq<Symbol>;
    }
}Eq, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for NonMacroAttrKind {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        NonMacroAttrKind::Builtin(ref __binding_0) => { 0usize }
                        NonMacroAttrKind::Tool => { 1usize }
                        NonMacroAttrKind::DeriveHelper => { 2usize }
                        NonMacroAttrKind::DeriveHelperCompat => { 3usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    NonMacroAttrKind::Builtin(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    NonMacroAttrKind::Tool => {}
                    NonMacroAttrKind::DeriveHelper => {}
                    NonMacroAttrKind::DeriveHelperCompat => {}
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for NonMacroAttrKind {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => {
                        NonMacroAttrKind::Builtin(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    1usize => { NonMacroAttrKind::Tool }
                    2usize => { NonMacroAttrKind::DeriveHelper }
                    3usize => { NonMacroAttrKind::DeriveHelperCompat }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `NonMacroAttrKind`, expected 0..4, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable, #[automatically_derived]
impl ::core::hash::Hash for NonMacroAttrKind {
    #[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 {
            NonMacroAttrKind::Builtin(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            _ => {}
        }
    }
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for NonMacroAttrKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            NonMacroAttrKind::Builtin(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "Builtin", &__self_0),
            NonMacroAttrKind::Tool =>
                ::core::fmt::Formatter::write_str(f, "Tool"),
            NonMacroAttrKind::DeriveHelper =>
                ::core::fmt::Formatter::write_str(f, "DeriveHelper"),
            NonMacroAttrKind::DeriveHelperCompat =>
                ::core::fmt::Formatter::write_str(f, "DeriveHelperCompat"),
        }
    }
}Debug, const _: () =
    {
        impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            for NonMacroAttrKind where __CTX: crate::HashStableContext {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    NonMacroAttrKind::Builtin(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    NonMacroAttrKind::Tool => {}
                    NonMacroAttrKind::DeriveHelper => {}
                    NonMacroAttrKind::DeriveHelperCompat => {}
                }
            }
        }
    };HashStable_Generic)]
85pub enum NonMacroAttrKind {
86    /// Single-segment attribute defined by the language (`#[inline]`)
87    Builtin(Symbol),
88    /// Multi-segment custom attribute living in a "tool module" (`#[rustfmt::skip]`).
89    Tool,
90    /// Single-segment custom attribute registered by a derive macro (`#[serde(default)]`).
91    DeriveHelper,
92    /// Single-segment custom attribute registered by a derive macro
93    /// but used before that derive macro was expanded (deprecated).
94    DeriveHelperCompat,
95}
96
97/// What kind of definition something is; e.g., `mod` vs `struct`.
98/// `enum DefPathData` may need to be updated if a new variant is added here.
99#[derive(#[automatically_derived]
impl ::core::clone::Clone for DefKind {
    #[inline]
    fn clone(&self) -> DefKind {
        let _: ::core::clone::AssertParamIsClone<hir::Safety>;
        let _: ::core::clone::AssertParamIsClone<ast::Mutability>;
        let _: ::core::clone::AssertParamIsClone<bool>;
        let _: ::core::clone::AssertParamIsClone<CtorOf>;
        let _: ::core::clone::AssertParamIsClone<CtorKind>;
        let _: ::core::clone::AssertParamIsClone<MacroKinds>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for DefKind { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for DefKind {
    #[inline]
    fn eq(&self, other: &DefKind) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (DefKind::Static {
                    safety: __self_0, mutability: __self_1, nested: __self_2 },
                    DefKind::Static {
                    safety: __arg1_0, mutability: __arg1_1, nested: __arg1_2 })
                    =>
                    __self_2 == __arg1_2 && __self_0 == __arg1_0 &&
                        __self_1 == __arg1_1,
                (DefKind::Ctor(__self_0, __self_1),
                    DefKind::Ctor(__arg1_0, __arg1_1)) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                (DefKind::Macro(__self_0), DefKind::Macro(__arg1_0)) =>
                    __self_0 == __arg1_0,
                (DefKind::Impl { of_trait: __self_0 }, DefKind::Impl {
                    of_trait: __arg1_0 }) => __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for DefKind {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) -> () {
        let _: ::core::cmp::AssertParamIsEq<hir::Safety>;
        let _: ::core::cmp::AssertParamIsEq<ast::Mutability>;
        let _: ::core::cmp::AssertParamIsEq<bool>;
        let _: ::core::cmp::AssertParamIsEq<CtorOf>;
        let _: ::core::cmp::AssertParamIsEq<CtorKind>;
        let _: ::core::cmp::AssertParamIsEq<MacroKinds>;
    }
}Eq, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for DefKind {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        DefKind::Mod => { 0usize }
                        DefKind::Struct => { 1usize }
                        DefKind::Union => { 2usize }
                        DefKind::Enum => { 3usize }
                        DefKind::Variant => { 4usize }
                        DefKind::Trait => { 5usize }
                        DefKind::TyAlias => { 6usize }
                        DefKind::ForeignTy => { 7usize }
                        DefKind::TraitAlias => { 8usize }
                        DefKind::AssocTy => { 9usize }
                        DefKind::TyParam => { 10usize }
                        DefKind::Fn => { 11usize }
                        DefKind::Const => { 12usize }
                        DefKind::ConstParam => { 13usize }
                        DefKind::Static {
                            safety: ref __binding_0,
                            mutability: ref __binding_1,
                            nested: ref __binding_2 } => {
                            14usize
                        }
                        DefKind::Ctor(ref __binding_0, ref __binding_1) => {
                            15usize
                        }
                        DefKind::AssocFn => { 16usize }
                        DefKind::AssocConst => { 17usize }
                        DefKind::Macro(ref __binding_0) => { 18usize }
                        DefKind::ExternCrate => { 19usize }
                        DefKind::Use => { 20usize }
                        DefKind::ForeignMod => { 21usize }
                        DefKind::AnonConst => { 22usize }
                        DefKind::InlineConst => { 23usize }
                        DefKind::OpaqueTy => { 24usize }
                        DefKind::Field => { 25usize }
                        DefKind::LifetimeParam => { 26usize }
                        DefKind::GlobalAsm => { 27usize }
                        DefKind::Impl { of_trait: ref __binding_0 } => { 28usize }
                        DefKind::Closure => { 29usize }
                        DefKind::SyntheticCoroutineBody => { 30usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    DefKind::Mod => {}
                    DefKind::Struct => {}
                    DefKind::Union => {}
                    DefKind::Enum => {}
                    DefKind::Variant => {}
                    DefKind::Trait => {}
                    DefKind::TyAlias => {}
                    DefKind::ForeignTy => {}
                    DefKind::TraitAlias => {}
                    DefKind::AssocTy => {}
                    DefKind::TyParam => {}
                    DefKind::Fn => {}
                    DefKind::Const => {}
                    DefKind::ConstParam => {}
                    DefKind::Static {
                        safety: ref __binding_0,
                        mutability: ref __binding_1,
                        nested: ref __binding_2 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_2,
                            __encoder);
                    }
                    DefKind::Ctor(ref __binding_0, ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    DefKind::AssocFn => {}
                    DefKind::AssocConst => {}
                    DefKind::Macro(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    DefKind::ExternCrate => {}
                    DefKind::Use => {}
                    DefKind::ForeignMod => {}
                    DefKind::AnonConst => {}
                    DefKind::InlineConst => {}
                    DefKind::OpaqueTy => {}
                    DefKind::Field => {}
                    DefKind::LifetimeParam => {}
                    DefKind::GlobalAsm => {}
                    DefKind::Impl { of_trait: ref __binding_0 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    DefKind::Closure => {}
                    DefKind::SyntheticCoroutineBody => {}
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for DefKind {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { DefKind::Mod }
                    1usize => { DefKind::Struct }
                    2usize => { DefKind::Union }
                    3usize => { DefKind::Enum }
                    4usize => { DefKind::Variant }
                    5usize => { DefKind::Trait }
                    6usize => { DefKind::TyAlias }
                    7usize => { DefKind::ForeignTy }
                    8usize => { DefKind::TraitAlias }
                    9usize => { DefKind::AssocTy }
                    10usize => { DefKind::TyParam }
                    11usize => { DefKind::Fn }
                    12usize => { DefKind::Const }
                    13usize => { DefKind::ConstParam }
                    14usize => {
                        DefKind::Static {
                            safety: ::rustc_serialize::Decodable::decode(__decoder),
                            mutability: ::rustc_serialize::Decodable::decode(__decoder),
                            nested: ::rustc_serialize::Decodable::decode(__decoder),
                        }
                    }
                    15usize => {
                        DefKind::Ctor(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    16usize => { DefKind::AssocFn }
                    17usize => { DefKind::AssocConst }
                    18usize => {
                        DefKind::Macro(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    19usize => { DefKind::ExternCrate }
                    20usize => { DefKind::Use }
                    21usize => { DefKind::ForeignMod }
                    22usize => { DefKind::AnonConst }
                    23usize => { DefKind::InlineConst }
                    24usize => { DefKind::OpaqueTy }
                    25usize => { DefKind::Field }
                    26usize => { DefKind::LifetimeParam }
                    27usize => { DefKind::GlobalAsm }
                    28usize => {
                        DefKind::Impl {
                            of_trait: ::rustc_serialize::Decodable::decode(__decoder),
                        }
                    }
                    29usize => { DefKind::Closure }
                    30usize => { DefKind::SyntheticCoroutineBody }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `DefKind`, expected 0..31, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable, #[automatically_derived]
impl ::core::hash::Hash for DefKind {
    #[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 {
            DefKind::Static {
                safety: __self_0, mutability: __self_1, nested: __self_2 } =>
                {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state);
                ::core::hash::Hash::hash(__self_2, state)
            }
            DefKind::Ctor(__self_0, __self_1) => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state)
            }
            DefKind::Macro(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            DefKind::Impl { of_trait: __self_0 } =>
                ::core::hash::Hash::hash(__self_0, state),
            _ => {}
        }
    }
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for DefKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            DefKind::Mod => ::core::fmt::Formatter::write_str(f, "Mod"),
            DefKind::Struct => ::core::fmt::Formatter::write_str(f, "Struct"),
            DefKind::Union => ::core::fmt::Formatter::write_str(f, "Union"),
            DefKind::Enum => ::core::fmt::Formatter::write_str(f, "Enum"),
            DefKind::Variant =>
                ::core::fmt::Formatter::write_str(f, "Variant"),
            DefKind::Trait => ::core::fmt::Formatter::write_str(f, "Trait"),
            DefKind::TyAlias =>
                ::core::fmt::Formatter::write_str(f, "TyAlias"),
            DefKind::ForeignTy =>
                ::core::fmt::Formatter::write_str(f, "ForeignTy"),
            DefKind::TraitAlias =>
                ::core::fmt::Formatter::write_str(f, "TraitAlias"),
            DefKind::AssocTy =>
                ::core::fmt::Formatter::write_str(f, "AssocTy"),
            DefKind::TyParam =>
                ::core::fmt::Formatter::write_str(f, "TyParam"),
            DefKind::Fn => ::core::fmt::Formatter::write_str(f, "Fn"),
            DefKind::Const => ::core::fmt::Formatter::write_str(f, "Const"),
            DefKind::ConstParam =>
                ::core::fmt::Formatter::write_str(f, "ConstParam"),
            DefKind::Static {
                safety: __self_0, mutability: __self_1, nested: __self_2 } =>
                ::core::fmt::Formatter::debug_struct_field3_finish(f,
                    "Static", "safety", __self_0, "mutability", __self_1,
                    "nested", &__self_2),
            DefKind::Ctor(__self_0, __self_1) =>
                ::core::fmt::Formatter::debug_tuple_field2_finish(f, "Ctor",
                    __self_0, &__self_1),
            DefKind::AssocFn =>
                ::core::fmt::Formatter::write_str(f, "AssocFn"),
            DefKind::AssocConst =>
                ::core::fmt::Formatter::write_str(f, "AssocConst"),
            DefKind::Macro(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Macro",
                    &__self_0),
            DefKind::ExternCrate =>
                ::core::fmt::Formatter::write_str(f, "ExternCrate"),
            DefKind::Use => ::core::fmt::Formatter::write_str(f, "Use"),
            DefKind::ForeignMod =>
                ::core::fmt::Formatter::write_str(f, "ForeignMod"),
            DefKind::AnonConst =>
                ::core::fmt::Formatter::write_str(f, "AnonConst"),
            DefKind::InlineConst =>
                ::core::fmt::Formatter::write_str(f, "InlineConst"),
            DefKind::OpaqueTy =>
                ::core::fmt::Formatter::write_str(f, "OpaqueTy"),
            DefKind::Field => ::core::fmt::Formatter::write_str(f, "Field"),
            DefKind::LifetimeParam =>
                ::core::fmt::Formatter::write_str(f, "LifetimeParam"),
            DefKind::GlobalAsm =>
                ::core::fmt::Formatter::write_str(f, "GlobalAsm"),
            DefKind::Impl { of_trait: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f, "Impl",
                    "of_trait", &__self_0),
            DefKind::Closure =>
                ::core::fmt::Formatter::write_str(f, "Closure"),
            DefKind::SyntheticCoroutineBody =>
                ::core::fmt::Formatter::write_str(f,
                    "SyntheticCoroutineBody"),
        }
    }
}Debug, const _: () =
    {
        impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            for DefKind where __CTX: crate::HashStableContext {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    DefKind::Mod => {}
                    DefKind::Struct => {}
                    DefKind::Union => {}
                    DefKind::Enum => {}
                    DefKind::Variant => {}
                    DefKind::Trait => {}
                    DefKind::TyAlias => {}
                    DefKind::ForeignTy => {}
                    DefKind::TraitAlias => {}
                    DefKind::AssocTy => {}
                    DefKind::TyParam => {}
                    DefKind::Fn => {}
                    DefKind::Const => {}
                    DefKind::ConstParam => {}
                    DefKind::Static {
                        safety: ref __binding_0,
                        mutability: ref __binding_1,
                        nested: ref __binding_2 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                        { __binding_2.hash_stable(__hcx, __hasher); }
                    }
                    DefKind::Ctor(ref __binding_0, ref __binding_1) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                    DefKind::AssocFn => {}
                    DefKind::AssocConst => {}
                    DefKind::Macro(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    DefKind::ExternCrate => {}
                    DefKind::Use => {}
                    DefKind::ForeignMod => {}
                    DefKind::AnonConst => {}
                    DefKind::InlineConst => {}
                    DefKind::OpaqueTy => {}
                    DefKind::Field => {}
                    DefKind::LifetimeParam => {}
                    DefKind::GlobalAsm => {}
                    DefKind::Impl { of_trait: ref __binding_0 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    DefKind::Closure => {}
                    DefKind::SyntheticCoroutineBody => {}
                }
            }
        }
    };HashStable_Generic)]
100pub enum DefKind {
101    // Type namespace
102    Mod,
103    /// Refers to the struct itself, [`DefKind::Ctor`] refers to its constructor if it exists.
104    Struct,
105    Union,
106    Enum,
107    /// Refers to the variant itself, [`DefKind::Ctor`] refers to its constructor if it exists.
108    Variant,
109    Trait,
110    /// Type alias: `type Foo = Bar;`
111    TyAlias,
112    /// Type from an `extern` block.
113    ForeignTy,
114    /// Trait alias: `trait IntIterator = Iterator<Item = i32>;`
115    TraitAlias,
116    /// Associated type: `trait MyTrait { type Assoc; }`
117    AssocTy,
118    /// Type parameter: the `T` in `struct Vec<T> { ... }`
119    TyParam,
120
121    // Value namespace
122    Fn,
123    Const,
124    /// Constant generic parameter: `struct Foo<const N: usize> { ... }`
125    ConstParam,
126    Static {
127        /// Whether it's a `unsafe static`, `safe static` (inside extern only) or just a `static`.
128        safety: hir::Safety,
129        /// Whether it's a `static mut` or just a `static`.
130        mutability: ast::Mutability,
131        /// Whether it's an anonymous static generated for nested allocations.
132        nested: bool,
133    },
134    /// Refers to the struct or enum variant's constructor.
135    ///
136    /// The reason `Ctor` exists in addition to [`DefKind::Struct`] and
137    /// [`DefKind::Variant`] is because structs and enum variants exist
138    /// in the *type* namespace, whereas struct and enum variant *constructors*
139    /// exist in the *value* namespace.
140    ///
141    /// You may wonder why enum variants exist in the type namespace as opposed
142    /// to the value namespace. Check out [RFC 2593] for intuition on why that is.
143    ///
144    /// [RFC 2593]: https://github.com/rust-lang/rfcs/pull/2593
145    Ctor(CtorOf, CtorKind),
146    /// Associated function: `impl MyStruct { fn associated() {} }`
147    /// or `trait Foo { fn associated() {} }`
148    AssocFn,
149    /// Associated constant: `trait MyTrait { const ASSOC: usize; }`
150    AssocConst,
151
152    // Macro namespace
153    Macro(MacroKinds),
154
155    // Not namespaced (or they are, but we don't treat them so)
156    ExternCrate,
157    Use,
158    /// An `extern` block.
159    ForeignMod,
160    /// Anonymous constant, e.g. the `1 + 2` in `[u8; 1 + 2]`.
161    ///
162    /// Not all anon-consts are actually still relevant in the HIR. We lower
163    /// trivial const-arguments directly to `hir::ConstArgKind::Path`, at which
164    /// point the definition for the anon-const ends up unused and incomplete.
165    ///
166    /// We do not provide any a `Span` for the definition and pretty much all other
167    /// queries also ICE when using this `DefId`. Given that the `DefId` of such
168    /// constants should only be reachable by iterating all definitions of a
169    /// given crate, you should not have to worry about this.
170    AnonConst,
171    /// An inline constant, e.g. `const { 1 + 2 }`
172    InlineConst,
173    /// Opaque type, aka `impl Trait`.
174    OpaqueTy,
175    /// A field in a struct, enum or union. e.g.
176    /// - `bar` in `struct Foo { bar: u8 }`
177    /// - `Foo::Bar::0` in `enum Foo { Bar(u8) }`
178    Field,
179    /// Lifetime parameter: the `'a` in `struct Foo<'a> { ... }`
180    LifetimeParam,
181    /// A use of `global_asm!`.
182    GlobalAsm,
183    Impl {
184        of_trait: bool,
185    },
186    /// A closure, coroutine, or coroutine-closure.
187    ///
188    /// These are all represented with the same `ExprKind::Closure` in the AST and HIR,
189    /// which makes it difficult to distinguish these during def collection. Therefore,
190    /// we treat them all the same, and code which needs to distinguish them can match
191    /// or `hir::ClosureKind` or `type_of`.
192    Closure,
193    /// The definition of a synthetic coroutine body created by the lowering of a
194    /// coroutine-closure, such as an async closure.
195    SyntheticCoroutineBody,
196}
197
198impl DefKind {
199    /// Get an English description for the item's kind.
200    ///
201    /// If you have access to `TyCtxt`, use `TyCtxt::def_descr` or
202    /// `TyCtxt::def_kind_descr` instead, because they give better
203    /// information for coroutines and associated functions.
204    pub fn descr(self, def_id: DefId) -> &'static str {
205        match self {
206            DefKind::Fn => "function",
207            DefKind::Mod if def_id.is_crate_root() && !def_id.is_local() => "crate",
208            DefKind::Mod => "module",
209            DefKind::Static { .. } => "static",
210            DefKind::Enum => "enum",
211            DefKind::Variant => "variant",
212            DefKind::Ctor(CtorOf::Variant, CtorKind::Fn) => "tuple variant",
213            DefKind::Ctor(CtorOf::Variant, CtorKind::Const) => "unit variant",
214            DefKind::Struct => "struct",
215            DefKind::Ctor(CtorOf::Struct, CtorKind::Fn) => "tuple struct",
216            DefKind::Ctor(CtorOf::Struct, CtorKind::Const) => "unit struct",
217            DefKind::OpaqueTy => "opaque type",
218            DefKind::TyAlias => "type alias",
219            DefKind::TraitAlias => "trait alias",
220            DefKind::AssocTy => "associated type",
221            DefKind::Union => "union",
222            DefKind::Trait => "trait",
223            DefKind::ForeignTy => "foreign type",
224            DefKind::AssocFn => "associated function",
225            DefKind::Const => "constant",
226            DefKind::AssocConst => "associated constant",
227            DefKind::TyParam => "type parameter",
228            DefKind::ConstParam => "const parameter",
229            DefKind::Macro(kinds) => kinds.descr(),
230            DefKind::LifetimeParam => "lifetime parameter",
231            DefKind::Use => "import",
232            DefKind::ForeignMod => "foreign module",
233            DefKind::AnonConst => "constant expression",
234            DefKind::InlineConst => "inline constant",
235            DefKind::Field => "field",
236            DefKind::Impl { .. } => "implementation",
237            DefKind::Closure => "closure",
238            DefKind::ExternCrate => "extern crate",
239            DefKind::GlobalAsm => "global assembly block",
240            DefKind::SyntheticCoroutineBody => "synthetic mir body",
241        }
242    }
243
244    /// Gets an English article for the definition.
245    ///
246    /// If you have access to `TyCtxt`, use `TyCtxt::def_descr_article` or
247    /// `TyCtxt::def_kind_descr_article` instead, because they give better
248    /// information for coroutines and associated functions.
249    pub fn article(&self) -> &'static str {
250        match *self {
251            DefKind::AssocTy
252            | DefKind::AssocConst
253            | DefKind::AssocFn
254            | DefKind::Enum
255            | DefKind::OpaqueTy
256            | DefKind::Impl { .. }
257            | DefKind::Use
258            | DefKind::InlineConst
259            | DefKind::ExternCrate => "an",
260            DefKind::Macro(kinds) => kinds.article(),
261            _ => "a",
262        }
263    }
264
265    pub fn ns(&self) -> Option<Namespace> {
266        match self {
267            DefKind::Mod
268            | DefKind::Struct
269            | DefKind::Union
270            | DefKind::Enum
271            | DefKind::Variant
272            | DefKind::Trait
273            | DefKind::TyAlias
274            | DefKind::ForeignTy
275            | DefKind::TraitAlias
276            | DefKind::AssocTy
277            | DefKind::TyParam => Some(Namespace::TypeNS),
278
279            DefKind::Fn
280            | DefKind::Const
281            | DefKind::ConstParam
282            | DefKind::Static { .. }
283            | DefKind::Ctor(..)
284            | DefKind::AssocFn
285            | DefKind::AssocConst => Some(Namespace::ValueNS),
286
287            DefKind::Macro(..) => Some(Namespace::MacroNS),
288
289            // Not namespaced.
290            DefKind::AnonConst
291            | DefKind::InlineConst
292            | DefKind::Field
293            | DefKind::LifetimeParam
294            | DefKind::ExternCrate
295            | DefKind::Closure
296            | DefKind::Use
297            | DefKind::ForeignMod
298            | DefKind::GlobalAsm
299            | DefKind::Impl { .. }
300            | DefKind::OpaqueTy
301            | DefKind::SyntheticCoroutineBody => None,
302        }
303    }
304
305    // Some `DefKind`s require a name, some don't. Panics if one is needed but
306    // not provided. (`AssocTy` is an exception, see below.)
307    pub fn def_path_data(self, name: Option<Symbol>) -> DefPathData {
308        match self {
309            DefKind::Mod
310            | DefKind::Struct
311            | DefKind::Union
312            | DefKind::Enum
313            | DefKind::Variant
314            | DefKind::Trait
315            | DefKind::TyAlias
316            | DefKind::ForeignTy
317            | DefKind::TraitAlias
318            | DefKind::TyParam
319            | DefKind::ExternCrate => DefPathData::TypeNs(name.unwrap()),
320
321            // An associated type name will be missing for an RPITIT (DefPathData::AnonAssocTy),
322            // but those provide their own DefPathData.
323            DefKind::AssocTy => DefPathData::TypeNs(name.unwrap()),
324
325            DefKind::Fn
326            | DefKind::Const
327            | DefKind::ConstParam
328            | DefKind::Static { .. }
329            | DefKind::AssocFn
330            | DefKind::AssocConst
331            | DefKind::Field => DefPathData::ValueNs(name.unwrap()),
332            DefKind::Macro(..) => DefPathData::MacroNs(name.unwrap()),
333            DefKind::LifetimeParam => DefPathData::LifetimeNs(name.unwrap()),
334            DefKind::Ctor(..) => DefPathData::Ctor,
335            DefKind::Use => DefPathData::Use,
336            DefKind::ForeignMod => DefPathData::ForeignMod,
337            DefKind::AnonConst => DefPathData::AnonConst,
338            DefKind::InlineConst => DefPathData::AnonConst,
339            DefKind::OpaqueTy => DefPathData::OpaqueTy,
340            DefKind::GlobalAsm => DefPathData::GlobalAsm,
341            DefKind::Impl { .. } => DefPathData::Impl,
342            DefKind::Closure => DefPathData::Closure,
343            DefKind::SyntheticCoroutineBody => DefPathData::SyntheticCoroutineBody,
344        }
345    }
346
347    pub fn is_assoc(self) -> bool {
348        #[allow(non_exhaustive_omitted_patterns)] match self {
    DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy => true,
    _ => false,
}matches!(self, DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy)
349    }
350
351    /// This is a "module" in name resolution sense.
352    #[inline]
353    pub fn is_module_like(self) -> bool {
354        #[allow(non_exhaustive_omitted_patterns)] match self {
    DefKind::Mod | DefKind::Enum | DefKind::Trait => true,
    _ => false,
}matches!(self, DefKind::Mod | DefKind::Enum | DefKind::Trait)
355    }
356
357    #[inline]
358    pub fn is_adt(self) -> bool {
359        #[allow(non_exhaustive_omitted_patterns)] match self {
    DefKind::Struct | DefKind::Union | DefKind::Enum => true,
    _ => false,
}matches!(self, DefKind::Struct | DefKind::Union | DefKind::Enum)
360    }
361
362    #[inline]
363    pub fn is_fn_like(self) -> bool {
364        #[allow(non_exhaustive_omitted_patterns)] match self {
    DefKind::Fn | DefKind::AssocFn | DefKind::Closure |
        DefKind::SyntheticCoroutineBody => true,
    _ => false,
}matches!(
365            self,
366            DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::SyntheticCoroutineBody
367        )
368    }
369
370    /// Whether the corresponding item has generic parameters, ie. the `generics_of` query works.
371    pub fn has_generics(self) -> bool {
372        match self {
373            DefKind::AnonConst
374            | DefKind::AssocConst
375            | DefKind::AssocFn
376            | DefKind::AssocTy
377            | DefKind::Closure
378            | DefKind::Const
379            | DefKind::Ctor(..)
380            | DefKind::Enum
381            | DefKind::Field
382            | DefKind::Fn
383            | DefKind::ForeignTy
384            | DefKind::Impl { .. }
385            | DefKind::InlineConst
386            | DefKind::OpaqueTy
387            | DefKind::Static { .. }
388            | DefKind::Struct
389            | DefKind::SyntheticCoroutineBody
390            | DefKind::Trait
391            | DefKind::TraitAlias
392            | DefKind::TyAlias
393            | DefKind::Union
394            | DefKind::Variant => true,
395            DefKind::ConstParam
396            | DefKind::ExternCrate
397            | DefKind::ForeignMod
398            | DefKind::GlobalAsm
399            | DefKind::LifetimeParam
400            | DefKind::Macro(_)
401            | DefKind::Mod
402            | DefKind::TyParam
403            | DefKind::Use => false,
404        }
405    }
406
407    /// Whether `query get_codegen_attrs` should be used with this definition.
408    pub fn has_codegen_attrs(self) -> bool {
409        match self {
410            DefKind::Fn
411            | DefKind::AssocFn
412            | DefKind::Ctor(..)
413            | DefKind::Closure
414            | DefKind::Static { .. }
415            | DefKind::SyntheticCoroutineBody => true,
416            DefKind::Mod
417            | DefKind::Struct
418            | DefKind::Union
419            | DefKind::Enum
420            | DefKind::Variant
421            | DefKind::Trait
422            | DefKind::TyAlias
423            | DefKind::ForeignTy
424            | DefKind::TraitAlias
425            | DefKind::AssocTy
426            | DefKind::Const
427            | DefKind::AssocConst
428            | DefKind::Macro(..)
429            | DefKind::Use
430            | DefKind::ForeignMod
431            | DefKind::OpaqueTy
432            | DefKind::Impl { .. }
433            | DefKind::Field
434            | DefKind::TyParam
435            | DefKind::ConstParam
436            | DefKind::LifetimeParam
437            | DefKind::AnonConst
438            | DefKind::InlineConst
439            | DefKind::GlobalAsm
440            | DefKind::ExternCrate => false,
441        }
442    }
443
444    /// Returns `true` if `self` is a kind of definition that does not have its own
445    /// type-checking context, i.e. closure, coroutine or inline const.
446    #[inline]
447    pub fn is_typeck_child(self) -> bool {
448        match self {
449            DefKind::Closure | DefKind::InlineConst | DefKind::SyntheticCoroutineBody => true,
450            DefKind::Mod
451            | DefKind::Struct
452            | DefKind::Union
453            | DefKind::Enum
454            | DefKind::Variant
455            | DefKind::Trait
456            | DefKind::TyAlias
457            | DefKind::ForeignTy
458            | DefKind::TraitAlias
459            | DefKind::AssocTy
460            | DefKind::TyParam
461            | DefKind::Fn
462            | DefKind::Const
463            | DefKind::ConstParam
464            | DefKind::Static { .. }
465            | DefKind::Ctor(_, _)
466            | DefKind::AssocFn
467            | DefKind::AssocConst
468            | DefKind::Macro(_)
469            | DefKind::ExternCrate
470            | DefKind::Use
471            | DefKind::ForeignMod
472            | DefKind::AnonConst
473            | DefKind::OpaqueTy
474            | DefKind::Field
475            | DefKind::LifetimeParam
476            | DefKind::GlobalAsm
477            | DefKind::Impl { .. } => false,
478        }
479    }
480}
481
482/// The resolution of a path or export.
483///
484/// For every path or identifier in Rust, the compiler must determine
485/// what the path refers to. This process is called name resolution,
486/// and `Res` is the primary result of name resolution.
487///
488/// For example, everything prefixed with `/* Res */` in this example has
489/// an associated `Res`:
490///
491/// ```ignore (illustrative)
492/// fn str_to_string(s: & /* Res */ str) -> /* Res */ String {
493///     /* Res */ String::from(/* Res */ s)
494/// }
495///
496/// /* Res */ str_to_string("hello");
497/// ```
498///
499/// The associated `Res`s will be:
500///
501/// - `str` will resolve to [`Res::PrimTy`];
502/// - `String` will resolve to [`Res::Def`], and the `Res` will include the [`DefId`]
503///   for `String` as defined in the standard library;
504/// - `String::from` will also resolve to [`Res::Def`], with the [`DefId`]
505///   pointing to `String::from`;
506/// - `s` will resolve to [`Res::Local`];
507/// - the call to `str_to_string` will resolve to [`Res::Def`], with the [`DefId`]
508///   pointing to the definition of `str_to_string` in the current crate.
509//
510#[derive(#[automatically_derived]
impl<Id: ::core::clone::Clone> ::core::clone::Clone for Res<Id> {
    #[inline]
    fn clone(&self) -> Res<Id> {
        match self {
            Res::Def(__self_0, __self_1) =>
                Res::Def(::core::clone::Clone::clone(__self_0),
                    ::core::clone::Clone::clone(__self_1)),
            Res::PrimTy(__self_0) =>
                Res::PrimTy(::core::clone::Clone::clone(__self_0)),
            Res::SelfTyParam { trait_: __self_0 } =>
                Res::SelfTyParam {
                    trait_: ::core::clone::Clone::clone(__self_0),
                },
            Res::SelfTyAlias { alias_to: __self_0, is_trait_impl: __self_1 }
                =>
                Res::SelfTyAlias {
                    alias_to: ::core::clone::Clone::clone(__self_0),
                    is_trait_impl: ::core::clone::Clone::clone(__self_1),
                },
            Res::SelfCtor(__self_0) =>
                Res::SelfCtor(::core::clone::Clone::clone(__self_0)),
            Res::Local(__self_0) =>
                Res::Local(::core::clone::Clone::clone(__self_0)),
            Res::ToolMod => Res::ToolMod,
            Res::NonMacroAttr(__self_0) =>
                Res::NonMacroAttr(::core::clone::Clone::clone(__self_0)),
            Res::Err => Res::Err,
        }
    }
}Clone, #[automatically_derived]
impl<Id: ::core::marker::Copy> ::core::marker::Copy for Res<Id> { }Copy, #[automatically_derived]
impl<Id: ::core::cmp::PartialEq> ::core::cmp::PartialEq for Res<Id> {
    #[inline]
    fn eq(&self, other: &Res<Id>) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (Res::Def(__self_0, __self_1), Res::Def(__arg1_0, __arg1_1))
                    => __self_0 == __arg1_0 && __self_1 == __arg1_1,
                (Res::PrimTy(__self_0), Res::PrimTy(__arg1_0)) =>
                    __self_0 == __arg1_0,
                (Res::SelfTyParam { trait_: __self_0 }, Res::SelfTyParam {
                    trait_: __arg1_0 }) => __self_0 == __arg1_0,
                (Res::SelfTyAlias {
                    alias_to: __self_0, is_trait_impl: __self_1 },
                    Res::SelfTyAlias {
                    alias_to: __arg1_0, is_trait_impl: __arg1_1 }) =>
                    __self_1 == __arg1_1 && __self_0 == __arg1_0,
                (Res::SelfCtor(__self_0), Res::SelfCtor(__arg1_0)) =>
                    __self_0 == __arg1_0,
                (Res::Local(__self_0), Res::Local(__arg1_0)) =>
                    __self_0 == __arg1_0,
                (Res::NonMacroAttr(__self_0), Res::NonMacroAttr(__arg1_0)) =>
                    __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl<Id: ::core::cmp::Eq> ::core::cmp::Eq for Res<Id> {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) -> () {
        let _: ::core::cmp::AssertParamIsEq<DefKind>;
        let _: ::core::cmp::AssertParamIsEq<DefId>;
        let _: ::core::cmp::AssertParamIsEq<hir::PrimTy>;
        let _: ::core::cmp::AssertParamIsEq<bool>;
        let _: ::core::cmp::AssertParamIsEq<Id>;
        let _: ::core::cmp::AssertParamIsEq<NonMacroAttrKind>;
    }
}Eq, const _: () =
    {
        impl<Id, __E: ::rustc_span::SpanEncoder>
            ::rustc_serialize::Encodable<__E> for Res<Id> where
            Id: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        Res::Def(ref __binding_0, ref __binding_1) => { 0usize }
                        Res::PrimTy(ref __binding_0) => { 1usize }
                        Res::SelfTyParam { trait_: ref __binding_0 } => { 2usize }
                        Res::SelfTyAlias {
                            alias_to: ref __binding_0, is_trait_impl: ref __binding_1 }
                            => {
                            3usize
                        }
                        Res::SelfCtor(ref __binding_0) => { 4usize }
                        Res::Local(ref __binding_0) => { 5usize }
                        Res::ToolMod => { 6usize }
                        Res::NonMacroAttr(ref __binding_0) => { 7usize }
                        Res::Err => { 8usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    Res::Def(ref __binding_0, ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    Res::PrimTy(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    Res::SelfTyParam { trait_: ref __binding_0 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    Res::SelfTyAlias {
                        alias_to: ref __binding_0, is_trait_impl: ref __binding_1 }
                        => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    Res::SelfCtor(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    Res::Local(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    Res::ToolMod => {}
                    Res::NonMacroAttr(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    Res::Err => {}
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<Id, __D: ::rustc_span::SpanDecoder>
            ::rustc_serialize::Decodable<__D> for Res<Id> where
            Id: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => {
                        Res::Def(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    1usize => {
                        Res::PrimTy(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    2usize => {
                        Res::SelfTyParam {
                            trait_: ::rustc_serialize::Decodable::decode(__decoder),
                        }
                    }
                    3usize => {
                        Res::SelfTyAlias {
                            alias_to: ::rustc_serialize::Decodable::decode(__decoder),
                            is_trait_impl: ::rustc_serialize::Decodable::decode(__decoder),
                        }
                    }
                    4usize => {
                        Res::SelfCtor(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    5usize => {
                        Res::Local(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    6usize => { Res::ToolMod }
                    7usize => {
                        Res::NonMacroAttr(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    8usize => { Res::Err }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `Res`, expected 0..9, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable, #[automatically_derived]
impl<Id: ::core::hash::Hash> ::core::hash::Hash for Res<Id> {
    #[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 {
            Res::Def(__self_0, __self_1) => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state)
            }
            Res::PrimTy(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            Res::SelfTyParam { trait_: __self_0 } =>
                ::core::hash::Hash::hash(__self_0, state),
            Res::SelfTyAlias { alias_to: __self_0, is_trait_impl: __self_1 }
                => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state)
            }
            Res::SelfCtor(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            Res::Local(__self_0) => ::core::hash::Hash::hash(__self_0, state),
            Res::NonMacroAttr(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            _ => {}
        }
    }
}Hash, #[automatically_derived]
impl<Id: ::core::fmt::Debug> ::core::fmt::Debug for Res<Id> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Res::Def(__self_0, __self_1) =>
                ::core::fmt::Formatter::debug_tuple_field2_finish(f, "Def",
                    __self_0, &__self_1),
            Res::PrimTy(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "PrimTy",
                    &__self_0),
            Res::SelfTyParam { trait_: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "SelfTyParam", "trait_", &__self_0),
            Res::SelfTyAlias { alias_to: __self_0, is_trait_impl: __self_1 }
                =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f,
                    "SelfTyAlias", "alias_to", __self_0, "is_trait_impl",
                    &__self_1),
            Res::SelfCtor(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "SelfCtor", &__self_0),
            Res::Local(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Local",
                    &__self_0),
            Res::ToolMod => ::core::fmt::Formatter::write_str(f, "ToolMod"),
            Res::NonMacroAttr(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "NonMacroAttr", &__self_0),
            Res::Err => ::core::fmt::Formatter::write_str(f, "Err"),
        }
    }
}Debug, const _: () =
    {
        impl<Id, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            Res<Id> where __CTX: crate::HashStableContext,
            Id: ::rustc_data_structures::stable_hasher::HashStable<__CTX> {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    Res::Def(ref __binding_0, ref __binding_1) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                    Res::PrimTy(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    Res::SelfTyParam { trait_: ref __binding_0 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    Res::SelfTyAlias {
                        alias_to: ref __binding_0, is_trait_impl: ref __binding_1 }
                        => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                    Res::SelfCtor(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    Res::Local(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    Res::ToolMod => {}
                    Res::NonMacroAttr(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    Res::Err => {}
                }
            }
        }
    };HashStable_Generic)]
511pub enum Res<Id = hir::HirId> {
512    /// Definition having a unique ID (`DefId`), corresponds to something defined in user code.
513    ///
514    /// **Not bound to a specific namespace.**
515    Def(DefKind, DefId),
516
517    // Type namespace
518    /// A primitive type such as `i32` or `str`.
519    ///
520    /// **Belongs to the type namespace.**
521    PrimTy(hir::PrimTy),
522
523    /// The `Self` type, as used within a trait.
524    ///
525    /// **Belongs to the type namespace.**
526    ///
527    /// See the examples on [`Res::SelfTyAlias`] for details.
528    SelfTyParam {
529        /// The trait this `Self` is a generic parameter for.
530        trait_: DefId,
531    },
532
533    /// The `Self` type, as used somewhere other than within a trait.
534    ///
535    /// **Belongs to the type namespace.**
536    ///
537    /// Examples:
538    /// ```
539    /// struct Bar(Box<Self>); // SelfTyAlias
540    ///
541    /// trait Foo {
542    ///     fn foo() -> Box<Self>; // SelfTyParam
543    /// }
544    ///
545    /// impl Bar {
546    ///     fn blah() {
547    ///         let _: Self; // SelfTyAlias
548    ///     }
549    /// }
550    ///
551    /// impl Foo for Bar {
552    ///     fn foo() -> Box<Self /* SelfTyAlias */> {
553    ///         let _: Self;        // SelfTyAlias
554    ///
555    ///         todo!()
556    ///     }
557    /// }
558    /// ```
559    /// *See also [`Res::SelfCtor`].*
560    ///
561    SelfTyAlias {
562        /// The item introducing the `Self` type alias. Can be used in the `type_of` query
563        /// to get the underlying type.
564        alias_to: DefId,
565
566        /// Is this within an `impl Foo for bar`?
567        is_trait_impl: bool,
568    },
569
570    // Value namespace
571    /// The `Self` constructor, along with the [`DefId`]
572    /// of the impl it is associated with.
573    ///
574    /// **Belongs to the value namespace.**
575    ///
576    /// *See also [`Res::SelfTyParam`] and [`Res::SelfTyAlias`].*
577    SelfCtor(DefId),
578
579    /// A local variable or function parameter.
580    ///
581    /// **Belongs to the value namespace.**
582    Local(Id),
583
584    /// A tool attribute module; e.g., the `rustfmt` in `#[rustfmt::skip]`.
585    ///
586    /// **Belongs to the type namespace.**
587    ToolMod,
588
589    // Macro namespace
590    /// An attribute that is *not* implemented via macro.
591    /// E.g., `#[inline]` and `#[rustfmt::skip]`, which are essentially directives,
592    /// as opposed to `#[test]`, which is a builtin macro.
593    ///
594    /// **Belongs to the macro namespace.**
595    NonMacroAttr(NonMacroAttrKind), // e.g., `#[inline]` or `#[rustfmt::skip]`
596
597    // All namespaces
598    /// Name resolution failed. We use a dummy `Res` variant so later phases
599    /// of the compiler won't crash and can instead report more errors.
600    ///
601    /// **Not bound to a specific namespace.**
602    Err,
603}
604
605impl<Id> IntoDiagArg for Res<Id> {
606    fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
607        DiagArgValue::Str(Cow::Borrowed(self.descr()))
608    }
609}
610
611/// The result of resolving a path before lowering to HIR,
612/// with "module" segments resolved and associated item
613/// segments deferred to type checking.
614/// `base_res` is the resolution of the resolved part of the
615/// path, `unresolved_segments` is the number of unresolved
616/// segments.
617///
618/// ```text
619/// module::Type::AssocX::AssocY::MethodOrAssocType
620/// ^~~~~~~~~~~~  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
621/// base_res      unresolved_segments = 3
622///
623/// <T as Trait>::AssocX::AssocY::MethodOrAssocType
624///       ^~~~~~~~~~~~~~  ^~~~~~~~~~~~~~~~~~~~~~~~~
625///       base_res        unresolved_segments = 2
626/// ```
627#[derive(#[automatically_derived]
impl ::core::marker::Copy for PartialRes { }Copy, #[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)]
628pub struct PartialRes {
629    base_res: Res<NodeId>,
630    unresolved_segments: usize,
631}
632
633impl PartialRes {
634    #[inline]
635    pub fn new(base_res: Res<NodeId>) -> Self {
636        PartialRes { base_res, unresolved_segments: 0 }
637    }
638
639    #[inline]
640    pub fn with_unresolved_segments(base_res: Res<NodeId>, mut unresolved_segments: usize) -> Self {
641        if base_res == Res::Err {
642            unresolved_segments = 0
643        }
644        PartialRes { base_res, unresolved_segments }
645    }
646
647    #[inline]
648    pub fn base_res(&self) -> Res<NodeId> {
649        self.base_res
650    }
651
652    #[inline]
653    pub fn unresolved_segments(&self) -> usize {
654        self.unresolved_segments
655    }
656
657    #[inline]
658    pub fn full_res(&self) -> Option<Res<NodeId>> {
659        (self.unresolved_segments == 0).then_some(self.base_res)
660    }
661
662    #[inline]
663    pub fn expect_full_res(&self) -> Res<NodeId> {
664        self.full_res().expect("unexpected unresolved segments")
665    }
666}
667
668/// Different kinds of symbols can coexist even if they share the same textual name.
669/// Therefore, they each have a separate universe (known as a "namespace").
670#[derive(#[automatically_derived]
impl ::core::marker::Copy for Namespace { }Copy, #[automatically_derived]
impl ::core::clone::Clone for Namespace {
    #[inline]
    fn clone(&self) -> Namespace { *self }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for Namespace {
    #[inline]
    fn eq(&self, other: &Namespace) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Namespace {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) -> () {}
}Eq, #[automatically_derived]
impl ::core::cmp::PartialOrd for Namespace {
    #[inline]
    fn partial_cmp(&self, other: &Namespace)
        -> ::core::option::Option<::core::cmp::Ordering> {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        ::core::cmp::PartialOrd::partial_cmp(&__self_discr, &__arg1_discr)
    }
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for Namespace {
    #[inline]
    fn cmp(&self, other: &Namespace) -> ::core::cmp::Ordering {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        ::core::cmp::Ord::cmp(&__self_discr, &__arg1_discr)
    }
}Ord, #[automatically_derived]
impl ::core::hash::Hash for Namespace {
    #[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)
    }
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for Namespace {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                Namespace::TypeNS => "TypeNS",
                Namespace::ValueNS => "ValueNS",
                Namespace::MacroNS => "MacroNS",
            })
    }
}Debug, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for Namespace {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        Namespace::TypeNS => { 0usize }
                        Namespace::ValueNS => { 1usize }
                        Namespace::MacroNS => { 2usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    Namespace::TypeNS => {}
                    Namespace::ValueNS => {}
                    Namespace::MacroNS => {}
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for Namespace {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { Namespace::TypeNS }
                    1usize => { Namespace::ValueNS }
                    2usize => { Namespace::MacroNS }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `Namespace`, expected 0..3, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable)]
671#[derive(const _: () =
    {
        impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            for Namespace where __CTX: crate::HashStableContext {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    Namespace::TypeNS => {}
                    Namespace::ValueNS => {}
                    Namespace::MacroNS => {}
                }
            }
        }
    };HashStable_Generic)]
672pub enum Namespace {
673    /// The type namespace includes `struct`s, `enum`s, `union`s, `trait`s, and `mod`s
674    /// (and, by extension, crates).
675    ///
676    /// Note that the type namespace includes other items; this is not an
677    /// exhaustive list.
678    TypeNS,
679    /// The value namespace includes `fn`s, `const`s, `static`s, and local variables (including function arguments).
680    ValueNS,
681    /// The macro namespace includes `macro_rules!` macros, declarative `macro`s,
682    /// procedural macros, attribute macros, `derive` macros, and non-macro attributes
683    /// like `#[inline]` and `#[rustfmt::skip]`.
684    MacroNS,
685}
686
687impl Namespace {
688    /// The English description of the namespace.
689    pub fn descr(self) -> &'static str {
690        match self {
691            Self::TypeNS => "type",
692            Self::ValueNS => "value",
693            Self::MacroNS => "macro",
694        }
695    }
696}
697
698impl IntoDiagArg for Namespace {
699    fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
700        DiagArgValue::Str(Cow::Borrowed(self.descr()))
701    }
702}
703
704impl<CTX: crate::HashStableContext> ToStableHashKey<CTX> for Namespace {
705    type KeyType = Namespace;
706
707    #[inline]
708    fn to_stable_hash_key(&self, _: &CTX) -> Namespace {
709        *self
710    }
711}
712
713/// Just a helper ‒ separate structure for each namespace.
714#[derive(#[automatically_derived]
impl<T: ::core::marker::Copy> ::core::marker::Copy for PerNS<T> { }Copy, #[automatically_derived]
impl<T: ::core::clone::Clone> ::core::clone::Clone for PerNS<T> {
    #[inline]
    fn clone(&self) -> PerNS<T> {
        PerNS {
            value_ns: ::core::clone::Clone::clone(&self.value_ns),
            type_ns: ::core::clone::Clone::clone(&self.type_ns),
            macro_ns: ::core::clone::Clone::clone(&self.macro_ns),
        }
    }
}Clone, #[automatically_derived]
impl<T: ::core::default::Default> ::core::default::Default for PerNS<T> {
    #[inline]
    fn default() -> PerNS<T> {
        PerNS {
            value_ns: ::core::default::Default::default(),
            type_ns: ::core::default::Default::default(),
            macro_ns: ::core::default::Default::default(),
        }
    }
}Default, #[automatically_derived]
impl<T: ::core::fmt::Debug> ::core::fmt::Debug for PerNS<T> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field3_finish(f, "PerNS",
            "value_ns", &self.value_ns, "type_ns", &self.type_ns, "macro_ns",
            &&self.macro_ns)
    }
}Debug, const _: () =
    {
        impl<T, __CTX>
            ::rustc_data_structures::stable_hasher::HashStable<__CTX> for
            PerNS<T> where __CTX: crate::HashStableContext,
            T: ::rustc_data_structures::stable_hasher::HashStable<__CTX> {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    PerNS {
                        value_ns: ref __binding_0,
                        type_ns: ref __binding_1,
                        macro_ns: ref __binding_2 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                        { __binding_2.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_Generic)]
715pub struct PerNS<T> {
716    pub value_ns: T,
717    pub type_ns: T,
718    pub macro_ns: T,
719}
720
721impl<T> PerNS<T> {
722    pub fn map<U, F: FnMut(T) -> U>(self, mut f: F) -> PerNS<U> {
723        PerNS { value_ns: f(self.value_ns), type_ns: f(self.type_ns), macro_ns: f(self.macro_ns) }
724    }
725
726    /// Note: Do you really want to use this? Often you know which namespace a
727    /// name will belong in, and you can consider just that namespace directly,
728    /// rather than iterating through all of them.
729    pub fn into_iter(self) -> IntoIter<T, 3> {
730        [self.value_ns, self.type_ns, self.macro_ns].into_iter()
731    }
732
733    /// Note: Do you really want to use this? Often you know which namespace a
734    /// name will belong in, and you can consider just that namespace directly,
735    /// rather than iterating through all of them.
736    pub fn iter(&self) -> IntoIter<&T, 3> {
737        [&self.value_ns, &self.type_ns, &self.macro_ns].into_iter()
738    }
739}
740
741impl<T> ::std::ops::Index<Namespace> for PerNS<T> {
742    type Output = T;
743
744    fn index(&self, ns: Namespace) -> &T {
745        match ns {
746            Namespace::ValueNS => &self.value_ns,
747            Namespace::TypeNS => &self.type_ns,
748            Namespace::MacroNS => &self.macro_ns,
749        }
750    }
751}
752
753impl<T> ::std::ops::IndexMut<Namespace> for PerNS<T> {
754    fn index_mut(&mut self, ns: Namespace) -> &mut T {
755        match ns {
756            Namespace::ValueNS => &mut self.value_ns,
757            Namespace::TypeNS => &mut self.type_ns,
758            Namespace::MacroNS => &mut self.macro_ns,
759        }
760    }
761}
762
763impl<T> PerNS<Option<T>> {
764    /// Returns `true` if all the items in this collection are `None`.
765    pub fn is_empty(&self) -> bool {
766        self.type_ns.is_none() && self.value_ns.is_none() && self.macro_ns.is_none()
767    }
768
769    /// Returns an iterator over the items which are `Some`.
770    ///
771    /// Note: Do you really want to use this? Often you know which namespace a
772    /// name will belong in, and you can consider just that namespace directly,
773    /// rather than iterating through all of them.
774    pub fn present_items(self) -> impl Iterator<Item = T> {
775        [self.type_ns, self.value_ns, self.macro_ns].into_iter().flatten()
776    }
777}
778
779impl CtorKind {
780    pub fn from_ast(vdata: &ast::VariantData) -> Option<(CtorKind, NodeId)> {
781        match *vdata {
782            ast::VariantData::Tuple(_, node_id) => Some((CtorKind::Fn, node_id)),
783            ast::VariantData::Unit(node_id) => Some((CtorKind::Const, node_id)),
784            ast::VariantData::Struct { .. } => None,
785        }
786    }
787}
788
789impl NonMacroAttrKind {
790    pub fn descr(self) -> &'static str {
791        match self {
792            NonMacroAttrKind::Builtin(..) => "built-in attribute",
793            NonMacroAttrKind::Tool => "tool attribute",
794            NonMacroAttrKind::DeriveHelper | NonMacroAttrKind::DeriveHelperCompat => {
795                "derive helper attribute"
796            }
797        }
798    }
799
800    // Currently trivial, but exists in case a new kind is added in the future whose name starts
801    // with a vowel.
802    pub fn article(self) -> &'static str {
803        "a"
804    }
805
806    /// Users of some attributes cannot mark them as used, so they are considered always used.
807    pub fn is_used(self) -> bool {
808        match self {
809            NonMacroAttrKind::Tool
810            | NonMacroAttrKind::DeriveHelper
811            | NonMacroAttrKind::DeriveHelperCompat => true,
812            NonMacroAttrKind::Builtin(..) => false,
813        }
814    }
815}
816
817impl<Id> Res<Id> {
818    /// Return the `DefId` of this `Def` if it has an ID, else panic.
819    pub fn def_id(&self) -> DefId
820    where
821        Id: Debug,
822    {
823        self.opt_def_id().unwrap_or_else(|| {
    ::core::panicking::panic_fmt(format_args!("attempted .def_id() on invalid res: {0:?}",
            self));
}panic!("attempted .def_id() on invalid res: {self:?}"))
824    }
825
826    /// Return `Some(..)` with the `DefId` of this `Res` if it has a ID, else `None`.
827    pub fn opt_def_id(&self) -> Option<DefId> {
828        match *self {
829            Res::Def(_, id) => Some(id),
830
831            Res::Local(..)
832            | Res::PrimTy(..)
833            | Res::SelfTyParam { .. }
834            | Res::SelfTyAlias { .. }
835            | Res::SelfCtor(..)
836            | Res::ToolMod
837            | Res::NonMacroAttr(..)
838            | Res::Err => None,
839        }
840    }
841
842    /// Return the `DefId` of this `Res` if it represents a module.
843    pub fn mod_def_id(&self) -> Option<DefId> {
844        match *self {
845            Res::Def(DefKind::Mod, id) => Some(id),
846            _ => None,
847        }
848    }
849
850    /// If this is a "module" in name resolution sense, return its `DefId`.
851    #[inline]
852    pub fn module_like_def_id(&self) -> Option<DefId> {
853        match self {
854            Res::Def(def_kind, def_id) if def_kind.is_module_like() => Some(*def_id),
855            _ => None,
856        }
857    }
858
859    /// A human readable name for the res kind ("function", "module", etc.).
860    pub fn descr(&self) -> &'static str {
861        match *self {
862            Res::Def(kind, def_id) => kind.descr(def_id),
863            Res::SelfCtor(..) => "self constructor",
864            Res::PrimTy(..) => "builtin type",
865            Res::Local(..) => "local variable",
866            Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } => "self type",
867            Res::ToolMod => "tool module",
868            Res::NonMacroAttr(attr_kind) => attr_kind.descr(),
869            Res::Err => "unresolved item",
870        }
871    }
872
873    /// Gets an English article for the `Res`.
874    pub fn article(&self) -> &'static str {
875        match *self {
876            Res::Def(kind, _) => kind.article(),
877            Res::NonMacroAttr(kind) => kind.article(),
878            Res::Err => "an",
879            _ => "a",
880        }
881    }
882
883    pub fn map_id<R>(self, mut map: impl FnMut(Id) -> R) -> Res<R> {
884        match self {
885            Res::Def(kind, id) => Res::Def(kind, id),
886            Res::SelfCtor(id) => Res::SelfCtor(id),
887            Res::PrimTy(id) => Res::PrimTy(id),
888            Res::Local(id) => Res::Local(map(id)),
889            Res::SelfTyParam { trait_ } => Res::SelfTyParam { trait_ },
890            Res::SelfTyAlias { alias_to, is_trait_impl } => {
891                Res::SelfTyAlias { alias_to, is_trait_impl }
892            }
893            Res::ToolMod => Res::ToolMod,
894            Res::NonMacroAttr(attr_kind) => Res::NonMacroAttr(attr_kind),
895            Res::Err => Res::Err,
896        }
897    }
898
899    pub fn apply_id<R, E>(self, mut map: impl FnMut(Id) -> Result<R, E>) -> Result<Res<R>, E> {
900        Ok(match self {
901            Res::Def(kind, id) => Res::Def(kind, id),
902            Res::SelfCtor(id) => Res::SelfCtor(id),
903            Res::PrimTy(id) => Res::PrimTy(id),
904            Res::Local(id) => Res::Local(map(id)?),
905            Res::SelfTyParam { trait_ } => Res::SelfTyParam { trait_ },
906            Res::SelfTyAlias { alias_to, is_trait_impl } => {
907                Res::SelfTyAlias { alias_to, is_trait_impl }
908            }
909            Res::ToolMod => Res::ToolMod,
910            Res::NonMacroAttr(attr_kind) => Res::NonMacroAttr(attr_kind),
911            Res::Err => Res::Err,
912        })
913    }
914
915    #[track_caller]
916    pub fn expect_non_local<OtherId>(self) -> Res<OtherId> {
917        self.map_id(
918            #[track_caller]
919            |_| { ::core::panicking::panic_fmt(format_args!("unexpected `Res::Local`")); }panic!("unexpected `Res::Local`"),
920        )
921    }
922
923    pub fn macro_kinds(self) -> Option<MacroKinds> {
924        match self {
925            Res::Def(DefKind::Macro(kinds), _) => Some(kinds),
926            Res::NonMacroAttr(..) => Some(MacroKinds::ATTR),
927            _ => None,
928        }
929    }
930
931    /// Returns `None` if this is `Res::Err`
932    pub fn ns(&self) -> Option<Namespace> {
933        match self {
934            Res::Def(kind, ..) => kind.ns(),
935            Res::PrimTy(..) | Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } | Res::ToolMod => {
936                Some(Namespace::TypeNS)
937            }
938            Res::SelfCtor(..) | Res::Local(..) => Some(Namespace::ValueNS),
939            Res::NonMacroAttr(..) => Some(Namespace::MacroNS),
940            Res::Err => None,
941        }
942    }
943
944    /// Always returns `true` if `self` is `Res::Err`
945    pub fn matches_ns(&self, ns: Namespace) -> bool {
946        self.ns().is_none_or(|actual_ns| actual_ns == ns)
947    }
948
949    /// Returns whether such a resolved path can occur in a tuple struct/variant pattern
950    pub fn expected_in_tuple_struct_pat(&self) -> bool {
951        #[allow(non_exhaustive_omitted_patterns)] match self {
    Res::Def(DefKind::Ctor(_, CtorKind::Fn), _) | Res::SelfCtor(..) => true,
    _ => false,
}matches!(self, Res::Def(DefKind::Ctor(_, CtorKind::Fn), _) | Res::SelfCtor(..))
952    }
953
954    /// Returns whether such a resolved path can occur in a unit struct/variant pattern
955    pub fn expected_in_unit_struct_pat(&self) -> bool {
956        #[allow(non_exhaustive_omitted_patterns)] match self {
    Res::Def(DefKind::Ctor(_, CtorKind::Const), _) | Res::SelfCtor(..) =>
        true,
    _ => false,
}matches!(self, Res::Def(DefKind::Ctor(_, CtorKind::Const), _) | Res::SelfCtor(..))
957    }
958}
959
960/// Resolution for a lifetime appearing in a type.
961#[derive(#[automatically_derived]
impl ::core::marker::Copy for LifetimeRes { }Copy, #[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<hir::MissingLifetimeKind>;
        *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, binder: __self_1, kind: __self_2 } =>
                ::core::fmt::Formatter::debug_struct_field3_finish(f, "Fresh",
                    "param", __self_0, "binder", __self_1, "kind", &__self_2),
            LifetimeRes::Infer =>
                ::core::fmt::Formatter::write_str(f, "Infer"),
            LifetimeRes::Static =>
                ::core::fmt::Formatter::write_str(f, "Static"),
            LifetimeRes::Error =>
                ::core::fmt::Formatter::write_str(f, "Error"),
            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::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, binder: __self_1, kind: __self_2 },
                    LifetimeRes::Fresh {
                    param: __arg1_0, binder: __arg1_1, kind: __arg1_2 }) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1 &&
                        __self_2 == __arg1_2,
                (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_receiver_is_total_eq(&self) -> () {
        let _: ::core::cmp::AssertParamIsEq<LocalDefId>;
        let _: ::core::cmp::AssertParamIsEq<NodeId>;
        let _: ::core::cmp::AssertParamIsEq<hir::MissingLifetimeKind>;
    }
}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, binder: __self_1, kind: __self_2 } => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state);
                ::core::hash::Hash::hash(__self_2, state)
            }
            LifetimeRes::ElidedAnchor { start: __self_0, end: __self_1 } => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state)
            }
            _ => {}
        }
    }
}Hash)]
962pub enum LifetimeRes {
963    /// Successfully linked the lifetime to a generic parameter.
964    Param {
965        /// Id of the generic parameter that introduced it.
966        param: LocalDefId,
967        /// Id of the introducing place. That can be:
968        /// - an item's id, for the item's generic parameters;
969        /// - a TraitRef's ref_id, identifying the `for<...>` binder;
970        /// - a FnPtr type's id.
971        ///
972        /// This information is used for impl-trait lifetime captures, to know when to or not to
973        /// capture any given lifetime.
974        binder: NodeId,
975    },
976    /// Created a generic parameter for an anonymous lifetime.
977    Fresh {
978        /// Id of the generic parameter that introduced it.
979        ///
980        /// Creating the associated `LocalDefId` is the responsibility of lowering.
981        param: NodeId,
982        /// Id of the introducing place. See `Param`.
983        binder: NodeId,
984        /// Kind of elided lifetime
985        kind: hir::MissingLifetimeKind,
986    },
987    /// This variant is used for anonymous lifetimes that we did not resolve during
988    /// late resolution. Those lifetimes will be inferred by typechecking.
989    Infer,
990    /// `'static` lifetime.
991    Static,
992    /// Resolution failure.
993    Error,
994    /// HACK: This is used to recover the NodeId of an elided lifetime.
995    ElidedAnchor { start: NodeId, end: NodeId },
996}
997
998pub type DocLinkResMap = UnordMap<(Symbol, Namespace), Option<Res<NodeId>>>;