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, GenericArgsRef, 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", __self_0, "synthetic", &__self_1),
            Self::Const { has_default: __self_0, arg_pos: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f, "Const",
                    "has_default", __self_0, "arg_pos", &__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) {
                ::std::mem::discriminant(self).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", &self.name, "def_id", &self.def_id,
            "index", &self.index, "pure_wrt_drop", &self.pure_wrt_drop,
            "kind", &&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(
366        &'tcx self,
367        args: &'tcx [ty::GenericArg<'tcx>],
368    ) -> &'tcx [ty::GenericArg<'tcx>] {
369        let own = &args[self.parent_count..][..self.own_params.len()];
370        if self.has_own_self() { &own[1..] } else { own }
371    }
372
373    /// Returns true if a concrete type is specified after a default type.
374    /// For example, consider `struct T<W = usize, X = Vec<W>>(W, X)`
375    /// `T<usize, String>` will return true
376    /// `T<usize>` will return false
377    pub fn check_concrete_type_after_default(
378        &'tcx self,
379        tcx: TyCtxt<'tcx>,
380        args: &'tcx [ty::GenericArg<'tcx>],
381    ) -> bool {
382        let mut default_param_seen = false;
383        for param in self.own_params.iter() {
384            if let Some(inst) = param
385                .default_value(tcx)
386                .map(|default| default.instantiate(tcx, args).skip_norm_wip())
387            {
388                if inst == args[param.index as usize] {
389                    default_param_seen = true;
390                } else if default_param_seen {
391                    return true;
392                }
393            }
394        }
395        false
396    }
397
398    pub fn is_empty(&'tcx self) -> bool {
399        self.count() == 0
400    }
401
402    pub fn is_own_empty(&'tcx self) -> bool {
403        self.own_params.is_empty()
404    }
405
406    pub fn has_own_self(&'tcx self) -> bool {
407        self.has_self && self.parent.is_none()
408    }
409}
410
411/// Bounds on generics.
412#[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", &self.parent, "clauses",
            &&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)]
413pub struct GenericClauses<'tcx> {
414    pub parent: Option<DefId>,
415    pub clauses: &'tcx [(Clause<'tcx>, Span)],
416}
417
418impl<'tcx> GenericClauses<'tcx> {
419    pub fn instantiate(
420        self,
421        tcx: TyCtxt<'tcx>,
422        args: GenericArgsRef<'tcx>,
423    ) -> InstantiatedClauses<'tcx> {
424        let mut instantiated = InstantiatedClauses::empty();
425        self.instantiate_into(tcx, &mut instantiated, args);
426        instantiated
427    }
428
429    pub fn instantiate_own(
430        self,
431        tcx: TyCtxt<'tcx>,
432        args: GenericArgsRef<'tcx>,
433    ) -> impl Iterator<Item = (Unnormalized<'tcx, Clause<'tcx>>, Span)>
434    + DoubleEndedIterator
435    + ExactSizeIterator
436    + Clone {
437        EarlyBinder::bind_iter(self.clauses).iter_instantiated_copied(tcx, args).map(|u| {
438            let (clause, span) = u.unzip();
439            (clause, span.skip_normalization())
440        })
441    }
442
443    pub fn instantiate_own_identity(
444        self,
445    ) -> impl Iterator<Item = (Unnormalized<'tcx, Clause<'tcx>>, Span)>
446    + DoubleEndedIterator
447    + ExactSizeIterator
448    + Clone {
449        EarlyBinder::bind_iter(self.clauses).iter_identity_copied().map(|u| {
450            let (clause, span) = u.unzip();
451            (clause, span.skip_normalization())
452        })
453    }
454
455    {}
#[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/07e526db9df34143c99ec8064acc8ad543f69b30/compiler/rustc_middle/src/ty/generics.rs"),
                                    ::tracing_core::__macro_support::Option::Some(455u32),
                                    ::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))]
