Skip to main content

rustc_ast_ir/
lib.rs

1//! Common utilities shared by both `rustc_ast` and `rustc_type_ir`.
2//!
3//! Don't depend on this crate directly; both of those crates should re-export
4//! the functionality. Additionally, if you're in scope of `rustc_middle`, then
5//! prefer imports via that too, to avoid needing to directly depend on (e.g.)
6//! `rustc_type_ir` for a single import.
7
8// tidy-alphabetical-start
9#![cfg_attr(feature = "nightly", allow(internal_features))]
10#![cfg_attr(feature = "nightly", feature(never_type))]
11#![cfg_attr(feature = "nightly", feature(rustc_attrs))]
12// tidy-alphabetical-end
13
14use std::fmt;
15
16#[cfg(feature = "nightly")]
17use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable};
18#[cfg(feature = "nightly")]
19use rustc_span::{Symbol, sym};
20
21pub mod visit;
22
23#[derive(#[automatically_derived]
impl ::core::clone::Clone for IntTy {
    #[inline]
    fn clone(&self) -> IntTy { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for IntTy { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for IntTy {
    #[inline]
    fn eq(&self, other: &IntTy) -> 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 IntTy {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::cmp::PartialOrd for IntTy {
    #[inline]
    fn partial_cmp(&self, other: &IntTy)
        -> ::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 IntTy {
    #[inline]
    fn cmp(&self, other: &IntTy) -> ::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 IntTy {
    #[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)]
24#[cfg_attr(feature = "nightly", derive(const _: () =
    {
        impl<__E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for IntTy {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        IntTy::Isize => { 0usize }
                        IntTy::I8 => { 1usize }
                        IntTy::I16 => { 2usize }
                        IntTy::I32 => { 3usize }
                        IntTy::I64 => { 4usize }
                        IntTy::I128 => { 5usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    IntTy::Isize => {}
                    IntTy::I8 => {}
                    IntTy::I16 => {}
                    IntTy::I32 => {}
                    IntTy::I64 => {}
                    IntTy::I128 => {}
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<__D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for IntTy {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { IntTy::Isize }
                    1usize => { IntTy::I8 }
                    2usize => { IntTy::I16 }
                    3usize => { IntTy::I32 }
                    4usize => { IntTy::I64 }
                    5usize => { IntTy::I128 }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `IntTy`, expected 0..6, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl ::rustc_data_structures::stable_hasher::HashStable for IntTy {
            #[inline]
            fn hash_stable<__Hcx: ::rustc_data_structures::stable_hasher::HashStableContext>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    IntTy::Isize => {}
                    IntTy::I8 => {}
                    IntTy::I16 => {}
                    IntTy::I32 => {}
                    IntTy::I64 => {}
                    IntTy::I128 => {}
                }
            }
        }
    };HashStable))]
25pub enum IntTy {
26    Isize,
27    I8,
28    I16,
29    I32,
30    I64,
31    I128,
32}
33
34impl IntTy {
35    pub fn name_str(&self) -> &'static str {
36        match *self {
37            IntTy::Isize => "isize",
38            IntTy::I8 => "i8",
39            IntTy::I16 => "i16",
40            IntTy::I32 => "i32",
41            IntTy::I64 => "i64",
42            IntTy::I128 => "i128",
43        }
44    }
45
46    #[cfg(feature = "nightly")]
47    pub fn name(self) -> Symbol {
48        match self {
49            IntTy::Isize => sym::isize,
50            IntTy::I8 => sym::i8,
51            IntTy::I16 => sym::i16,
52            IntTy::I32 => sym::i32,
53            IntTy::I64 => sym::i64,
54            IntTy::I128 => sym::i128,
55        }
56    }
57
58    pub fn bit_width(&self) -> Option<u64> {
59        Some(match *self {
60            IntTy::Isize => return None,
61            IntTy::I8 => 8,
62            IntTy::I16 => 16,
63            IntTy::I32 => 32,
64            IntTy::I64 => 64,
65            IntTy::I128 => 128,
66        })
67    }
68
69    pub fn normalize(&self, target_width: u16) -> Self {
70        match self {
71            IntTy::Isize => match target_width {
72                16 => IntTy::I16,
73                32 => IntTy::I32,
74                64 => IntTy::I64,
75                _ => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
76            },
77            _ => *self,
78        }
79    }
80
81    pub fn to_unsigned(self) -> UintTy {
82        match self {
83            IntTy::Isize => UintTy::Usize,
84            IntTy::I8 => UintTy::U8,
85            IntTy::I16 => UintTy::U16,
86            IntTy::I32 => UintTy::U32,
87            IntTy::I64 => UintTy::U64,
88            IntTy::I128 => UintTy::U128,
89        }
90    }
91}
92
93impl fmt::Debug for IntTy {
94    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
95        f.write_fmt(format_args!("{0}", self.name_str()))write!(f, "{}", self.name_str())
96    }
97}
98
99#[derive(#[automatically_derived]
impl ::core::clone::Clone for UintTy {
    #[inline]
    fn clone(&self) -> UintTy { *self }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for UintTy {
    #[inline]
    fn eq(&self, other: &UintTy) -> 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 UintTy {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::cmp::PartialOrd for UintTy {
    #[inline]
    fn partial_cmp(&self, other: &UintTy)
        -> ::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 UintTy {
    #[inline]
    fn cmp(&self, other: &UintTy) -> ::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 UintTy {
    #[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::marker::Copy for UintTy { }Copy)]
100#[cfg_attr(feature = "nightly", derive(const _: () =
    {
        impl<__E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for UintTy {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        UintTy::Usize => { 0usize }
                        UintTy::U8 => { 1usize }
                        UintTy::U16 => { 2usize }
                        UintTy::U32 => { 3usize }
                        UintTy::U64 => { 4usize }
                        UintTy::U128 => { 5usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    UintTy::Usize => {}
                    UintTy::U8 => {}
                    UintTy::U16 => {}
                    UintTy::U32 => {}
                    UintTy::U64 => {}
                    UintTy::U128 => {}
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<__D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for UintTy {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { UintTy::Usize }
                    1usize => { UintTy::U8 }
                    2usize => { UintTy::U16 }
                    3usize => { UintTy::U32 }
                    4usize => { UintTy::U64 }
                    5usize => { UintTy::U128 }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `UintTy`, expected 0..6, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl ::rustc_data_structures::stable_hasher::HashStable for UintTy {
            #[inline]
            fn hash_stable<__Hcx: ::rustc_data_structures::stable_hasher::HashStableContext>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    UintTy::Usize => {}
                    UintTy::U8 => {}
                    UintTy::U16 => {}
                    UintTy::U32 => {}
                    UintTy::U64 => {}
                    UintTy::U128 => {}
                }
            }
        }
    };HashStable))]
101pub enum UintTy {
102    Usize,
103    U8,
104    U16,
105    U32,
106    U64,
107    U128,
108}
109
110impl UintTy {
111    pub fn name_str(&self) -> &'static str {
112        match *self {
113            UintTy::Usize => "usize",
114            UintTy::U8 => "u8",
115            UintTy::U16 => "u16",
116            UintTy::U32 => "u32",
117            UintTy::U64 => "u64",
118            UintTy::U128 => "u128",
119        }
120    }
121
122    #[cfg(feature = "nightly")]
123    pub fn name(self) -> Symbol {
124        match self {
125            UintTy::Usize => sym::usize,
126            UintTy::U8 => sym::u8,
127            UintTy::U16 => sym::u16,
128            UintTy::U32 => sym::u32,
129            UintTy::U64 => sym::u64,
130            UintTy::U128 => sym::u128,
131        }
132    }
133
134    pub fn bit_width(&self) -> Option<u64> {
135        Some(match *self {
136            UintTy::Usize => return None,
137            UintTy::U8 => 8,
138            UintTy::U16 => 16,
139            UintTy::U32 => 32,
140            UintTy::U64 => 64,
141            UintTy::U128 => 128,
142        })
143    }
144
145    pub fn normalize(&self, target_width: u16) -> Self {
146        match self {
147            UintTy::Usize => match target_width {
148                16 => UintTy::U16,
149                32 => UintTy::U32,
150                64 => UintTy::U64,
151                _ => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
152            },
153            _ => *self,
154        }
155    }
156
157    pub fn to_signed(self) -> IntTy {
158        match self {
159            UintTy::Usize => IntTy::Isize,
160            UintTy::U8 => IntTy::I8,
161            UintTy::U16 => IntTy::I16,
162            UintTy::U32 => IntTy::I32,
163            UintTy::U64 => IntTy::I64,
164            UintTy::U128 => IntTy::I128,
165        }
166    }
167}
168
169impl fmt::Debug for UintTy {
170    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
171        f.write_fmt(format_args!("{0}", self.name_str()))write!(f, "{}", self.name_str())
172    }
173}
174
175#[derive(#[automatically_derived]
impl ::core::clone::Clone for FloatTy {
    #[inline]
    fn clone(&self) -> FloatTy { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for FloatTy { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for FloatTy {
    #[inline]
    fn eq(&self, other: &FloatTy) -> 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 FloatTy {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::cmp::PartialOrd for FloatTy {
    #[inline]
    fn partial_cmp(&self, other: &FloatTy)
        -> ::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 FloatTy {
    #[inline]
    fn cmp(&self, other: &FloatTy) -> ::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 FloatTy {
    #[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)]
176#[cfg_attr(feature = "nightly", derive(const _: () =
    {
        impl<__E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for FloatTy {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        FloatTy::F16 => { 0usize }
                        FloatTy::F32 => { 1usize }
                        FloatTy::F64 => { 2usize }
                        FloatTy::F128 => { 3usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    FloatTy::F16 => {}
                    FloatTy::F32 => {}
                    FloatTy::F64 => {}
                    FloatTy::F128 => {}
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<__D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for FloatTy {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { FloatTy::F16 }
                    1usize => { FloatTy::F32 }
                    2usize => { FloatTy::F64 }
                    3usize => { FloatTy::F128 }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `FloatTy`, expected 0..4, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl ::rustc_data_structures::stable_hasher::HashStable for FloatTy {
            #[inline]
            fn hash_stable<__Hcx: ::rustc_data_structures::stable_hasher::HashStableContext>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    FloatTy::F16 => {}
                    FloatTy::F32 => {}
                    FloatTy::F64 => {}
                    FloatTy::F128 => {}
                }
            }
        }
    };HashStable))]
177pub enum FloatTy {
178    F16,
179    F32,
180    F64,
181    F128,
182}
183
184impl FloatTy {
185    pub fn name_str(self) -> &'static str {
186        match self {
187            FloatTy::F16 => "f16",
188            FloatTy::F32 => "f32",
189            FloatTy::F64 => "f64",
190            FloatTy::F128 => "f128",
191        }
192    }
193
194    #[cfg(feature = "nightly")]
195    pub fn name(self) -> Symbol {
196        match self {
197            FloatTy::F16 => sym::f16,
198            FloatTy::F32 => sym::f32,
199            FloatTy::F64 => sym::f64,
200            FloatTy::F128 => sym::f128,
201        }
202    }
203
204    pub fn bit_width(self) -> u64 {
205        match self {
206            FloatTy::F16 => 16,
207            FloatTy::F32 => 32,
208            FloatTy::F64 => 64,
209            FloatTy::F128 => 128,
210        }
211    }
212}
213
214impl fmt::Debug for FloatTy {
215    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
216        f.write_fmt(format_args!("{0}", self.name_str()))write!(f, "{}", self.name_str())
217    }
218}
219
220/// The movability of a coroutine / closure literal:
221/// whether a coroutine contains self-references, causing it to be `!Unpin`.
222#[derive(#[automatically_derived]
impl ::core::clone::Clone for Movability {
    #[inline]
    fn clone(&self) -> Movability { *self }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for Movability {
    #[inline]
    fn eq(&self, other: &Movability) -> 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 Movability {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::cmp::PartialOrd for Movability {
    #[inline]
    fn partial_cmp(&self, other: &Movability)
        -> ::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 Movability {
    #[inline]
    fn cmp(&self, other: &Movability) -> ::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 Movability {
    #[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 Movability {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                Movability::Static => "Static",
                Movability::Movable => "Movable",
            })
    }
}Debug, #[automatically_derived]
impl ::core::marker::Copy for Movability { }Copy)]
223#[cfg_attr(feature = "nightly", derive(const _: () =
    {
        impl<__E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for Movability {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        Movability::Static => { 0usize }
                        Movability::Movable => { 1usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    Movability::Static => {}
                    Movability::Movable => {}
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<__D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for Movability {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { Movability::Static }
                    1usize => { Movability::Movable }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `Movability`, expected 0..2, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl ::rustc_data_structures::stable_hasher::HashStable for Movability
            {
            #[inline]
            fn hash_stable<__Hcx: ::rustc_data_structures::stable_hasher::HashStableContext>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    Movability::Static => {}
                    Movability::Movable => {}
                }
            }
        }
    };HashStable))]
224pub enum Movability {
225    /// May contain self-references, `!Unpin`.
226    Static,
227    /// Must not contain self-references, `Unpin`.
228    Movable,
229}
230
231#[derive(#[automatically_derived]
impl ::core::clone::Clone for Mutability {
    #[inline]
    fn clone(&self) -> Mutability { *self }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for Mutability {
    #[inline]
    fn eq(&self, other: &Mutability) -> 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 Mutability {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::cmp::PartialOrd for Mutability {
    #[inline]
    fn partial_cmp(&self, other: &Mutability)
        -> ::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 Mutability {
    #[inline]
    fn cmp(&self, other: &Mutability) -> ::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 Mutability {
    #[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 Mutability {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                Mutability::Not => "Not",
                Mutability::Mut => "Mut",
            })
    }
}Debug, #[automatically_derived]
impl ::core::marker::Copy for Mutability { }Copy)]
232#[cfg_attr(feature = "nightly", derive(const _: () =
    {
        impl<__E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for Mutability {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        Mutability::Not => { 0usize }
                        Mutability::Mut => { 1usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self { Mutability::Not => {} Mutability::Mut => {} }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<__D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for Mutability {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { Mutability::Not }
                    1usize => { Mutability::Mut }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `Mutability`, expected 0..2, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl ::rustc_data_structures::stable_hasher::HashStable for Mutability
            {
            #[inline]
            fn hash_stable<__Hcx: ::rustc_data_structures::stable_hasher::HashStableContext>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self { Mutability::Not => {} Mutability::Mut => {} }
            }
        }
    };HashStable))]
233pub enum Mutability {
234    // N.B. Order is deliberate, so that Not < Mut
235    Not,
236    Mut,
237}
238
239impl Mutability {
240    pub fn invert(self) -> Self {
241        match self {
242            Mutability::Mut => Mutability::Not,
243            Mutability::Not => Mutability::Mut,
244        }
245    }
246
247    /// Returns `""` (empty string) or `"mut "` depending on the mutability.
248    pub fn prefix_str(self) -> &'static str {
249        match self {
250            Mutability::Mut => "mut ",
251            Mutability::Not => "",
252        }
253    }
254
255    /// Returns `"&"` or `"&mut "` depending on the mutability.
256    pub fn ref_prefix_str(self) -> &'static str {
257        match self {
258            Mutability::Not => "&",
259            Mutability::Mut => "&mut ",
260        }
261    }
262
263    /// Returns `"const"` or `"mut"` depending on the mutability.
264    pub fn ptr_str(self) -> &'static str {
265        match self {
266            Mutability::Not => "const",
267            Mutability::Mut => "mut",
268        }
269    }
270
271    /// Returns `""` (empty string) or `"mutably "` depending on the mutability.
272    pub fn mutably_str(self) -> &'static str {
273        match self {
274            Mutability::Not => "",
275            Mutability::Mut => "mutably ",
276        }
277    }
278
279    /// Return `true` if self is mutable
280    pub fn is_mut(self) -> bool {
281        #[allow(non_exhaustive_omitted_patterns)] match self {
    Self::Mut => true,
    _ => false,
}matches!(self, Self::Mut)
282    }
283
284    /// Return `true` if self is **not** mutable
285    pub fn is_not(self) -> bool {
286        #[allow(non_exhaustive_omitted_patterns)] match self {
    Self::Not => true,
    _ => false,
}matches!(self, Self::Not)
287    }
288}
289
290#[derive(#[automatically_derived]
impl ::core::clone::Clone for Pinnedness {
    #[inline]
    fn clone(&self) -> Pinnedness { *self }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for Pinnedness {
    #[inline]
    fn eq(&self, other: &Pinnedness) -> 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 Pinnedness {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::cmp::PartialOrd for Pinnedness {
    #[inline]
    fn partial_cmp(&self, other: &Pinnedness)
        -> ::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 Pinnedness {
    #[inline]
    fn cmp(&self, other: &Pinnedness) -> ::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 Pinnedness {
    #[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 Pinnedness {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                Pinnedness::Not => "Not",
                Pinnedness::Pinned => "Pinned",
            })
    }
}Debug, #[automatically_derived]
impl ::core::marker::Copy for Pinnedness { }Copy)]
291#[cfg_attr(feature = "nightly", derive(const _: () =
    {
        impl<__E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for Pinnedness {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        Pinnedness::Not => { 0usize }
                        Pinnedness::Pinned => { 1usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self { Pinnedness::Not => {} Pinnedness::Pinned => {} }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<__D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for Pinnedness {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { Pinnedness::Not }
                    1usize => { Pinnedness::Pinned }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `Pinnedness`, expected 0..2, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable_NoContext, const _: () =
    {
        impl ::rustc_data_structures::stable_hasher::HashStable for Pinnedness
            {
            #[inline]
            fn hash_stable<__Hcx: ::rustc_data_structures::stable_hasher::HashStableContext>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self { Pinnedness::Not => {} Pinnedness::Pinned => {} }
            }
        }
    };HashStable))]
292pub enum Pinnedness {
293    Not,
294    Pinned,
295}
296
297impl Pinnedness {
298    /// Return `true` if self is pinned
299    pub fn is_pinned(self) -> bool {
300        #[allow(non_exhaustive_omitted_patterns)] match self {
    Self::Pinned => true,
    _ => false,
}matches!(self, Self::Pinned)
301    }
302
303    /// Returns `""` (empty string), "mut", `"pin mut "` or `"pin const "` depending
304    /// on the pinnedness and mutability.
305    pub fn prefix_str(self, mutbl: Mutability) -> &'static str {
306        match (self, mutbl) {
307            (Pinnedness::Pinned, Mutability::Mut) => "pin mut ",
308            (Pinnedness::Pinned, Mutability::Not) => "pin const ",
309            (Pinnedness::Not, Mutability::Mut) => "mut ",
310            (Pinnedness::Not, Mutability::Not) => "",
311        }
312    }
313}