Skip to main content

rustc_middle/ty/
generics.rs

1use std::ops::ControlFlow;
2
3use rustc_ast as ast;
4use rustc_data_structures::fx::FxHashMap;
5use rustc_hir::def_id::DefId;
6use rustc_macros::{StableHash, TyDecodable, TyEncodable};
7use rustc_span::{Span, Symbol, bug, kw};
8use rustc_type_ir::{TypeSuperVisitable as _, TypeVisitable, TypeVisitor};
9use tracing::instrument;
10
11use super::{Clause, InstantiatedClauses, ParamConst, ParamTy, Ty, TyCtxt, Unnormalized};
12use crate::ty::{self, ClauseKind, EarlyBinder, GenericArgs, Region, RegionKind, TyKind};
13
14#[derive(#[automatically_derived]impl ::core::clone::Clone for GenericParamDefKind {
    #[inline]
    fn clone(&self) -> Self {
        match self {
            Self::Lifetime => GenericParamDefKind::Lifetime,
            Self::Type { has_default: __self_0, synthetic: __self_1 } =>
                GenericParamDefKind::Type {
                    has_default: ::core::clone::Clone::clone(__self_0),
                    synthetic: ::core::clone::Clone::clone(__self_1),
                },
            Self::Const { has_default: __self_0, arg_pos: __self_1 } =>
                GenericParamDefKind::Const {
                    has_default: ::core::clone::Clone::clone(__self_0),
                    arg_pos: ::core::clone::Clone::clone(__self_1),
                },
        }
    }
}Clone, #[automatically_derived]impl ::core::fmt::Debug for GenericParamDefKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Self::Lifetime =>
                ::core::fmt::Formatter::write_str(f, "Lifetime"),
            Self::Type { has_default: __self_0, synthetic: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f,
                    "Type has_default synthetic", __self_0, &__self_1),
            Self::Const { has_default: __self_0, arg_pos: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f,
                    "Const has_default arg_pos", __self_0, &__self_1),
        }
    }
}Debug, const _: () =
    {
        impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
            ::rustc_serialize::Encodable<__E> for GenericParamDefKind {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        GenericParamDefKind::Lifetime => { 0usize }
                        GenericParamDefKind::Type {
                            has_default: ref __binding_0, synthetic: ref __binding_1 }
                            => {
                            1usize
                        }
                        GenericParamDefKind::Const {
                            has_default: ref __binding_0, arg_pos: ref __binding_1 } =>
                            {
                            2usize
                        }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    GenericParamDefKind::Lifetime => {}
                    GenericParamDefKind::Type {
                        has_default: ref __binding_0, synthetic: ref __binding_1 }
                        => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    GenericParamDefKind::Const {
                        has_default: ref __binding_0, arg_pos: ref __binding_1 } =>
                        {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                }
            }
        }
    };TyEncodable, const _: () =
    {
        impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
            ::rustc_serialize::Decodable<__D> for GenericParamDefKind {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { GenericParamDefKind::Lifetime }
                    1usize => {
                        GenericParamDefKind::Type {
                            has_default: ::rustc_serialize::Decodable::decode(__decoder),
                            synthetic: ::rustc_serialize::Decodable::decode(__decoder),
                        }
                    }
                    2usize => {
                        GenericParamDefKind::Const {
                            has_default: ::rustc_serialize::Decodable::decode(__decoder),
                            arg_pos: ::rustc_serialize::Decodable::decode(__decoder),
                        }
                    }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `GenericParamDefKind`, expected 0..3, actual {0}",
                                n));
                    }
                }
            }
        }
    };TyDecodable, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for
            GenericParamDefKind {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    GenericParamDefKind::Lifetime =>
                        0u8.stable_hash(__hcx, __hasher),
                    GenericParamDefKind::Type {
                        has_default: ref __binding_0, synthetic: ref __binding_1 }
                        => 1u8.stable_hash(__hcx, __hasher),
                    GenericParamDefKind::Const {
                        has_default: ref __binding_0, arg_pos: ref __binding_1 } =>
                        2u8.stable_hash(__hcx, __hasher),
                }
                match *self {
                    GenericParamDefKind::Lifetime => {}
                    GenericParamDefKind::Type {
                        has_default: ref __binding_0, synthetic: ref __binding_1 }
                        => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                    GenericParamDefKind::Const {
                        has_default: ref __binding_0, arg_pos: ref __binding_1 } =>
                        {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash)]
