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, 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::region::RegionExt;
13use crate::ty::{self, ClauseKind, EarlyBinder, GenericArgsRef, Region, RegionKind, TyKind};
14
15#[derive(#[automatically_derived]
impl ::core::clone::Clone for GenericParamDefKind {
    #[inline]
    fn clone(&self) -> GenericParamDefKind {
        match self {
            GenericParamDefKind::Lifetime => GenericParamDefKind::Lifetime,
            GenericParamDefKind::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),
                },
            GenericParamDefKind::Const { has_default: __self_0 } =>
                GenericParamDefKind::Const {
                    has_default: ::core::clone::Clone::clone(__self_0),
                },
        }
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for GenericParamDefKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            GenericParamDefKind::Lifetime =>
                ::core::fmt::Formatter::write_str(f, "Lifetime"),
            GenericParamDefKind::Type {
                has_default: __self_0, synthetic: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f, "Type",
                    "has_default", __self_0, "synthetic", &__self_1),
            GenericParamDefKind::Const { has_default: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f, "Const",
                    "has_default", &__self_0),
        }
    }
}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 }
                            => {
                            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 }
                        => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __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),
                        }
                    }
                    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 }
                        => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash)]
16pub enum GenericParamDefKind {
17    Lifetime,
18    Type { has_default: bool, synthetic: bool },
19    Const { has_default: bool },
20}
21
22impl GenericParamDefKind {
23    pub fn descr(&self) -> &'static str {
24        match self {
25            GenericParamDefKind::Lifetime => "lifetime",
26            GenericParamDefKind::Type { .. } => "type",
27            GenericParamDefKind::Const { .. } => "constant",
28        }
29    }
30    pub fn to_ord(&self) -> ast::ParamKindOrd {
31        match self {
32            GenericParamDefKind::Lifetime => ast::ParamKindOrd::Lifetime,
33            GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => {
34                ast::ParamKindOrd::TypeOrConst
35            }
36        }
37    }
38
39    pub fn is_ty_or_const(&self) -> bool {
40        match self {
41            GenericParamDefKind::Lifetime => false,
42            GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => true,
43        }
44    }
45
46    pub fn is_synthetic(&self) -> bool {
47        match self {
48            GenericParamDefKind::Type { synthetic, .. } => *synthetic,
49            _ => false,
50        }
51    }
52}
53
54#[derive(#[automatically_derived]
impl ::core::clone::Clone for GenericParamDef {
    #[inline]
    fn clone(&self) -> GenericParamDef {
        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) {
                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 } => {
                        ::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)]