456    fn instantiate_into(
457        self,
458        tcx: TyCtxt<'tcx>,
459        instantiated: &mut InstantiatedClauses<'tcx>,
460        args: GenericArgsRef<'tcx>,
461    ) {
462        if let Some(def_id) = self.parent {
463            tcx.clauses_of(def_id).instantiate_into(tcx, instantiated, args);
464        }
465        instantiated.clauses.extend(
466            self.clauses.iter().map(|(p, _)| EarlyBinder::bind(tcx, *p).instantiate(tcx, args)),
467        );
468        instantiated.spans.extend(self.clauses.iter().map(|(_, sp)| *sp));
469    }
470
471    pub fn instantiate_identity(self, tcx: TyCtxt<'tcx>) -> InstantiatedClauses<'tcx> {
472        let mut instantiated = InstantiatedClauses::empty();
473        self.instantiate_identity_into(tcx, &mut instantiated);
474        instantiated
475    }
476
477    fn instantiate_identity_into(
478        self,
479        tcx: TyCtxt<'tcx>,
480        instantiated: &mut InstantiatedClauses<'tcx>,
481    ) {
482        if let Some(def_id) = self.parent {
483            tcx.clauses_of(def_id).instantiate_identity_into(tcx, instantiated);
484        }
485        instantiated.clauses.extend(self.clauses.iter().map(|(p, _)| Unnormalized::new(*p)));
486        instantiated.spans.extend(self.clauses.iter().map(|(_, s)| s));
487    }
488
489    /// Allow simple where bounds like `T: Debug`, but prevent any kind of
490    /// outlives bounds or uses of generic parameters on the right hand side.
491    ///
492    /// We allow simple bounds because when the `T` actually gets substituted with a concrete type
493    /// during monomorphization, we will be checking its `Debug` impl for fully_generic_for_reflection.
494    ///
495    /// Constants (associated or generic) are irrelevant for this analysis, as their value is neither
496    /// affected by lifetimes, nor do they affect lifetimes.
497    pub fn is_fully_generic_for_reflection(self) -> bool {
498        struct ParamChecker;
499        impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ParamChecker {
500            type Result = ControlFlow<()>;
501            fn visit_region(&mut self, r: Region<'tcx>) -> Self::Result {
502                match r.kind() {
503                    RegionKind::ReEarlyParam(_) | RegionKind::ReStatic | RegionKind::ReError(_) => {
504                        ControlFlow::Break(())
505                    }
506                    RegionKind::ReVar(_)
507                    | RegionKind::RePlaceholder(_)
508                    | RegionKind::ReErased
509                    | RegionKind::ReLateParam(_) => {
510                        ::rustc_span::macros::bug_impl(None,
    format_args!("unexpected lifetime in impl: {0:?}", r), Location::caller())bug!("unexpected lifetime in impl: {r:?}")
511                    }
512                    RegionKind::ReBound(..) => ControlFlow::Continue(()),
513                }
514            }
515
516            fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
517                match t.kind() {
518                    TyKind::Param(_p) => {
519                        // Reject using parameters used in the type in where bounds
520                        return ControlFlow::Break(());
521                    }
522                    TyKind::Alias(..) => return ControlFlow::Break(()),
523                    _ => (),
524                }
525                t.super_visit_with(self)
526            }
527        }
528
529        // Pessimistic: if any of the parameters have where bounds
530        // don't allow this impl to be used.
531        self.clauses.iter().all(|(clause, _)| {
532            match clause.kind().skip_binder() {
533                ClauseKind::Trait(trait_predicate) => {
534                    // In a `T: Trait`, if the rhs bound does not contain any generic params
535                    // or 'static lifetimes, then it cannot transitively cause such requirements,
536                    // considering we apply the fully-generic-for-reflection rules to any impls for
537                    // that trait, too.
538                    if #[allow(non_exhaustive_omitted_patterns)] match trait_predicate.self_ty().kind()
    {
    ty::Param(_) => true,
    _ => false,
}matches!(trait_predicate.self_ty().kind(), ty::Param(_))
539                        && trait_predicate.trait_ref.args[1..]
540                            .iter()
541                            .all(|arg| arg.visit_with(&mut ParamChecker).is_continue())
542                    {
543                        return true;
544                    }
545                }
546                ClauseKind::RegionOutlives(_)
547                | ClauseKind::TypeOutlives(_)
548                | ClauseKind::Projection(_)
549                | ClauseKind::ConstArgHasType(_, _)
550                | ClauseKind::WellFormed(_)
551                | ClauseKind::ConstEvaluatable(_)
552                | ClauseKind::HostEffect(_)
553                | ClauseKind::UnstableFeature(_) => {}
554            }
555            clause.visit_with(&mut ParamChecker).is_continue()
556        })
557    }
558}
559
560/// `[const]` bounds for a given item. This is represented using a struct much like
561/// `GenericClauses`, where you can either choose to only instantiate the "own"
562/// bounds or all of the bounds including those from the parent. This distinction
563/// is necessary for code like `compare_method_clause_entailment`.
564#[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", &self.parent, "clauses",
            &&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)]