15pub enum GenericParamDefKind {
16    Lifetime,
17    Type {
18        has_default: bool,
19        synthetic: bool,
20    },
21    Const {
22        has_default: bool,
23        /// Used by `function_arg_const_generics` to track the position of
24        /// a const parameter in the function's argument list (including `self`).
25        /// `Some(i)` means the argument at index `i` supplies this const parameter,
26        /// while `None` indicates a regular const generic parameter.
27        arg_pos: Option<u16>,
28    },
29}
30
31impl GenericParamDefKind {
32    pub fn descr(&self) -> &'static str {
33        match self {
34            GenericParamDefKind::Lifetime => "lifetime",
35            GenericParamDefKind::Type { .. } => "type",
36            GenericParamDefKind::Const { .. } => "constant",
37        }
38    }
39    pub fn to_ord(&self) -> ast::ParamKindOrd {
40        match self {
41            GenericParamDefKind::Lifetime => ast::ParamKindOrd::Lifetime,
42            GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => {
43                ast::ParamKindOrd::TypeOrConst
44            }
45        }
46    }
47
48    pub fn is_ty_or_const(&self) -> bool {
49        match self {
50            GenericParamDefKind::Lifetime => false,
51            GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => true,
52        }
53    }
54
55    pub fn is_synthetic(&self) -> bool {
56        match self {
57            GenericParamDefKind::Type { synthetic, .. } => *synthetic,
58            _ => false,
59        }
60    }
61
62    /// Returns the position of a function argument const generic.
63    pub fn arg_pos(&self) -> Option<u16> {
64        match self {
65            GenericParamDefKind::Const { arg_pos, .. } => *arg_pos,
66            _ => None,
67        }
68    }
69}
70
71#[derive(#[automatically_derived]impl ::core::clone::Clone for GenericParamDef {
    #[inline]
    fn clone(&self) -> Self {
        GenericParamDef {
            name: ::core::clone::Clone::clone(&self.name),
            def_id: ::core::clone::Clone::clone(&self.def_id),
            index: ::core::clone::Clone::clone(&self.index),
            pure_wrt_drop: ::core::clone::Clone::clone(&self.pure_wrt_drop),
            kind: ::core::clone::Clone::clone(&self.kind),
        }
    }
}Clone, #[automatically_derived]impl ::core::fmt::Debug for GenericParamDef {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field5_finish(f,
            "GenericParamDef name def_id index pure_wrt_drop kind",
            &self.name, &self.def_id, &self.index, &self.pure_wrt_drop,
            &&self.kind)
    }
}Debug, const _: () =
    {
        impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
            ::rustc_serialize::Encodable<__E> for GenericParamDef {
            fn encode(&self, __encoder: &mut __E) {
                let GenericParamDef {
                        name: ref __binding_0,
                        def_id: ref __binding_1,
                        index: ref __binding_2,
                        pure_wrt_drop: ref __binding_3,
                        kind: ref __binding_4 } = *self;
                ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                    __encoder);
                ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                    __encoder);
                ::rustc_serialize::Encodable::<__E>::encode(__binding_2,
                    __encoder);
                ::rustc_serialize::Encodable::<__E>::encode(__binding_3,
                    __encoder);
                ::rustc_serialize::Encodable::<__E>::encode(__binding_4,
                    __encoder);
            }
        }
    };TyEncodable, const _: () =
    {
        impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
            ::rustc_serialize::Decodable<__D> for GenericParamDef {
            fn decode(__decoder: &mut __D) -> Self {
                GenericParamDef {
                    name: ::rustc_serialize::Decodable::decode(__decoder),
                    def_id: ::rustc_serialize::Decodable::decode(__decoder),
                    index: ::rustc_serialize::Decodable::decode(__decoder),
                    pure_wrt_drop: ::rustc_serialize::Decodable::decode(__decoder),
                    kind: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };TyDecodable, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for
            GenericParamDef {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    GenericParamDef {
                        name: ref __binding_0,
                        def_id: ref __binding_1,
                        index: ref __binding_2,
                        pure_wrt_drop: ref __binding_3,
                        kind: ref __binding_4 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                        { __binding_2.stable_hash(__hcx, __hasher); }
                        { __binding_3.stable_hash(__hcx, __hasher); }
                        { __binding_4.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash)]
72pub struct GenericParamDef {
73    pub name: Symbol,
74    pub def_id: DefId,
75    pub index: u32,
76
77    /// `pure_wrt_drop`, set by the (unsafe) `#[may_dangle]` attribute
78    /// on generic parameter `'a`/`T`, asserts data behind the parameter
79    /// `'a`/`T` won't be accessed during the parent type's `Drop` impl.
80    pub pure_wrt_drop: bool,
81
82    pub kind: GenericParamDefKind,
83}
84
85impl GenericParamDef {
86    pub fn to_early_bound_region_data(&self) -> ty::EarlyParamRegion {
87        if let GenericParamDefKind::Lifetime = self.kind {
88            ty::EarlyParamRegion { index: self.index, name: self.name }
89        } else {
90            ::rustc_span::macros::bug_impl(None,
    format_args!("cannot convert a non-lifetime parameter def to an early bound region"),
    Location::caller())bug!("cannot convert a non-lifetime parameter def to an early bound region")
91        }
92    }
93
94    pub fn is_anonymous_lifetime(&self) -> bool {
95        match self.kind {
96            GenericParamDefKind::Lifetime => self.name == kw::UnderscoreLifetime,
97            _ => false,
98        }
99    }
100
101    pub fn default_value<'tcx>(
102        &self,
103        tcx: TyCtxt<'tcx>,
104    ) -> Option<EarlyBinder<'tcx, ty::GenericArg<'tcx>>> {
105        match self.kind {
106            GenericParamDefKind::Type { has_default: true, .. } => {
107                Some(tcx.type_of(self.def_id).map_bound(|t| t.into()))
108            }
109            GenericParamDefKind::Const { has_default: true, .. } => {
110                Some(tcx.const_param_default(self.def_id).map_bound(|c| c.into()))
111            }
112            _ => None,
113        }
114    }
115
116    pub fn to_error<'tcx>(&self, tcx: TyCtxt<'tcx>) -> ty::GenericArg<'tcx> {
117        match &self.kind {
118            ty::GenericParamDefKind::Lifetime => ty::Region::new_error_misc(tcx).into(),
119            ty::GenericParamDefKind::Type { .. } => Ty::new_misc_error(tcx).into(),
120            ty::GenericParamDefKind::Const { .. } => ty::Const::new_misc_error(tcx).into(),
121        }
122    }
123}
124
125#[derive(#[automatically_derived]impl ::core::default::Default for GenericParamCount {
    #[inline]
    fn default() -> Self {
        GenericParamCount {
            lifetimes: ::core::default::Default::default(),
            types: ::core::default::Default::default(),
            consts: ::core::default::Default::default(),
        }
    }
}Default)]
126pub struct GenericParamCount {
127    pub lifetimes: usize,
128    pub types: usize,
129    pub consts: usize,
130}
131
132/// Information about the formal type/lifetime parameters associated
133/// with an item or method. Analogous to `hir::Generics`.
134///
135/// The ordering of parameters is the same as in [`ty::GenericArg`] (excluding child generics):
136/// `Self` (optionally), `Lifetime` params..., `Type` params...
137#[derive(#[automatically_derived]impl ::core::clone::Clone for Generics {
    #[inline]
    fn clone(&self) -> Self {
        Generics {
            parent: ::core::clone::Clone::clone(&self.parent),
            parent_count: ::core::clone::Clone::clone(&self.parent_count),
            own_params: ::core::clone::Clone::clone(&self.own_params),
            param_def_id_to_index: ::core::clone::Clone::clone(&self.param_def_id_to_index),
            has_self: ::core::clone::Clone::clone(&self.has_self),
            has_arg_pos_consts: ::core::clone::Clone::clone(&self.has_arg_pos_consts),
            has_late_bound_regions: ::core::clone::Clone::clone(&self.has_late_bound_regions),
        }
    }
}Clone, const _: () =
    {
        impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
            ::rustc_serialize::Encodable<__E> for Generics {
            fn encode(&self, __encoder: &mut __E) {
                let Generics {
                        parent: ref __binding_0,
                        parent_count: ref __binding_1,
                        own_params: ref __binding_2,
                        param_def_id_to_index: ref __binding_3,
                        has_self: ref __binding_4,
                        has_arg_pos_consts: ref __binding_5,
                        has_late_bound_regions: ref __binding_6 } = *self;
                ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                    __encoder);
                ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                    __encoder);
                ::rustc_serialize::Encodable::<__E>::encode(__binding_2,
                    __encoder);
                ::rustc_serialize::Encodable::<__E>::encode(__binding_3,
                    __encoder);
                ::rustc_serialize::Encodable::<__E>::encode(__binding_4,
                    __encoder);
                ::rustc_serialize::Encodable::<__E>::encode(__binding_5,
                    __encoder);
                ::rustc_serialize::Encodable::<__E>::encode(__binding_6,
                    __encoder);
            }
        }
    };TyEncodable, const _: () =
    {
        impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
            ::rustc_serialize::Decodable<__D> for Generics {
            fn decode(__decoder: &mut __D) -> Self {
                Generics {
                    parent: ::rustc_serialize::Decodable::decode(__decoder),
                    parent_count: ::rustc_serialize::Decodable::decode(__decoder),
                    own_params: ::rustc_serialize::Decodable::decode(__decoder),
                    param_def_id_to_index: ::rustc_serialize::Decodable::decode(__decoder),
                    has_self: ::rustc_serialize::Decodable::decode(__decoder),
                    has_arg_pos_consts: ::rustc_serialize::Decodable::decode(__decoder),
                    has_late_bound_regions: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };TyDecodable, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for Generics {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    Generics {
                        parent: ref __binding_0,
                        parent_count: ref __binding_1,
                        own_params: ref __binding_2,
                        param_def_id_to_index: ref __binding_3,
                        has_self: ref __binding_4,
                        has_arg_pos_consts: ref __binding_5,
                        has_late_bound_regions: ref __binding_6 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                        { __binding_2.stable_hash(__hcx, __hasher); }
                        {}
                        { __binding_4.stable_hash(__hcx, __hasher); }
                        { __binding_5.stable_hash(__hcx, __hasher); }
                        { __binding_6.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash)]
138pub struct Generics {
139    pub parent: Option<DefId>,
140    pub parent_count: usize,
141    pub own_params: Vec<GenericParamDef>,
142
143    /// Reverse map to the `index` field of each `GenericParamDef`.
144    #[stable_hash(ignore)]
145    pub param_def_id_to_index: FxHashMap<DefId, u32>,
146
147    pub has_self: bool,
148    pub has_arg_pos_consts: bool,
149    pub has_late_bound_regions: Option<Span>,
150}
151
152impl std::fmt::Debug for Generics {
153    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
154        // ironically, we get this warning because of what we're trying to fix.
155        #[expect(rustc::potential_query_instability)]
156        let mut stabilized_hashmap = self.param_def_id_to_index.iter().collect::<Vec<_>>();
157        stabilized_hashmap.sort_by_key(|(_, v)| **v);
158        f.debug_struct("Generics")
159            .field("parent", &self.parent)
160            .field("parent_count", &self.parent_count)
161            .field("own_params", &self.own_params)
162            .field("param_def_id_to_index", &stabilized_hashmap)
163            .field("has_self", &self.has_self)
164            .field("has_late_bound_regions", &self.has_late_bound_regions)
165            .finish()
166    }
167}
168
169impl<'tcx> rustc_type_ir::inherent::GenericsOf<TyCtxt<'tcx>> for &'tcx Generics {
170    fn count(&self) -> usize {
171        self.parent_count + self.own_params.len()
172    }
173    fn param_region_def_id(self, tcx: TyCtxt<'tcx>, ebr: ty::EarlyParamRegion) -> DefId {
174        self.region_param(ebr, tcx).def_id
175    }
176}
177
178impl<'tcx> Generics {
179    /// Looks through the generics and all parents to find the index of the
180    /// given param def-id. This is in comparison to the `param_def_id_to_index`
181    /// struct member, which only stores information about this item's own
182    /// generics.
183    pub fn param_def_id_to_index(&self, tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<u32> {
184        if let Some(idx) = self.param_def_id_to_index.get(&def_id) {
185            Some(*idx)
186        } else if let Some(parent) = self.parent {
187            let parent = tcx.generics_of(parent);
188            parent.param_def_id_to_index(tcx, def_id)
189        } else {
190            None
191        }
192    }
193
194    #[inline]
195    pub fn count(&self) -> usize {
196        self.parent_count + self.own_params.len()
197    }
198
199    pub fn own_counts(&self) -> GenericParamCount {
200        // We could cache this as a property of `GenericParamCount`, but
201        // the aim is to refactor this away entirely eventually and the
202        // presence of this method will be a constant reminder.
203        let mut own_counts = GenericParamCount::default();
204
205        for param in &self.own_params {
206            match param.kind {
207                GenericParamDefKind::Lifetime => own_counts.lifetimes += 1,
208                GenericParamDefKind::Type { .. } => own_counts.types += 1,
209                GenericParamDefKind::Const { .. } => own_counts.consts += 1,
210            }
211        }
212
213        own_counts
214    }
215
216    pub fn own_defaults(&self) -> GenericParamCount {
217        let mut own_defaults = GenericParamCount::default();
218
219        for param in &self.own_params {
220            match param.kind {
221                GenericParamDefKind::Lifetime => (),
222                GenericParamDefKind::Type { has_default, .. } => {
223                    own_defaults.types += has_default as usize;
224                }
225                GenericParamDefKind::Const { has_default, .. } => {
226                    own_defaults.consts += has_default as usize;
227                }
228            }
229        }
230
231        own_defaults
232    }
233
234    pub fn requires_monomorphization(&self, tcx: TyCtxt<'tcx>) -> bool {
235        if self.own_requires_monomorphization() {
236            return true;
237        }
238
239        if let Some(parent_def_id) = self.parent {
240            let parent = tcx.generics_of(parent_def_id);
241            parent.requires_monomorphization(tcx)
242        } else {
243            false
244        }
245    }
246
247    pub fn own_requires_monomorphization(&self) -> bool {
248        for param in &self.own_params {
249            match param.kind {
250                GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => {
251                    return true;
252                }
253                GenericParamDefKind::Lifetime => {}
254            }
255        }
256        false
257    }
258
259    /// Returns the `GenericParamDef` with the given index.
260    pub fn param_at(&'tcx self, param_index: usize, tcx: TyCtxt<'tcx>) -> &'tcx GenericParamDef {
261        if let Some(index) = param_index.checked_sub(self.parent_count) {
262            &self.own_params[index]
263        } else {
264            tcx.generics_of(self.parent.expect("parent_count > 0 but no parent?"))
265                .param_at(param_index, tcx)
266        }
267    }
268
269    pub fn params_to(&'tcx self, param_index: usize, tcx: TyCtxt<'tcx>) -> &'tcx [GenericParamDef] {
270        if let Some(index) = param_index.checked_sub(self.parent_count) {
271            &self.own_params[..index]
272        } else {
273            tcx.generics_of(self.parent.expect("parent_count > 0 but no parent?"))
274                .params_to(param_index, tcx)
275        }
276    }
277
278    /// Returns the `GenericParamDef` associated with this `EarlyParamRegion`.
279    pub fn region_param(
280        &'tcx self,
281        param: ty::EarlyParamRegion,
282        tcx: TyCtxt<'tcx>,
283    ) -> &'tcx GenericParamDef {
284        let param = self.param_at(param.index as usize, tcx);
285        match param.kind {
286            GenericParamDefKind::Lifetime => param,
287            _ => {
288                ::rustc_span::macros::bug_impl(None,
    format_args!("expected lifetime parameter, but found another generic parameter: {0:#?}",
        param), Location::caller())bug!("expected lifetime parameter, but found another generic parameter: {param:#?}")
289            }
290        }
291    }
292
293    /// Returns the `GenericParamDef` associated with this `ParamTy`.
294    pub fn type_param(&'tcx self, param: ParamTy, tcx: TyCtxt<'tcx>) -> &'tcx GenericParamDef {
295        let param = self.param_at(param.index as usize, tcx);
296        match param.kind {
297            GenericParamDefKind::Type { .. } => param,
298            _ => ::rustc_span::macros::bug_impl(None,
    format_args!("expected type parameter, but found another generic parameter: {0:#?}",
        param), Location::caller())bug!("expected type parameter, but found another generic parameter: {param:#?}"),
299        }
300    }
301
302    /// Returns the `GenericParamDef` associated with this `ParamConst`.
303    pub fn const_param(&'tcx self, param: ParamConst, tcx: TyCtxt<'tcx>) -> &'tcx GenericParamDef {
304        let param = self.param_at(param.index as usize, tcx);
305        match param.kind {
306            GenericParamDefKind::Const { .. } => param,
307            _ => ::rustc_span::macros::bug_impl(None,
    format_args!("expected const parameter, but found another generic parameter: {0:#?}",
        param), Location::caller())bug!("expected const parameter, but found another generic parameter: {param:#?}"),
308        }
309    }
310
311    /// Returns `true` if `params` has `impl Trait`.
312    pub fn has_impl_trait(&'tcx self) -> bool {
313        self.own_params.iter().any(|param| {
314            #[allow(non_exhaustive_omitted_patterns)] match param.kind {
    ty::GenericParamDefKind::Type { synthetic: true, .. } => true,
    _ => false,
}matches!(param.kind, ty::GenericParamDefKind::Type { synthetic: true, .. })
315        })
316    }
317
318    pub fn own_synthetic_params_count(&'tcx self) -> usize {
319        self.own_params.iter().filter(|p| p.kind.is_synthetic()).count()
320    }
321
322    pub fn own_arg_pos_consts(&'tcx self) -> impl Iterator<Item = (&'tcx GenericParamDef, u16)> {
323        let params = if self.has_arg_pos_consts { &self.own_params[..] } else { &[] };
324
325        params.iter().filter_map(|param| Some((param, param.kind.arg_pos()?)))
326    }
327
328    /// Returns the args corresponding to the generic parameters
329    /// of this item, excluding `Self`.
330    ///
331    /// **This should only be used for diagnostics purposes.**
332    pub fn own_args_no_defaults<'a>(
333        &'tcx self,
334        tcx: TyCtxt<'tcx>,
335        args: &'a [ty::GenericArg<'tcx>],
336    ) -> &'a [ty::GenericArg<'tcx>] {
337        let mut own_params = self.parent_count..self.count();
338        if self.has_own_self() {
339            own_params.start = 1;
340        }
341
342        // Filter the default arguments.
343        //
344        // This currently uses structural equality instead
345        // of semantic equivalence. While not ideal, that's
346        // good enough for now as this should only be used
347        // for diagnostics anyways.
348        own_params.end -= self
349            .own_params
350            .iter()
351            .rev()
352            .take_while(|param| {
353                param.default_value(tcx).is_some_and(|default| {
354                    default.instantiate(tcx, args).skip_norm_wip() == args[param.index as usize]
355                })
356            })
357            .count();
358
359        &args[own_params]
360    }
361
362    /// Returns the args corresponding to the generic parameters of this item, excluding `Self`.
363    ///
364    /// **This should only be used for diagnostics purposes.**
365    pub fn own_args<'a>(&self, args: &'a [ty::GenericArg<'tcx>]) -> &'a [ty::GenericArg<'tcx>] {
366        let own = &args[self.parent_count..][..self.own_params.len()];
367        if self.has_own_self() { &own[1..] } else { own }
368    }
369
370    /// Returns true if a concrete type is specified after a default type.
371    /// For example, consider `struct T<W = usize, X = Vec<W>>(W, X)`
372    /// `T<usize, String>` will return true
373    /// `T<usize>` will return false
374    pub fn check_concrete_type_after_default(
375        &'tcx self,
376        tcx: TyCtxt<'tcx>,
377        args: ty::GenericArgs<'tcx>,
378    ) -> bool {
379        let mut default_param_seen = false;
380        for param in self.own_params.iter() {
381            if let Some(inst) = param
382                .default_value(tcx)
383                .map(|default| default.instantiate(tcx, args).skip_norm_wip())
384            {
385                if inst == args[param.index as usize] {
386                    default_param_seen = true;
387                } else if default_param_seen {
388                    return true;
389                }
390            }
391        }
392        false
393    }
394
395    pub fn is_empty(&'tcx self) -> bool {
396        self.count() == 0
397    }
398
399    pub fn is_own_empty(&'tcx self) -> bool {
400        self.own_params.is_empty()
401    }
402
403    pub fn has_own_self(&'tcx self) -> bool {
404        self.has_self && self.parent.is_none()
405    }
406}
407
408/// Bounds on generics.
409#[derive(#[automatically_derived]impl<'tcx> ::core::marker::Copy for
    GenericClauses<'tcx> {
}Copy, #[automatically_derived]#[doc(hidden)]unsafe impl<'tcx>
    ::core::clone::TrivialClone for GenericClauses<'tcx> {
}
#[automatically_derived]impl<'tcx> ::core::clone::Clone for
    GenericClauses<'tcx> {
    #[inline]
    fn clone(&self) -> Self {
        let _: ::core::clone::AssertParamIsClone<Option<DefId>>;
        let _:
                ::core::clone::AssertParamIsClone<&'tcx [(Clause<'tcx>,
                Span)]>;
        *self
    }
}Clone, #[automatically_derived]impl<'tcx> ::core::default::Default for
    GenericClauses<'tcx> {
    #[inline]
    fn default() -> Self {
        GenericClauses {
            parent: ::core::default::Default::default(),
            clauses: ::core::default::Default::default(),
        }
    }
}Default, #[automatically_derived]impl<'tcx> ::core::fmt::Debug for GenericClauses<'tcx>
    {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f,
            "GenericClauses parent clauses", &self.parent, &&self.clauses)
    }
}Debug, const _: () =
    {
        impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
            ::rustc_serialize::Encodable<__E> for GenericClauses<'tcx> {
            fn encode(&self, __encoder: &mut __E) {
                let GenericClauses {
                        parent: ref __binding_0, clauses: __binding_1 } = *self;
                ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                    __encoder);
                ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                    __encoder);
            }
        }
    };TyEncodable, const _: () =
    {
        impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
            ::rustc_serialize::Decodable<__D> for GenericClauses<'tcx> {
            fn decode(__decoder: &mut __D) -> Self {
                GenericClauses {
                    parent: ::rustc_serialize::Decodable::decode(__decoder),
                    clauses: ::rustc_middle::ty::codec::RefDecodable::decode(__decoder),
                }
            }
        }
    };TyDecodable, const _: () =
    {
        impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
            GenericClauses<'tcx> {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    GenericClauses {
                        parent: ref __binding_0, clauses: ref __binding_1 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash)]