55pub struct GenericParamDef {
56    pub name: Symbol,
57    pub def_id: DefId,
58    pub index: u32,
59
60    /// `pure_wrt_drop`, set by the (unsafe) `#[may_dangle]` attribute
61    /// on generic parameter `'a`/`T`, asserts data behind the parameter
62    /// `'a`/`T` won't be accessed during the parent type's `Drop` impl.
63    pub pure_wrt_drop: bool,
64
65    pub kind: GenericParamDefKind,
66}
67
68impl GenericParamDef {
69    pub fn to_early_bound_region_data(&self) -> ty::EarlyParamRegion {
70        if let GenericParamDefKind::Lifetime = self.kind {
71            ty::EarlyParamRegion { index: self.index, name: self.name }
72        } else {
73            crate::util::bug::bug_fmt(format_args!("cannot convert a non-lifetime parameter def to an early bound region"))bug!("cannot convert a non-lifetime parameter def to an early bound region")
74        }
75    }
76
77    pub fn is_anonymous_lifetime(&self) -> bool {
78        match self.kind {
79            GenericParamDefKind::Lifetime => self.name == kw::UnderscoreLifetime,
80            _ => false,
81        }
82    }
83
84    pub fn default_value<'tcx>(
85        &self,
86        tcx: TyCtxt<'tcx>,
87    ) -> Option<EarlyBinder<'tcx, ty::GenericArg<'tcx>>> {
88        match self.kind {
89            GenericParamDefKind::Type { has_default: true, .. } => {
90                Some(tcx.type_of(self.def_id).map_bound(|t| t.into()))
91            }
92            GenericParamDefKind::Const { has_default: true, .. } => {
93                Some(tcx.const_param_default(self.def_id).map_bound(|c| c.into()))
94            }
95            _ => None,
96        }
97    }
98
99    pub fn to_error<'tcx>(&self, tcx: TyCtxt<'tcx>) -> ty::GenericArg<'tcx> {
100        match &self.kind {
101            ty::GenericParamDefKind::Lifetime => ty::Region::new_error_misc(tcx).into(),
102            ty::GenericParamDefKind::Type { .. } => Ty::new_misc_error(tcx).into(),
103            ty::GenericParamDefKind::Const { .. } => ty::Const::new_misc_error(tcx).into(),
104        }
105    }
106}
107
108#[derive(#[automatically_derived]
impl ::core::default::Default for GenericParamCount {
    #[inline]
    fn default() -> GenericParamCount {
        GenericParamCount {
            lifetimes: ::core::default::Default::default(),
            types: ::core::default::Default::default(),
            consts: ::core::default::Default::default(),
        }
    }
}Default)]
109pub struct GenericParamCount {
110    pub lifetimes: usize,
111    pub types: usize,
112    pub consts: usize,
113}
114
115/// Information about the formal type/lifetime parameters associated
116/// with an item or method. Analogous to `hir::Generics`.
117///
118/// The ordering of parameters is the same as in [`ty::GenericArg`] (excluding child generics):
119/// `Self` (optionally), `Lifetime` params..., `Type` params...
120#[derive(#[automatically_derived]
impl ::core::clone::Clone for Generics {
    #[inline]
    fn clone(&self) -> Generics {
        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_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) {
                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_late_bound_regions: ref __binding_5 } => {
                        ::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);
                    }
                }
            }
        }
    };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_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_late_bound_regions: ref __binding_5 } => {
                        { __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); }
                    }
                }
            }
        }
    };StableHash)]