565pub struct ConstConditions<'tcx> {
566    pub parent: Option<DefId>,
567    pub clauses: &'tcx [(ty::PolyTraitRef<'tcx>, Span)],
568}
569
570impl<'tcx> ConstConditions<'tcx> {
571    pub fn instantiate(
572        self,
573        tcx: TyCtxt<'tcx>,
574        args: GenericArgsRef<'tcx>,
575    ) -> Vec<(Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>, Span)> {
576        let mut instantiated = ::alloc::vec::Vec::new()vec![];
577        self.instantiate_into(tcx, &mut instantiated, args);
578        instantiated
579    }
580
581    pub fn instantiate_own(
582        self,
583        tcx: TyCtxt<'tcx>,
584        args: GenericArgsRef<'tcx>,
585    ) -> impl Iterator<Item = (Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>, Span)>
586    + DoubleEndedIterator
587    + ExactSizeIterator
588    + Clone {
589        EarlyBinder::bind_iter(self.clauses).iter_instantiated_copied(tcx, args).map(|u| {
590            let (trait_ref, span) = u.unzip();
591            (trait_ref, span.skip_normalization())
592        })
593    }
594
595    pub fn instantiate_own_identity(
596        self,
597    ) -> impl Iterator<Item = (Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>, Span)>
598    + DoubleEndedIterator
599    + ExactSizeIterator
600    + Clone {
601        EarlyBinder::bind_iter(self.clauses).iter_identity_copied().map(|u| {
602            let (trait_ref, span) = u.unzip();
603            (trait_ref, span.skip_normalization())
604        })
605    }
606
607    {}
#[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/07e526db9df34143c99ec8064acc8ad543f69b30/compiler/rustc_middle/src/ty/generics.rs"),
                                    ::tracing_core::__macro_support::Option::Some(607u32),
                                    ::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))]
608    fn instantiate_into(
609        self,
610        tcx: TyCtxt<'tcx>,
611        instantiated: &mut Vec<(Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>, Span)>,
612        args: GenericArgsRef<'tcx>,
613    ) {
614        if let Some(def_id) = self.parent {
615            tcx.const_conditions(def_id).instantiate_into(tcx, instantiated, args);
616        }
617        instantiated.extend(
618            self.clauses
619                .iter()
620                .map(|&(c, s)| (EarlyBinder::bind(tcx, c).instantiate(tcx, args), s)),
621        );
622    }
623
624    pub fn instantiate_identity(
625        self,
626        tcx: TyCtxt<'tcx>,
627    ) -> Vec<(Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>, Span)> {
628        let mut instantiated = ::alloc::vec::Vec::new()vec![];
629        self.instantiate_identity_into(tcx, &mut instantiated);
630        instantiated
631    }
632
633    fn instantiate_identity_into(
634        self,
635        tcx: TyCtxt<'tcx>,
636        instantiated: &mut Vec<(Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>, Span)>,
637    ) {
638        if let Some(def_id) = self.parent {
639            tcx.const_conditions(def_id).instantiate_identity_into(tcx, instantiated);
640        }
641        instantiated.extend(
642            self.clauses
643                .iter()
644                .copied()
645                .map(|(trait_ref, span)| (Unnormalized::new(trait_ref), span)),
646        );
647    }
648}