410pub struct GenericClauses<'tcx> {
411    pub parent: Option<DefId>,
412    pub clauses: &'tcx [(Clause<'tcx>, Span)],
413}
414
415impl<'tcx> GenericClauses<'tcx> {
416    pub fn instantiate(
417        self,
418        tcx: TyCtxt<'tcx>,
419        args: GenericArgs<'tcx>,
420    ) -> InstantiatedClauses<'tcx> {
421        let mut instantiated = InstantiatedClauses::empty();
422        self.instantiate_into(tcx, &mut instantiated, args);
423        instantiated
424    }
425
426    pub fn instantiate_own(
427        self,
428        tcx: TyCtxt<'tcx>,
429        args: GenericArgs<'tcx>,
430    ) -> impl Iterator<Item = (Unnormalized<'tcx, Clause<'tcx>>, Span)>
431    + DoubleEndedIterator
432    + ExactSizeIterator
433    + Clone {
434        EarlyBinder::bind_iter(self.clauses).iter_instantiated_copied(tcx, args).map(|u| {
435            let (clause, span) = u.unzip();
436            (clause, span.skip_normalization())
437        })
438    }
439
440    pub fn instantiate_own_identity(
441        self,
442    ) -> impl Iterator<Item = (Unnormalized<'tcx, Clause<'tcx>>, Span)>
443    + DoubleEndedIterator
444    + ExactSizeIterator
445    + Clone {
446        EarlyBinder::bind_iter(self.clauses).iter_identity_copied().map(|u| {
447            let (clause, span) = u.unzip();
448            (clause, span.skip_normalization())
449        })
450    }
451
452    {}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("instantiate_into",
                                    "rustc_middle::ty::generics", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/5b7b37aefcb5b2fba3c2392bc9065b9e4602d494/compiler/rustc_middle/src/ty/generics.rs"),
                                    ::tracing_core::__macro_support::Option::Some(452u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_middle::ty::generics"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("instantiated")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("instantiated");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("args")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("args");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&instantiated)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            if let Some(def_id) = self.parent {
                tcx.clauses_of(def_id).instantiate_into(tcx, instantiated,
                    args);
            }
            instantiated.clauses.extend(self.clauses.iter().map(|(p, _)|
                        EarlyBinder::bind(tcx, *p).instantiate(tcx, args)));
            instantiated.spans.extend(self.clauses.iter().map(|(_, sp)| *sp));
        }
    }
}#[instrument(level = "debug", skip(self, tcx))]
453    fn instantiate_into(
454        self,
455        tcx: TyCtxt<'tcx>,
456        instantiated: &mut InstantiatedClauses<'tcx>,
457        args: GenericArgs<'tcx>,
458    ) {
459        if let Some(def_id) = self.parent {
460            tcx.clauses_of(def_id).instantiate_into(tcx, instantiated, args);
461        }
462        instantiated.clauses.extend(
463            self.clauses.iter().map(|(p, _)| EarlyBinder::bind(tcx, *p).instantiate(tcx, args)),
464        );
465        instantiated.spans.extend(self.clauses.iter().map(|(_, sp)| *sp));
466    }
467
468    pub fn instantiate_identity(self, tcx: TyCtxt<'tcx>) -> InstantiatedClauses<'tcx> {
469        let mut instantiated = InstantiatedClauses::empty();
470        self.instantiate_identity_into(tcx, &mut instantiated);
471        instantiated
472    }
473
474    fn instantiate_identity_into(
475        self,
476        tcx: TyCtxt<'tcx>,
477        instantiated: &mut InstantiatedClauses<'tcx>,
478    ) {
479        if let Some(def_id) = self.parent {
480            tcx.clauses_of(def_id).instantiate_identity_into(tcx, instantiated);
481        }
482        instantiated.clauses.extend(self.clauses.iter().map(|(p, _)| Unnormalized::new(*p)));
483        instantiated.spans.extend(self.clauses.iter().map(|(_, s)| s));
484    }
485
486    /// Allow simple where bounds like `T: Debug`, but prevent any kind of
487    /// outlives bounds or uses of generic parameters on the right hand side.
488    ///
489    /// We allow simple bounds because when the `T` actually gets substituted with a concrete type
490    /// during monomorphization, we will be checking its `Debug` impl for fully_generic_for_reflection.
491    ///
492    /// Constants (associated or generic) are irrelevant for this analysis, as their value is neither
493    /// affected by lifetimes, nor do they affect lifetimes.
494    pub fn is_fully_generic_for_reflection(self) -> bool {
495        struct ParamChecker;
496        impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ParamChecker {
497            type Result = ControlFlow<()>;
498            fn visit_region(&mut self, r: Region<'tcx>) -> Self::Result {
499                match r.kind() {
500                    RegionKind::ReEarlyParam(_) | RegionKind::ReStatic | RegionKind::ReError(_) => {
501                        ControlFlow::Break(())
502                    }
503                    RegionKind::ReVar(_)
504                    | RegionKind::RePlaceholder(_)
505                    | RegionKind::ReErased
506                    | RegionKind::ReLateParam(_) => {
507                        ::rustc_span::macros::bug_impl(None,
    format_args!("unexpected lifetime in impl: {0:?}", r), Location::caller())bug!("unexpected lifetime in impl: {r:?}")
508                    }
509                    RegionKind::ReBound(..) => ControlFlow::Continue(()),
510                }
511            }
512
513            fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
514                match t.kind() {
515                    TyKind::Param(_p) => {
516                        // Reject using parameters used in the type in where bounds
517                        return ControlFlow::Break(());
518                    }
519                    TyKind::Alias(..) => return ControlFlow::Break(()),
520                    _ => (),
521                }
522                t.super_visit_with(self)
523            }
524        }
525
526        // Pessimistic: if any of the parameters have where bounds
527        // don't allow this impl to be used.
528        self.clauses.iter().all(|(clause, _)| {
529            match clause.kind().skip_binder() {
530                ClauseKind::Trait(trait_predicate) => {
531                    // In a `T: Trait`, if the rhs bound does not contain any generic params
532                    // or 'static lifetimes, then it cannot transitively cause such requirements,
533                    // considering we apply the fully-generic-for-reflection rules to any impls for
534                    // that trait, too.
535                    if #[allow(non_exhaustive_omitted_patterns)] match trait_predicate.self_ty().kind()
    {
    ty::Param(_) => true,
    _ => false,
}matches!(trait_predicate.self_ty().kind(), ty::Param(_))
536                        && trait_predicate.trait_ref.args.as_slice()[1..]
537                            .iter()
538                            .all(|arg| arg.visit_with(&mut ParamChecker).is_continue())
539                    {
540                        return true;
541                    }
542                }
543                ClauseKind::RegionOutlives(_)
544                | ClauseKind::TypeOutlives(_)
545                | ClauseKind::Projection(_)
546                | ClauseKind::ConstArgHasType(_, _)
547                | ClauseKind::WellFormed(_)
548                | ClauseKind::ConstEvaluatable(_)
549                | ClauseKind::HostEffect(_)
550                | ClauseKind::UnstableFeature(_) => {}
551            }
552            clause.visit_with(&mut ParamChecker).is_continue()
553        })
554    }
555}
556
557/// `[const]` bounds for a given item. This is represented using a struct much like
558/// `GenericClauses`, where you can either choose to only instantiate the "own"
559/// bounds or all of the bounds including those from the parent. This distinction
560/// is necessary for code like `compare_method_clause_entailment`.
561#[derive(#[automatically_derived]impl<'tcx> ::core::marker::Copy for
    ConstConditions<'tcx> {
}Copy, #[automatically_derived]#[doc(hidden)]unsafe impl<'tcx>
    ::core::clone::TrivialClone for ConstConditions<'tcx> {
}
#[automatically_derived]impl<'tcx> ::core::clone::Clone for
    ConstConditions<'tcx> {
    #[inline]
    fn clone(&self) -> Self {
        let _: ::core::clone::AssertParamIsClone<Option<DefId>>;
        let _:
                ::core::clone::AssertParamIsClone<&'tcx [(ty::PolyTraitRef<'tcx>,
                Span)]>;
        *self
    }
}Clone, #[automatically_derived]impl<'tcx> ::core::default::Default for
    ConstConditions<'tcx> {
    #[inline]
    fn default() -> Self {
        ConstConditions {
            parent: ::core::default::Default::default(),
            clauses: ::core::default::Default::default(),
        }
    }
}Default, #[automatically_derived]impl<'tcx> ::core::fmt::Debug for
    ConstConditions<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f,
            "ConstConditions parent clauses", &self.parent, &&self.clauses)
    }
}Debug, const _: () =
    {
        impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
            ::rustc_serialize::Encodable<__E> for ConstConditions<'tcx> {
            fn encode(&self, __encoder: &mut __E) {
                let ConstConditions {
                        parent: ref __binding_0, clauses: __binding_1 } = *self;
                ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                    __encoder);
                ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                    __encoder);
            }
        }
    };TyEncodable, const _: () =
    {
        impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
            ::rustc_serialize::Decodable<__D> for ConstConditions<'tcx> {
            fn decode(__decoder: &mut __D) -> Self {
                ConstConditions {
                    parent: ::rustc_serialize::Decodable::decode(__decoder),
                    clauses: ::rustc_middle::ty::codec::RefDecodable::decode(__decoder),
                }
            }
        }
    };TyDecodable, const _: () =
    {
        impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
            ConstConditions<'tcx> {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    ConstConditions {
                        parent: ref __binding_0, clauses: ref __binding_1 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash)]