121pub struct Generics {
122    pub parent: Option<DefId>,
123    pub parent_count: usize,
124    pub own_params: Vec<GenericParamDef>,
125
126    /// Reverse map to the `index` field of each `GenericParamDef`.
127    #[stable_hash(ignore)]
128    pub param_def_id_to_index: FxHashMap<DefId, u32>,
129
130    pub has_self: bool,
131    pub has_late_bound_regions: Option<Span>,
132}
133
134impl std::fmt::Debug for Generics {
135    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
136        // ironically, we get this warning because of what we're trying to fix.
137        #[expect(rustc::potential_query_instability)]
138        let mut stabilized_hashmap = self.param_def_id_to_index.iter().collect::<Vec<_>>();
139        stabilized_hashmap.sort_by_key(|(_, v)| **v);
140        f.debug_struct("Generics")
141            .field("parent", &self.parent)
142            .field("parent_count", &self.parent_count)
143            .field("own_params", &self.own_params)
144            .field("param_def_id_to_index", &stabilized_hashmap)
145            .field("has_self", &self.has_self)
146            .field("has_late_bound_regions", &self.has_late_bound_regions)
147            .finish()
148    }
149}
150
151impl<'tcx> rustc_type_ir::inherent::GenericsOf<TyCtxt<'tcx>> for &'tcx Generics {
152    fn count(&self) -> usize {
153        self.parent_count + self.own_params.len()
154    }
155}
156
157impl<'tcx> Generics {
158    /// Looks through the generics and all parents to find the index of the
159    /// given param def-id. This is in comparison to the `param_def_id_to_index`
160    /// struct member, which only stores information about this item's own
161    /// generics.
162    pub fn param_def_id_to_index(&self, tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<u32> {
163        if let Some(idx) = self.param_def_id_to_index.get(&def_id) {
164            Some(*idx)
165        } else if let Some(parent) = self.parent {
166            let parent = tcx.generics_of(parent);
167            parent.param_def_id_to_index(tcx, def_id)
168        } else {
169            None
170        }
171    }
172
173    #[inline]
174    pub fn count(&self) -> usize {
175        self.parent_count + self.own_params.len()
176    }
177
178    pub fn own_counts(&self) -> GenericParamCount {
179        // We could cache this as a property of `GenericParamCount`, but
180        // the aim is to refactor this away entirely eventually and the
181        // presence of this method will be a constant reminder.
182        let mut own_counts = GenericParamCount::default();
183
184        for param in &self.own_params {
185            match param.kind {
186                GenericParamDefKind::Lifetime => own_counts.lifetimes += 1,
187                GenericParamDefKind::Type { .. } => own_counts.types += 1,
188                GenericParamDefKind::Const { .. } => own_counts.consts += 1,
189            }
190        }
191
192        own_counts
193    }
194
195    pub fn own_defaults(&self) -> GenericParamCount {
196        let mut own_defaults = GenericParamCount::default();
197
198        for param in &self.own_params {
199            match param.kind {
200                GenericParamDefKind::Lifetime => (),
201                GenericParamDefKind::Type { has_default, .. } => {
202                    own_defaults.types += has_default as usize;
203                }
204                GenericParamDefKind::Const { has_default, .. } => {
205                    own_defaults.consts += has_default as usize;
206                }
207            }
208        }
209
210        own_defaults
211    }
212
213    pub fn requires_monomorphization(&self, tcx: TyCtxt<'tcx>) -> bool {
214        if self.own_requires_monomorphization() {
215            return true;
216        }
217
218        if let Some(parent_def_id) = self.parent {
219            let parent = tcx.generics_of(parent_def_id);
220            parent.requires_monomorphization(tcx)
221        } else {
222            false
223        }
224    }
225
226    pub fn own_requires_monomorphization(&self) -> bool {
227        for param in &self.own_params {
228            match param.kind {
229                GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => {
230                    return true;
231                }
232                GenericParamDefKind::Lifetime => {}
233            }
234        }
235        false
236    }
237
238    /// Returns the `GenericParamDef` with the given index.
239    pub fn param_at(&'tcx self, param_index: usize, tcx: TyCtxt<'tcx>) -> &'tcx GenericParamDef {
240        if let Some(index) = param_index.checked_sub(self.parent_count) {
241            &self.own_params[index]
242        } else {
243            tcx.generics_of(self.parent.expect("parent_count > 0 but no parent?"))
244                .param_at(param_index, tcx)
245        }
246    }
247
248    pub fn params_to(&'tcx self, param_index: usize, tcx: TyCtxt<'tcx>) -> &'tcx [GenericParamDef] {
249        if let Some(index) = param_index.checked_sub(self.parent_count) {
250            &self.own_params[..index]
251        } else {
252            tcx.generics_of(self.parent.expect("parent_count > 0 but no parent?"))
253                .params_to(param_index, tcx)
254        }
255    }
256
257    /// Returns the `GenericParamDef` associated with this `EarlyParamRegion`.
258    pub fn region_param(
259        &'tcx self,
260        param: ty::EarlyParamRegion,
261        tcx: TyCtxt<'tcx>,
262    ) -> &'tcx GenericParamDef {
263        let param = self.param_at(param.index as usize, tcx);
264        match param.kind {
265            GenericParamDefKind::Lifetime => param,
266            _ => {
267                crate::util::bug::bug_fmt(format_args!("expected lifetime parameter, but found another generic parameter: {0:#?}",
        param))bug!("expected lifetime parameter, but found another generic parameter: {param:#?}")
268            }
269        }
270    }
271
272    /// Returns the `GenericParamDef` associated with this `ParamTy`.
273    pub fn type_param(&'tcx self, param: ParamTy, tcx: TyCtxt<'tcx>) -> &'tcx GenericParamDef {
274        let param = self.param_at(param.index as usize, tcx);
275        match param.kind {
276            GenericParamDefKind::Type { .. } => param,
277            _ => crate::util::bug::bug_fmt(format_args!("expected type parameter, but found another generic parameter: {0:#?}",
        param))bug!("expected type parameter, but found another generic parameter: {param:#?}"),
278        }
279    }
280
281    /// Returns the `GenericParamDef` associated with this `ParamConst`.
282    pub fn const_param(&'tcx self, param: ParamConst, tcx: TyCtxt<'tcx>) -> &'tcx GenericParamDef {
283        let param = self.param_at(param.index as usize, tcx);
284        match param.kind {
285            GenericParamDefKind::Const { .. } => param,
286            _ => crate::util::bug::bug_fmt(format_args!("expected const parameter, but found another generic parameter: {0:#?}",
        param))bug!("expected const parameter, but found another generic parameter: {param:#?}"),
287        }
288    }
289
290    /// Returns `true` if `params` has `impl Trait`.
291    pub fn has_impl_trait(&'tcx self) -> bool {
292        self.own_params.iter().any(|param| {
293            #[allow(non_exhaustive_omitted_patterns)] match param.kind {
    ty::GenericParamDefKind::Type { synthetic: true, .. } => true,
    _ => false,
}matches!(param.kind, ty::GenericParamDefKind::Type { synthetic: true, .. })
294        })
295    }
296
297    pub fn own_synthetic_params_count(&'tcx self) -> usize {
298        self.own_params.iter().filter(|p| p.kind.is_synthetic()).count()
299    }
300
301    /// Returns the args corresponding to the generic parameters
302    /// of this item, excluding `Self`.
303    ///
304    /// **This should only be used for diagnostics purposes.**
305    pub fn own_args_no_defaults<'a>(
306        &'tcx self,
307        tcx: TyCtxt<'tcx>,
308        args: &'a [ty::GenericArg<'tcx>],
309    ) -> &'a [ty::GenericArg<'tcx>] {
310        let mut own_params = self.parent_count..self.count();
311        if self.has_own_self() {
312            own_params.start = 1;
313        }
314
315        // Filter the default arguments.
316        //
317        // This currently uses structural equality instead
318        // of semantic equivalence. While not ideal, that's
319        // good enough for now as this should only be used
320        // for diagnostics anyways.
321        own_params.end -= self
322            .own_params
323            .iter()
324            .rev()
325            .take_while(|param| {
326                param.default_value(tcx).is_some_and(|default| {
327                    default.instantiate(tcx, args).skip_norm_wip() == args[param.index as usize]
328                })
329            })
330            .count();
331
332        &args[own_params]
333    }
334
335    /// Returns the args corresponding to the generic parameters of this item, excluding `Self`.
336    ///
337    /// **This should only be used for diagnostics purposes.**
338    pub fn own_args(
339        &'tcx self,
340        args: &'tcx [ty::GenericArg<'tcx>],
341    ) -> &'tcx [ty::GenericArg<'tcx>] {
342        let own = &args[self.parent_count..][..self.own_params.len()];
343        if self.has_own_self() { &own[1..] } else { own }
344    }
345
346    /// Returns true if a concrete type is specified after a default type.
347    /// For example, consider `struct T<W = usize, X = Vec<W>>(W, X)`
348    /// `T<usize, String>` will return true
349    /// `T<usize>` will return false
350    pub fn check_concrete_type_after_default(
351        &'tcx self,
352        tcx: TyCtxt<'tcx>,
353        args: &'tcx [ty::GenericArg<'tcx>],
354    ) -> bool {
355        let mut default_param_seen = false;
356        for param in self.own_params.iter() {
357            if let Some(inst) = param
358                .default_value(tcx)
359                .map(|default| default.instantiate(tcx, args).skip_norm_wip())
360            {
361                if inst == args[param.index as usize] {
362                    default_param_seen = true;
363                } else if default_param_seen {
364                    return true;
365                }
366            }
367        }
368        false
369    }
370
371    pub fn is_empty(&'tcx self) -> bool {
372        self.count() == 0
373    }
374
375    pub fn is_own_empty(&'tcx self) -> bool {
376        self.own_params.is_empty()
377    }
378
379    pub fn has_own_self(&'tcx self) -> bool {
380        self.has_self && self.parent.is_none()
381    }
382}
383
384/// Bounds on generics.
385#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for GenericClauses<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for GenericClauses<'tcx> {
    #[inline]
    fn clone(&self) -> GenericClauses<'tcx> {
        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() -> GenericClauses<'tcx> {
        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) {
                match *self {
                    GenericClauses {
                        parent: ref __binding_0, clauses: __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 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)]
386pub struct GenericClauses<'tcx> {
387    pub parent: Option<DefId>,
388    pub clauses: &'tcx [(Clause<'tcx>, Span)],
389}
390
391impl<'tcx> GenericClauses<'tcx> {
392    pub fn instantiate(
393        self,
394        tcx: TyCtxt<'tcx>,
395        args: GenericArgsRef<'tcx>,
396    ) -> InstantiatedClauses<'tcx> {
397        let mut instantiated = InstantiatedClauses::empty();
398        self.instantiate_into(tcx, &mut instantiated, args);
399        instantiated
400    }
401
402    pub fn instantiate_own(
403        self,
404        tcx: TyCtxt<'tcx>,
405        args: GenericArgsRef<'tcx>,
406    ) -> impl Iterator<Item = (Unnormalized<'tcx, Clause<'tcx>>, Span)>
407    + DoubleEndedIterator
408    + ExactSizeIterator
409    + Clone {
410        EarlyBinder::bind_iter(self.clauses).iter_instantiated_copied(tcx, args).map(|u| {
411            let (clause, span) = u.unzip();
412            (clause, span.skip_normalization())
413        })
414    }
415
416    pub fn instantiate_own_identity(
417        self,
418    ) -> impl Iterator<Item = (Unnormalized<'tcx, Clause<'tcx>>, Span)>
419    + DoubleEndedIterator
420    + ExactSizeIterator
421    + Clone {
422        EarlyBinder::bind_iter(self.clauses).iter_identity_copied().map(|u| {
423            let (clause, span) = u.unzip();
424            (clause, span.skip_normalization())
425        })
426    }
427
428    #[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("compiler/rustc_middle/src/ty/generics.rs"),
                                    ::tracing_core::__macro_support::Option::Some(428u32),
                                    ::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))]