562pub struct ConstConditions<'tcx> {
563    pub parent: Option<DefId>,
564    pub clauses: &'tcx [(ty::PolyTraitRef<'tcx>, Span)],
565}
566
567impl<'tcx> ConstConditions<'tcx> {
568    pub fn instantiate(
569        self,
570        tcx: TyCtxt<'tcx>,
571        args: GenericArgs<'tcx>,
572    ) -> Vec<(Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>, Span)> {
573        let mut instantiated = ::alloc::vec::Vec::new()vec![];
574        self.instantiate_into(tcx, &mut instantiated, args);
575        instantiated
576    }
577
578    pub fn instantiate_own(
579        self,
580        tcx: TyCtxt<'tcx>,
581        args: GenericArgs<'tcx>,
582    ) -> impl Iterator<Item = (Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>, Span)>
583    + DoubleEndedIterator
584    + ExactSizeIterator
585    + Clone {
586        EarlyBinder::bind_iter(self.clauses).iter_instantiated_copied(tcx, args).map(|u| {
587            let (trait_ref, span) = u.unzip();
588            (trait_ref, span.skip_normalization())
589        })
590    }
591
592    pub fn instantiate_own_identity(
593        self,
594    ) -> impl Iterator<Item = (Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>, Span)>
595    + DoubleEndedIterator
596    + ExactSizeIterator
597    + Clone {
598        EarlyBinder::bind_iter(self.clauses).iter_identity_copied().map(|u| {
599            let (trait_ref, span) = u.unzip();
600            (trait_ref, span.skip_normalization())
601        })
602    }
603
604    {}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("instantiate_into",
                                    "rustc_middle::ty::generics", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/5b7b37aefcb5b2fba3c2392bc9065b9e4602d494/compiler/rustc_middle/src/ty/generics.rs"),
                                    ::tracing_core::__macro_support::Option::Some(604u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_middle::ty::generics"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("instantiated")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("instantiated");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("args")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("args");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&instantiated)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            if let Some(def_id) = self.parent {
                tcx.const_conditions(def_id).instantiate_into(tcx,
                    instantiated, args);
            }
            instantiated.extend(self.clauses.iter().map(|&(c, s)|
                        (EarlyBinder::bind(tcx, c).instantiate(tcx, args), s)));
        }
    }
}#[instrument(level = "debug", skip(self, tcx))]
605    fn instantiate_into(
606        self,
607        tcx: TyCtxt<'tcx>,
608        instantiated: &mut Vec<(Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>, Span)>,
609        args: GenericArgs<'tcx>,
610    ) {
611        if let Some(def_id) = self.parent {
612            tcx.const_conditions(def_id).instantiate_into(tcx, instantiated, args);
613        }
614        instantiated.extend(
615            self.clauses
616                .iter()
617                .map(|&(c, s)| (EarlyBinder::bind(tcx, c).instantiate(tcx, args), s)),
618        );
619    }
620
621    pub fn instantiate_identity(
622        self,
623        tcx: TyCtxt<'tcx>,
624    ) -> Vec<(Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>, Span)> {
625        let mut instantiated = ::alloc::vec::Vec::new()vec![];
626        self.instantiate_identity_into(tcx, &mut instantiated);
627        instantiated
628    }
629
630    fn instantiate_identity_into(
631        self,
632        tcx: TyCtxt<'tcx>,
633        instantiated: &mut Vec<(Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>, Span)>,
634    ) {
635        if let Some(def_id) = self.parent {
636            tcx.const_conditions(def_id).instantiate_identity_into(tcx, instantiated);
637        }
638        instantiated.extend(
639            self.clauses
640                .iter()
641                .copied()
642                .map(|(trait_ref, span)| (Unnormalized::new(trait_ref), span)),
643        );
644    }
645}