429    fn instantiate_into(
430        self,
431        tcx: TyCtxt<'tcx>,
432        instantiated: &mut InstantiatedClauses<'tcx>,
433        args: GenericArgsRef<'tcx>,
434    ) {
435        if let Some(def_id) = self.parent {
436            tcx.clauses_of(def_id).instantiate_into(tcx, instantiated, args);
437        }
438        instantiated.clauses.extend(
439            self.clauses.iter().map(|(p, _)| EarlyBinder::bind(tcx, *p).instantiate(tcx, args)),
440        );
441        instantiated.spans.extend(self.clauses.iter().map(|(_, sp)| *sp));
442    }
443
444    pub fn instantiate_identity(self, tcx: TyCtxt<'tcx>) -> InstantiatedClauses<'tcx> {
445        let mut instantiated = InstantiatedClauses::empty();
446        self.instantiate_identity_into(tcx, &mut instantiated);
447        instantiated
448    }
449
450    fn instantiate_identity_into(
451        self,
452        tcx: TyCtxt<'tcx>,
453        instantiated: &mut InstantiatedClauses<'tcx>,
454    ) {
455        if let Some(def_id) = self.parent {
456            tcx.clauses_of(def_id).instantiate_identity_into(tcx, instantiated);
457        }
458        instantiated.clauses.extend(self.clauses.iter().map(|(p, _)| Unnormalized::new(*p)));
459        instantiated.spans.extend(self.clauses.iter().map(|(_, s)| s));
460    }
461
462    /// Allow simple where bounds like `T: Debug`, but prevent any kind of
463    /// outlives bounds or uses of generic parameters on the right hand side.
464    ///
465    /// We allow simple bounds because when the `T` actually gets substituted with a concrete type
466    /// during monomorphization, we will be checking its `Debug` impl for fully_generic_for_reflection.
467    ///
468    /// Constants (associated or generic) are irrelevant for this analysis, as their value is neither
469    /// affected by lifetimes, nor do they affect lifetimes.
470    pub fn is_fully_generic_for_reflection(self) -> bool {
471        struct ParamChecker;
472        impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ParamChecker {
473            type Result = ControlFlow<()>;
474            fn visit_region(&mut self, r: Region<'tcx>) -> Self::Result {
475                match r.kind() {
476                    RegionKind::ReEarlyParam(_) | RegionKind::ReStatic | RegionKind::ReError(_) => {
477                        ControlFlow::Break(())
478                    }
479                    RegionKind::ReVar(_)
480                    | RegionKind::RePlaceholder(_)
481                    | RegionKind::ReErased
482                    | RegionKind::ReLateParam(_) => {
483                        crate::util::bug::bug_fmt(format_args!("unexpected lifetime in impl: {0:?}",
        r))bug!("unexpected lifetime in impl: {r:?}")
484                    }
485                    RegionKind::ReBound(..) => ControlFlow::Continue(()),
486                }
487            }
488
489            fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
490                match t.kind() {
491                    TyKind::Param(_p) => {
492                        // Reject using parameters used in the type in where bounds
493                        return ControlFlow::Break(());
494                    }
495                    TyKind::Alias(..) => return ControlFlow::Break(()),
496                    _ => (),
497                }
498                t.super_visit_with(self)
499            }
500        }
501
502        // Pessimistic: if any of the parameters have where bounds
503        // don't allow this impl to be used.
504        self.clauses.iter().all(|(clause, _)| {
505            match clause.kind().skip_binder() {
506                ClauseKind::Trait(trait_predicate) => {
507                    // In a `T: Trait`, if the rhs bound does not contain any generic params
508                    // or 'static lifetimes, then it cannot transitively cause such requirements,
509                    // considering we apply the fully-generic-for-reflection rules to any impls for
510                    // that trait, too.
511                    if #[allow(non_exhaustive_omitted_patterns)] match trait_predicate.self_ty().kind()
    {
    ty::Param(_) => true,
    _ => false,
}matches!(trait_predicate.self_ty().kind(), ty::Param(_))
512                        && trait_predicate.trait_ref.args[1..]
513                            .iter()
514                            .all(|arg| arg.visit_with(&mut ParamChecker).is_continue())
515                    {
516                        return true;
517                    }
518                }
519                ClauseKind::RegionOutlives(_)
520                | ClauseKind::TypeOutlives(_)
521                | ClauseKind::Projection(_)
522                | ClauseKind::ConstArgHasType(_, _)
523                | ClauseKind::WellFormed(_)
524                | ClauseKind::ConstEvaluatable(_)
525                | ClauseKind::HostEffect(_)
526                | ClauseKind::UnstableFeature(_) => {}
527            }
528            clause.visit_with(&mut ParamChecker).is_continue()
529        })
530    }
531}
532
533/// `[const]` bounds for a given item. This is represented using a struct much like
534/// `GenericClauses`, where you can either choose to only instantiate the "own"
535/// bounds or all of the bounds including those from the parent. This distinction
536/// is necessary for code like `compare_method_predicate_entailment`.
537#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for ConstConditions<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for ConstConditions<'tcx> {
    #[inline]
    fn clone(&self) -> ConstConditions<'tcx> {
        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() -> ConstConditions<'tcx> {
        ConstConditions {
            parent: ::core::default::Default::default(),
            predicates: ::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, "predicates",
            &&self.predicates)
    }
}Debug, const _: () =
    {
        impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
            ::rustc_serialize::Encodable<__E> for ConstConditions<'tcx> {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    ConstConditions {
                        parent: ref __binding_0, predicates: __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 ConstConditions<'tcx> {
            fn decode(__decoder: &mut __D) -> Self {
                ConstConditions {
                    parent: ::rustc_serialize::Decodable::decode(__decoder),
                    predicates: ::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, predicates: ref __binding_1 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash)]
538pub struct ConstConditions<'tcx> {
539    pub parent: Option<DefId>,
540    pub predicates: &'tcx [(ty::PolyTraitRef<'tcx>, Span)],
541}
542
543impl<'tcx> ConstConditions<'tcx> {
544    pub fn instantiate(
545        self,
546        tcx: TyCtxt<'tcx>,
547        args: GenericArgsRef<'tcx>,
548    ) -> Vec<(Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>, Span)> {
549        let mut instantiated = ::alloc::vec::Vec::new()vec![];
550        self.instantiate_into(tcx, &mut instantiated, args);
551        instantiated
552    }
553
554    pub fn instantiate_own(
555        self,
556        tcx: TyCtxt<'tcx>,
557        args: GenericArgsRef<'tcx>,
558    ) -> impl Iterator<Item = (Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>, Span)>
559    + DoubleEndedIterator
560    + ExactSizeIterator
561    + Clone {
562        EarlyBinder::bind_iter(self.predicates).iter_instantiated_copied(tcx, args).map(|u| {
563            let (trait_ref, span) = u.unzip();
564            (trait_ref, span.skip_normalization())
565        })
566    }
567
568    pub fn instantiate_own_identity(
569        self,
570    ) -> impl Iterator<Item = (Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>, Span)>
571    + DoubleEndedIterator
572    + ExactSizeIterator
573    + Clone {
574        EarlyBinder::bind_iter(self.predicates).iter_identity_copied().map(|u| {
575            let (trait_ref, span) = u.unzip();
576            (trait_ref, span.skip_normalization())
577        })
578    }
579
580    #[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("compiler/rustc_middle/src/ty/generics.rs"),
                                    ::tracing_core::__macro_support::Option::Some(580u32),
                                    ::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.predicates.iter().map(|&(p, s)|
                        (EarlyBinder::bind(tcx, p).instantiate(tcx, args), s)));
        }
    }
}#[instrument(level = "debug", skip(self, tcx))]
581    fn instantiate_into(
582        self,
583        tcx: TyCtxt<'tcx>,
584        instantiated: &mut Vec<(Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>, Span)>,
585        args: GenericArgsRef<'tcx>,
586    ) {
587        if let Some(def_id) = self.parent {
588            tcx.const_conditions(def_id).instantiate_into(tcx, instantiated, args);
589        }
590        instantiated.extend(
591            self.predicates
592                .iter()
593                .map(|&(p, s)| (EarlyBinder::bind(tcx, p).instantiate(tcx, args), s)),
594        );
595    }
596
597    pub fn instantiate_identity(
598        self,
599        tcx: TyCtxt<'tcx>,
600    ) -> Vec<(Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>, Span)> {
601        let mut instantiated = ::alloc::vec::Vec::new()vec![];
602        self.instantiate_identity_into(tcx, &mut instantiated);
603        instantiated
604    }
605
606    fn instantiate_identity_into(
607        self,
608        tcx: TyCtxt<'tcx>,
609        instantiated: &mut Vec<(Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>, Span)>,
610    ) {
611        if let Some(def_id) = self.parent {
612            tcx.const_conditions(def_id).instantiate_identity_into(tcx, instantiated);
613        }
614        instantiated.extend(
615            self.predicates
616                .iter()
617                .copied()
618                .map(|(trait_ref, span)| (Unnormalized::new(trait_ref), span)),
619        );
620    }
621}