Skip to main content

rustc_hir_analysis/hir_ty_lowering/
mod.rs

1// ignore-tidy-file-filelength
2
3//! HIR ty lowering: Lowers type-system entities[^1] from the [HIR][hir] to
4//! the [`rustc_middle::ty`] representation.
5//!
6//! Not to be confused with *AST lowering* which lowers AST constructs to HIR ones
7//! or with *THIR* / *MIR* *lowering* / *building* which lowers HIR *bodies*
8//! (i.e., “executable code”) to THIR / MIR.
9//!
10//! Most lowering routines are defined on [`dyn HirTyLowerer`](HirTyLowerer) directly,
11//! like the main routine of this module, `lower_ty`.
12//!
13//! This module used to be called `astconv`.
14//!
15//! [^1]: This includes types, lifetimes / regions, constants in type positions,
16//! trait references and bounds.
17
18pub(crate) mod bounds;
19mod cmse;
20mod dyn_trait;
21pub mod errors;
22pub mod generics;
23
24use std::{assert_matches, slice};
25
26use rustc_abi::FIRST_VARIANT;
27use rustc_ast::LitKind;
28use rustc_attr_ir::lang_items::LangItem;
29use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
30use rustc_data_structures::sso::SsoHashSet;
31use rustc_data_structures::thin_vec::ThinVec;
32use rustc_errors::codes::*;
33use rustc_errors::{
34    Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed, FatalError, StashKey,
35    struct_span_code_err,
36};
37use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
38use rustc_hir::def_id::{DefId, LocalDefId};
39use rustc_hir::{self as hir, AnonConst, GenericArg, GenericArgs, HirId};
40use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
41use rustc_infer::traits::DynCompatibilityViolation;
42use rustc_lint_defs::builtin::AMBIGUOUS_ASSOCIATED_ITEMS;
43use rustc_macros::{TypeFoldable, TypeVisitable};
44use rustc_middle::middle::stability::AllowUnstable;
45use rustc_middle::ty::{
46    self, Const, FnSigKind, GenericArgKind, GenericParamDefKind, IncludeSizedImplicitBounds,
47    LitToConstInput, Ty, TyCtxt, TypeSuperFoldable, TypeVisitableExt, TypingMode, Unnormalized,
48    Upcast, const_lit_matches_ty, fold_regions,
49};
50use rustc_session::diagnostics::feature_err;
51use rustc_span::def_id::{LocalModId, ModId};
52use rustc_span::{DUMMY_SP, Ident, Span, bug, kw, span_bug, sym};
53use rustc_trait_selection::infer::InferCtxtExt;
54use rustc_trait_selection::traits::{self, FulfillmentError};
55use tracing::{debug, instrument};
56
57use crate::check::check_abi;
58use crate::check_c_variadic_abi;
59use crate::diagnostics::{self, BadReturnTypeNotation, NoFieldOnType, NoVariantNamed};
60use crate::hir_ty_lowering::errors::{
61    GenericsArgsErrExtend, eq_ctxt_suggestion_span, prohibit_assoc_item_constraint,
62};
63use crate::hir_ty_lowering::generics::{check_generic_arg_count, lower_generic_args};
64use crate::middle::resolve_bound_vars as rbv;
65
66/// The context in which an implied bound is being added to a item being lowered (i.e. a sizedness
67/// trait or a default trait)
68#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl<'tcx>
    ::core::clone::TrivialClone for ImpliedBoundsContext<'tcx> {
}
#[automatically_derived]impl<'tcx> ::core::clone::Clone for
    ImpliedBoundsContext<'tcx> {
    #[inline]
    #[rustc_trivial_field_reads]
    fn clone(&self) -> Self {
        let _: ::core::clone::AssertParamIsClone<LocalDefId>;
        let _:
                ::core::clone::AssertParamIsClone<&'tcx [hir::WherePredicate<'tcx>]>;
        *self
    }
}Clone, #[automatically_derived]impl<'tcx> ::core::marker::Copy for
    ImpliedBoundsContext<'tcx> {
}Copy)]
69pub(crate) enum ImpliedBoundsContext<'tcx> {
70    /// An implied bound is added to a trait definition (i.e. a new supertrait), used when adding
71    /// a default `MetaSized` supertrait
72    TraitDef(LocalDefId),
73    /// An implied bound is added to a type parameter
74    TyParam(LocalDefId, &'tcx [hir::WherePredicate<'tcx>]),
75    /// An implied bound being added in any other context
76    AssociatedTypeOrImplTrait,
77}
78
79/// A path segment that is semantically allowed to have generic arguments.
80#[derive(#[automatically_derived]impl ::core::fmt::Debug for GenericPathSegment {
    #[inline]
    #[rustc_trivial_field_reads]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f,
            "GenericPathSegment", &self.0, &&self.1)
    }
}Debug)]
81pub struct GenericPathSegment(pub DefId, pub usize);
82
83#[derive(#[automatically_derived]impl ::core::marker::Copy for PredicateFilter { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
    for PredicateFilter {
}
#[automatically_derived]impl ::core::clone::Clone for PredicateFilter {
    #[inline]
    #[rustc_trivial_field_reads]
    fn clone(&self) -> Self {
        let _: ::core::clone::AssertParamIsClone<Ident>;
        *self
    }
}Clone, #[automatically_derived]impl ::core::fmt::Debug for PredicateFilter {
    #[inline]
    #[rustc_trivial_field_reads]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Self::All => ::core::fmt::Formatter::write_str(f, "All"),
            Self::SelfOnly =>
                ::core::fmt::Formatter::write_str(f, "SelfOnly"),
            Self::SelfTraitThatDefines(__self_0) =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "SelfTraitThatDefines", &__self_0),
            Self::SelfAndAssociatedTypeBounds =>
                ::core::fmt::Formatter::write_str(f,
                    "SelfAndAssociatedTypeBounds"),
            Self::ConstIfConst =>
                ::core::fmt::Formatter::write_str(f, "ConstIfConst"),
            Self::SelfConstIfConst =>
                ::core::fmt::Formatter::write_str(f, "SelfConstIfConst"),
        }
    }
}Debug)]
84pub enum PredicateFilter {
85    /// All predicates may be implied by the trait.
86    All,
87
88    /// Only traits that reference `Self: ..` are implied by the trait.
89    SelfOnly,
90
91    /// Only traits that reference `Self: ..` and define an associated type
92    /// with the given ident are implied by the trait. This mode exists to
93    /// side-step query cycles when lowering associated types.
94    SelfTraitThatDefines(Ident),
95
96    /// Only traits that reference `Self: ..` and their associated type bounds.
97    /// For example, given `Self: Tr<A: B>`, this would expand to `Self: Tr`
98    /// and `<Self as Tr>::A: B`.
99    SelfAndAssociatedTypeBounds,
100
101    /// Filter only the `[const]` bounds, which are lowered into `HostEffect` clauses.
102    ConstIfConst,
103
104    /// Filter only the `[const]` bounds which are *also* in the supertrait position.
105    SelfConstIfConst,
106}
107
108#[derive(#[automatically_derived]impl<'a> ::core::fmt::Debug for RegionInferReason<'a>
    {
    #[inline]
    #[rustc_trivial_field_reads]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Self::ExplicitObjectLifetime =>
                ::core::fmt::Formatter::write_str(f,
                    "ExplicitObjectLifetime"),
            Self::ObjectLifetimeDefault(__self_0) =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "ObjectLifetimeDefault", &__self_0),
            Self::Param(__self_0) =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f, "Param",
                    &__self_0),
            Self::RegionPredicate =>
                ::core::fmt::Formatter::write_str(f, "RegionPredicate"),
            Self::Reference =>
                ::core::fmt::Formatter::write_str(f, "Reference"),
            Self::OutlivesBound =>
                ::core::fmt::Formatter::write_str(f, "OutlivesBound"),
        }
    }
}Debug)]
109pub enum RegionInferReason<'a> {
110    /// Lifetime on a trait object that is spelled explicitly, e.g. `+ 'a` or `+ '_`.
111    ExplicitObjectLifetime,
112    /// A trait object's lifetime when it is elided, e.g. `dyn Any`.
113    ObjectLifetimeDefault(Span),
114    /// Generic lifetime parameter
115    Param(&'a ty::GenericParamDef),
116    RegionPredicate,
117    Reference,
118    OutlivesBound,
119}
120
121#[derive(#[automatically_derived]impl ::core::marker::Copy for InherentAssocCandidate {
}Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
    for InherentAssocCandidate {
}
#[automatically_derived]impl ::core::clone::Clone for InherentAssocCandidate {
    #[inline]
    #[rustc_trivial_field_reads]
    fn clone(&self) -> Self {
        let _: ::core::clone::AssertParamIsClone<DefId>;
        let _: ::core::clone::AssertParamIsClone<ModId>;
        *self
    }
}Clone, const _: () =
    {
        impl<'tcx>
            ::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
            for InherentAssocCandidate {
            fn try_fold_with<__F: ::rustc_middle::ty::FallibleTypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
                __folder: &mut __F) -> Result<Self, __F::Error> {
                Ok(match self {
                        InherentAssocCandidate {
                            impl_: __binding_0,
                            assoc_item: __binding_1,
                            scope: __binding_2 } => {
                            InherentAssocCandidate {
                                impl_: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
                                        __folder)?,
                                assoc_item: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
                                        __folder)?,
                                scope: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_2,
                                        __folder)?,
                            }
                        }
                    })
            }
            fn fold_with<__F: ::rustc_middle::ty::TypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
                __folder: &mut __F) -> Self {
                match self {
                    InherentAssocCandidate {
                        impl_: __binding_0,
                        assoc_item: __binding_1,
                        scope: __binding_2 } => {
                        InherentAssocCandidate {
                            impl_: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
                                __folder),
                            assoc_item: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
                                __folder),
                            scope: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_2,
                                __folder),
                        }
                    }
                }
            }
        }
    };TypeFoldable, const _: () =
    {
        impl<'tcx>
            ::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
            for InherentAssocCandidate {
            fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
                __visitor: &mut __V) -> __V::Result {
                match *self {
                    InherentAssocCandidate {
                        impl_: ref __binding_0,
                        assoc_item: ref __binding_1,
                        scope: ref __binding_2 } => {
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                        {
                            match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_2,
                                        __visitor)) {
                                ::core::ops::ControlFlow::Continue(()) => {}
                                ::core::ops::ControlFlow::Break(r) => {
                                    return ::rustc_middle::ty::VisitorResult::from_residual(r);
                                }
                            }
                        }
                    }
                }
                <__V::Result as ::rustc_middle::ty::VisitorResult>::output()
            }
        }
    };TypeVisitable, #[automatically_derived]impl ::core::fmt::Debug for InherentAssocCandidate {
    #[inline]
    #[rustc_trivial_field_reads]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field3_finish(f,
            "InherentAssocCandidate impl_ assoc_item scope", &self.impl_,
            &self.assoc_item, &&self.scope)
    }
}Debug)]
122pub struct InherentAssocCandidate {
123    pub impl_: DefId,
124    pub assoc_item: DefId,
125    pub scope: ModId,
126}
127
128pub struct ResolvedStructPath<'tcx> {
129    pub res: Result<Res, ErrorGuaranteed>,
130    pub ty: Ty<'tcx>,
131}
132
133/// A context which can lower type-system entities from the [HIR][hir] to
134/// the [`rustc_middle::ty`] representation.
135///
136/// This trait used to be called `AstConv`.
137pub trait HirTyLowerer<'tcx> {
138    fn tcx(&self) -> TyCtxt<'tcx>;
139
140    fn dcx(&self) -> DiagCtxtHandle<'_>;
141
142    /// Returns the [`LocalDefId`] of the overarching item whose constituents get lowered.
143    fn item_def_id(&self) -> LocalDefId;
144
145    /// Returns the containing module.
146    fn mod_id(&self) -> LocalModId;
147
148    /// Returns the region to use when a lifetime is omitted (and not elided).
149    fn re_infer(&self, span: Span, reason: RegionInferReason<'_>) -> ty::Region<'tcx>;
150
151    /// Returns the type to use when a type is omitted.
152    fn ty_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx>;
153
154    /// Returns the const to use when a const is omitted.
155    fn ct_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Const<'tcx>;
156
157    fn register_trait_ascription_bounds(
158        &self,
159        bounds: Vec<(ty::Clause<'tcx>, Span)>,
160        hir_id: HirId,
161        span: Span,
162    );
163
164    /// Probe bounds in scope where the bounded type coincides with the given type parameter.
165    ///
166    /// Rephrased, this returns bounds of the form `T: Trait`, where `T` is a type parameter
167    /// with the given `def_id`. This is a subset of the full set of bounds.
168    ///
169    /// This method may use the given `assoc_name` to disregard bounds whose trait reference
170    /// doesn't define an associated item with the provided name.
171    ///
172    /// This is used for one specific purpose: Resolving “short-hand” associated type references
173    /// like `T::Item` where `T` is a type parameter. In principle, we would do that by first
174    /// getting the full set of predicates in scope and then filtering down to find those that
175    /// apply to `T`, but this can lead to cycle errors. The problem is that we have to do this
176    /// resolution *in order to create the predicates in the first place*.
177    /// Hence, we have this “special pass”.
178    fn probe_ty_param_bounds(
179        &self,
180        span: Span,
181        def_id: LocalDefId,
182        assoc_ident: Ident,
183    ) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]>;
184
185    fn select_inherent_assoc_candidates(
186        &self,
187        span: Span,
188        self_ty: Ty<'tcx>,
189        candidates: Vec<InherentAssocCandidate>,
190    ) -> (Vec<InherentAssocCandidate>, ThinVec<FulfillmentError<'tcx>>);
191
192    /// Lower a path to an associated item (of a trait) to a projection.
193    ///
194    /// This method has to be defined by the concrete lowering context because
195    /// dealing with higher-ranked trait references depends on its capabilities:
196    ///
197    /// If the context can make use of type inference, it can simply instantiate
198    /// any late-bound vars bound by the trait reference with inference variables.
199    /// If it doesn't support type inference, there is nothing reasonable it can
200    /// do except reject the associated type.
201    ///
202    /// The canonical example of this is associated type `T::P` where `T` is a type
203    /// param constrained by `T: for<'a> Trait<'a>` and where `Trait` defines `P`.
204    fn lower_assoc_item_path(
205        &self,
206        span: Span,
207        item_def_id: DefId,
208        item_segment: &hir::PathSegment<'_>,
209        poly_trait_ref: ty::PolyTraitRef<'tcx>,
210    ) -> Result<(DefId, ty::GenericArgs<'tcx>), ErrorGuaranteed>;
211
212    fn lower_fn_sig(
213        &self,
214        decl: &hir::FnDecl<'_>,
215        generics: Option<&hir::Generics<'_>>,
216        hir_id: HirId,
217        hir_ty: Option<&hir::Ty<'_>>,
218    ) -> (Vec<Ty<'tcx>>, Ty<'tcx>);
219
220    /// Returns `AdtDef` if `ty` is an ADT.
221    ///
222    /// Note that `ty` might be a alias type that needs normalization.
223    /// This used to get the enum variants in scope of the type.
224    /// For example, `Self::A` could refer to an associated type
225    /// or to an enum variant depending on the result of this function.
226    fn probe_adt(&self, span: Span, ty: Ty<'tcx>) -> Option<ty::AdtDef<'tcx>>;
227
228    /// Record the lowered type of a HIR node in this context.
229    fn record_ty(&self, hir_id: HirId, ty: Ty<'tcx>, span: Span);
230
231    /// The inference context of the lowering context if applicable.
232    fn infcx(&self) -> Option<&InferCtxt<'tcx>>;
233
234    /// Convenience method for coercing the lowering context into a trait object type.
235    ///
236    /// Most lowering routines are defined on the trait object type directly
237    /// necessitating a coercion step from the concrete lowering context.
238    fn lowerer(&self) -> &dyn HirTyLowerer<'tcx>
239    where
240        Self: Sized,
241    {
242        self
243    }
244
245    /// Performs minimalistic dyn compat checks outside of bodies, but full within bodies.
246    /// Outside of bodies we could end up in cycles, so we delay most checks to later phases.
247    fn dyn_compatibility_violations(&self, trait_def_id: DefId) -> Vec<DynCompatibilityViolation>;
248}
249
250/// The "qualified self" of an associated item path.
251///
252/// For diagnostic purposes only.
253enum AssocItemQSelf {
254    Trait(DefId),
255    TyParam(LocalDefId, Span),
256    SelfTyAlias,
257}
258
259impl AssocItemQSelf {
260    fn to_string(&self, tcx: TyCtxt<'_>) -> String {
261        match *self {
262            Self::Trait(def_id) => tcx.def_path_str(def_id),
263            Self::TyParam(def_id, _) => tcx.hir_ty_param_name(def_id).to_string(),
264            Self::SelfTyAlias => kw::SelfUpper.to_string(),
265        }
266    }
267}
268
269#[derive(#[automatically_derived]impl ::core::fmt::Debug for LowerTypeRelativePathMode
    {
    #[inline]
    #[rustc_trivial_field_reads]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Self::Type(__self_0) =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f, "Type",
                    &__self_0),
            Self::Const => ::core::fmt::Formatter::write_str(f, "Const"),
        }
    }
}Debug, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
    for LowerTypeRelativePathMode {
}
#[automatically_derived]impl ::core::clone::Clone for
    LowerTypeRelativePathMode {
    #[inline]
    #[rustc_trivial_field_reads]
    fn clone(&self) -> Self {
        let _: ::core::clone::AssertParamIsClone<PermitVariants>;
        *self
    }
}Clone, #[automatically_derived]impl ::core::marker::Copy for
    LowerTypeRelativePathMode {
}Copy)]
270enum LowerTypeRelativePathMode {
271    Type(PermitVariants),
272    Const,
273}
274
275impl LowerTypeRelativePathMode {
276    fn assoc_tag(self) -> ty::AssocTag {
277        match self {
278            Self::Type(_) => ty::AssocTag::Type,
279            Self::Const => ty::AssocTag::Const,
280        }
281    }
282
283    ///NOTE: use `assoc_tag` for any important logic
284    fn def_kind_for_diagnostics(self) -> DefKind {
285        match self {
286            Self::Type(_) => DefKind::AssocTy,
287            Self::Const => DefKind::AssocConst,
288        }
289    }
290
291    fn permit_variants(self) -> PermitVariants {
292        match self {
293            Self::Type(permit_variants) => permit_variants,
294            // FIXME(mgca): Support paths like `Option::<T>::None` or `Option::<T>::Some` which
295            // resolve to const ctors/fn items respectively.
296            Self::Const => PermitVariants::No,
297        }
298    }
299}
300
301/// Whether to permit a path to resolve to an enum variant.
302#[derive(#[automatically_derived]impl ::core::fmt::Debug for PermitVariants {
    #[inline]
    #[rustc_trivial_field_reads]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                PermitVariants::Yes => "Yes",
                PermitVariants::No => "No",
            })
    }
}Debug, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
    for PermitVariants {
}
#[automatically_derived]impl ::core::clone::Clone for PermitVariants {
    #[inline]
    #[rustc_trivial_field_reads]
    fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for PermitVariants { }Copy)]
303pub enum PermitVariants {
304    Yes,
305    No,
306}
307
308#[derive(#[automatically_derived]impl<'tcx> ::core::fmt::Debug for
    TypeRelativePath<'tcx> {
    #[inline]
    #[rustc_trivial_field_reads]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Self::AssocItem(__self_0) =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "AssocItem", &__self_0),
            Self::Variant { adt: __self_0, variant_did: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f,
                    "Variant adt variant_did", __self_0, &__self_1),
            Self::Ctor { ctor_def_id: __self_0, args: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f,
                    "Ctor ctor_def_id args", __self_0, &__self_1),
        }
    }
}Debug, #[automatically_derived]#[doc(hidden)]unsafe impl<'tcx>
    ::core::clone::TrivialClone for TypeRelativePath<'tcx> {
}
#[automatically_derived]impl<'tcx> ::core::clone::Clone for
    TypeRelativePath<'tcx> {
    #[inline]
    #[rustc_trivial_field_reads]
    fn clone(&self) -> Self {
        let _: ::core::clone::AssertParamIsClone<ty::AliasTerm<'tcx>>;
        let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
        let _: ::core::clone::AssertParamIsClone<DefId>;
        let _: ::core::clone::AssertParamIsClone<ty::GenericArgs<'tcx>>;
        *self
    }
}Clone, #[automatically_derived]impl<'tcx> ::core::marker::Copy for
    TypeRelativePath<'tcx> {
}Copy)]
309enum TypeRelativePath<'tcx> {
310    AssocItem(ty::AliasTerm<'tcx>),
311    Variant { adt: Ty<'tcx>, variant_did: DefId },
312    Ctor { ctor_def_id: DefId, args: ty::GenericArgs<'tcx> },
313}
314
315/// New-typed boolean indicating whether explicit late-bound lifetimes
316/// are present in a set of generic arguments.
317///
318/// For example if we have some method `fn f<'a>(&'a self)` implemented
319/// for some type `T`, although `f` is generic in the lifetime `'a`, `'a`
320/// is late-bound so should not be provided explicitly. Thus, if `f` is
321/// instantiated with some generic arguments providing `'a` explicitly,
322/// we taint those arguments with `ExplicitLateBound::Yes` so that we
323/// can provide an appropriate diagnostic later.
324#[derive(#[automatically_derived]impl ::core::marker::Copy for ExplicitLateBound { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
    for ExplicitLateBound {
}
#[automatically_derived]impl ::core::clone::Clone for ExplicitLateBound {
    #[inline]
    #[rustc_trivial_field_reads]
    fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
    ExplicitLateBound {
}
#[automatically_derived]impl ::core::cmp::PartialEq for ExplicitLateBound {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        ::core::intrinsics::discriminant_value(self) ==
            ::core::intrinsics::discriminant_value(other)
    }
}PartialEq, #[automatically_derived]impl ::core::fmt::Debug for ExplicitLateBound {
    #[inline]
    #[rustc_trivial_field_reads]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                ExplicitLateBound::Yes => "Yes",
                ExplicitLateBound::No => "No",
            })
    }
}Debug)]
325pub enum ExplicitLateBound {
326    Yes,
327    No,
328}
329
330#[derive(#[automatically_derived]impl ::core::fmt::Debug for IsMethodCall {
    #[inline]
    #[rustc_trivial_field_reads]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                IsMethodCall::Yes => "Yes",
                IsMethodCall::No => "No",
            })
    }
}Debug, #[automatically_derived]impl ::core::marker::Copy for IsMethodCall { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
    for IsMethodCall {
}
#[automatically_derived]impl ::core::clone::Clone for IsMethodCall {
    #[inline]
    #[rustc_trivial_field_reads]
    fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
    IsMethodCall {
}
#[automatically_derived]impl ::core::cmp::PartialEq for IsMethodCall {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        ::core::intrinsics::discriminant_value(self) ==
            ::core::intrinsics::discriminant_value(other)
    }
}PartialEq)]
331pub enum IsMethodCall {
332    Yes,
333    No,
334}
335
336/// Denotes the "position" of a generic argument, indicating if it is a generic type,
337/// generic function or generic method call.
338#[derive(#[automatically_derived]impl ::core::fmt::Debug for GenericArgPosition {
    #[inline]
    #[rustc_trivial_field_reads]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Self::Type => ::core::fmt::Formatter::write_str(f, "Type"),
            Self::Value(__self_0) =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f, "Value",
                    &__self_0),
        }
    }
}Debug, #[automatically_derived]impl ::core::marker::Copy for GenericArgPosition { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
    for GenericArgPosition {
}
#[automatically_derived]impl ::core::clone::Clone for GenericArgPosition {
    #[inline]
    #[rustc_trivial_field_reads]
    fn clone(&self) -> Self {
        let _: ::core::clone::AssertParamIsClone<IsMethodCall>;
        *self
    }
}Clone, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
    GenericArgPosition {
}
#[automatically_derived]impl ::core::cmp::PartialEq for GenericArgPosition {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        ::core::intrinsics::discriminant_value(self) ==
                ::core::intrinsics::discriminant_value(other) &&
            match (self, other) {
                (Self::Value(__self_0), Self::Value(__arg1_0)) =>
                    __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq)]
339pub(crate) enum GenericArgPosition {
340    Type,
341    Value(IsMethodCall),
342}
343
344/// Whether to allow duplicate associated iten constraints in a trait ref, e.g.
345/// `Trait<Assoc = Ty, Assoc = Ty>`. This is forbidden in `dyn Trait<...>`
346/// but allowed everywhere else.
347#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
    for OverlappingAsssocItemConstraints {
}
#[automatically_derived]impl ::core::clone::Clone for
    OverlappingAsssocItemConstraints {
    #[inline]
    #[rustc_trivial_field_reads]
    fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for
    OverlappingAsssocItemConstraints {
}Copy, #[automatically_derived]impl ::core::fmt::Debug for
    OverlappingAsssocItemConstraints {
    #[inline]
    #[rustc_trivial_field_reads]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                OverlappingAsssocItemConstraints::Allowed => "Allowed",
                OverlappingAsssocItemConstraints::Forbidden => "Forbidden",
            })
    }
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
    OverlappingAsssocItemConstraints {
}
#[automatically_derived]impl ::core::cmp::PartialEq for
    OverlappingAsssocItemConstraints {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        ::core::intrinsics::discriminant_value(self) ==
            ::core::intrinsics::discriminant_value(other)
    }
}PartialEq)]
348pub(crate) enum OverlappingAsssocItemConstraints {
349    Allowed,
350    Forbidden,
351}
352
353/// A marker denoting that the generic arguments that were
354/// provided did not match the respective generic parameters.
355#[derive(#[automatically_derived]impl ::core::clone::Clone for GenericArgCountMismatch
    {
    #[inline]
    #[rustc_trivial_field_reads]
    fn clone(&self) -> Self {
        GenericArgCountMismatch {
            reported: ::core::clone::Clone::clone(&self.reported),
            invalid_args: ::core::clone::Clone::clone(&self.invalid_args),
        }
    }
}Clone, #[automatically_derived]impl ::core::fmt::Debug for GenericArgCountMismatch {
    #[inline]
    #[rustc_trivial_field_reads]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f,
            "GenericArgCountMismatch reported invalid_args", &self.reported,
            &&self.invalid_args)
    }
}Debug)]
356pub struct GenericArgCountMismatch {
357    pub reported: ErrorGuaranteed,
358    /// A list of indices of arguments provided that were not valid.
359    pub invalid_args: Vec<usize>,
360}
361
362/// Decorates the result of a generic argument count mismatch
363/// check with whether explicit late bounds were provided.
364#[derive(#[automatically_derived]impl ::core::clone::Clone for GenericArgCountResult {
    #[inline]
    #[rustc_trivial_field_reads]
    fn clone(&self) -> Self {
        GenericArgCountResult {
            explicit_late_bound: ::core::clone::Clone::clone(&self.explicit_late_bound),
            correct: ::core::clone::Clone::clone(&self.correct),
        }
    }
}Clone, #[automatically_derived]impl ::core::fmt::Debug for GenericArgCountResult {
    #[inline]
    #[rustc_trivial_field_reads]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f,
            "GenericArgCountResult explicit_late_bound correct",
            &self.explicit_late_bound, &&self.correct)
    }
}Debug)]
365pub struct GenericArgCountResult {
366    pub explicit_late_bound: ExplicitLateBound,
367    pub correct: Result<(), GenericArgCountMismatch>,
368}
369
370/// A context which can lower HIR's [`GenericArg`] to `rustc_middle`'s [`ty::GenericArg`].
371///
372/// Its only consumer is [`generics::lower_generic_args`].
373/// Read its documentation to learn more.
374pub trait GenericArgsLowerer<'a, 'tcx> {
375    fn args_for_def_id(&mut self, def_id: DefId) -> (Option<&'a GenericArgs<'a>>, bool);
376
377    fn provided_kind(
378        &mut self,
379        preceding_args: &[ty::GenericArg<'tcx>],
380        param: &ty::GenericParamDef,
381        arg: &GenericArg<'_>,
382    ) -> ty::GenericArg<'tcx>;
383
384    fn inferred_kind(
385        &mut self,
386        preceding_args: &[ty::GenericArg<'tcx>],
387        param: &ty::GenericParamDef,
388        infer_args: bool,
389    ) -> ty::GenericArg<'tcx>;
390}
391
392/// Context in which `ForbidParamUsesFolder` is being used, to emit appropriate diagnostics.
393enum ForbidParamContext {
394    /// Anon const in a const argument position.
395    ConstArgument,
396    /// Enum discriminant expression.
397    EnumDiscriminant,
398}
399
400struct ForbidParamUsesFolder<'tcx> {
401    tcx: TyCtxt<'tcx>,
402    anon_const_def_id: LocalDefId,
403    span: Span,
404    is_self_alias: bool,
405    context: ForbidParamContext,
406}
407
408impl<'tcx> ForbidParamUsesFolder<'tcx> {
409    fn error(&self) -> ErrorGuaranteed {
410        let msg = match self.context {
411            ForbidParamContext::EnumDiscriminant if self.is_self_alias => {
412                "generic `Self` types are not permitted in enum discriminant values"
413            }
414            ForbidParamContext::EnumDiscriminant => {
415                "generic parameters may not be used in enum discriminant values"
416            }
417            ForbidParamContext::ConstArgument if self.is_self_alias => {
418                "generic `Self` types are currently not permitted in anonymous constants"
419            }
420            ForbidParamContext::ConstArgument => {
421                if self.tcx.features().gca_const_items() {
422                    "generic parameters in const blocks are not allowed; use a named `const` item instead"
423                } else {
424                    "generic parameters may not be used in const operations"
425                }
426            }
427        };
428        let mut diag = self.tcx.dcx().struct_span_err(self.span, msg);
429        if self.is_self_alias && #[allow(non_exhaustive_omitted_patterns)] match self.context {
    ForbidParamContext::ConstArgument => true,
    _ => false,
}matches!(self.context, ForbidParamContext::ConstArgument) {
430            let anon_const_hir_id: HirId = HirId::make_owner(self.anon_const_def_id);
431            let parent_impl = self.tcx.hir_parent_owner_iter(anon_const_hir_id).find_map(
432                |(_, node)| match node {
433                    hir::OwnerNode::Item(hir::Item {
434                        kind: hir::ItemKind::Impl(impl_), ..
435                    }) => Some(impl_),
436                    _ => None,
437                },
438            );
439            if let Some(impl_) = parent_impl {
440                diag.span_note(impl_.self_ty.span, "not a concrete type");
441            }
442        }
443        if #[allow(non_exhaustive_omitted_patterns)] match self.context {
    ForbidParamContext::ConstArgument => true,
    _ => false,
}matches!(self.context, ForbidParamContext::ConstArgument) {
444            if self.tcx.features().gca_const_items() {
445                diag.help("consider wrapping the expression in the `gca!` macro");
446            } else if self.tcx.features().gca_min_const_items() {
447                diag.help("add `#![feature(gca_const_items)]` and wrap the expression in the `gca!` macro");
448            } else if self.tcx.sess.is_nightly_build() {
449                diag.help(
450                    "add `#![feature(generic_const_exprs)]` to allow generic const expressions",
451                );
452                diag.help("alternatively, you can use `#![feature(gca_const_items)]` and wrap the expression in the `gca!` macro");
453            }
454        }
455        diag.emit_err()
456    }
457}
458
459impl<'tcx> ty::TypeFolder<TyCtxt<'tcx>> for ForbidParamUsesFolder<'tcx> {
460    fn cx(&self) -> TyCtxt<'tcx> {
461        self.tcx
462    }
463
464    fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
465        if #[allow(non_exhaustive_omitted_patterns)] match t.kind() {
    ty::Param(..) => true,
    _ => false,
}matches!(t.kind(), ty::Param(..)) {
466            return Ty::new_error(self.tcx, self.error());
467        }
468        t.super_fold_with(self)
469    }
470
471    fn fold_const(&mut self, c: Const<'tcx>) -> Const<'tcx> {
472        if #[allow(non_exhaustive_omitted_patterns)] match c.kind() {
    ty::ConstKind::Param(..) => true,
    _ => false,
}matches!(c.kind(), ty::ConstKind::Param(..)) {
473            return Const::new_error(self.tcx, self.error());
474        }
475        c.super_fold_with(self)
476    }
477
478    fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
479        if #[allow(non_exhaustive_omitted_patterns)] match r.kind() {
    ty::RegionKind::ReEarlyParam(..) | ty::RegionKind::ReLateParam(..) =>
        true,
    _ => false,
}matches!(r.kind(), ty::RegionKind::ReEarlyParam(..) | ty::RegionKind::ReLateParam(..)) {
480            return ty::Region::new_error(self.tcx, self.error());
481        }
482        r
483    }
484}
485
486impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
487    /// See `check_param_uses_if_mcg`.
488    ///
489    /// FIXME(mgca): this is pub only for instantiate_value_path and would be nice to avoid altogether
490    pub fn check_param_res_if_mcg_for_instantiate_value_path(
491        &self,
492        res: Res,
493        span: Span,
494    ) -> Result<(), ErrorGuaranteed> {
495        let tcx = self.tcx();
496        let parent_def_id = self.item_def_id();
497        // In this path, `Some(context)` should be `ConstArgument`: enum
498        // discriminants are handled earlier by resolve. We still use the helper so
499        // nested inline consts are checked in the outer const-argument context.
500        if let Res::Def(DefKind::ConstParam, _) = res
501            && let Some(context) = self.anon_const_forbids_generic_params()
502        {
503            let folder = ForbidParamUsesFolder {
504                tcx,
505                anon_const_def_id: parent_def_id,
506                span,
507                is_self_alias: false,
508                context,
509            };
510            return Err(folder.error());
511        }
512        Ok(())
513    }
514
515    /// Returns the `ForbidParamContext` for the current anon const if it is a context that
516    /// forbids uses of generic parameters. `None` if the current item is not such a context.
517    ///
518    /// Name resolution handles most invalid generic parameter uses in these contexts, but it
519    /// cannot reject `Self` that aliases a generic type, nor generic parameters introduced by
520    /// type-dependent name resolution (e.g. `<Self as Trait>::Assoc` resolving to a type that
521    /// contains params). Those cases are handled by `check_param_uses_if_mcg`.
522    fn anon_const_forbids_generic_params(&self) -> Option<ForbidParamContext> {
523        let tcx = self.tcx();
524        let item_def_id = self.item_def_id();
525
526        // Inline consts and closures can be nested inside anon consts that forbid generic
527        // params (e.g. an enum discriminant). Walk up the def parent chain to find the
528        // nearest enclosing AnonConst and use that to determine the context.
529        let anon_const_def_id = tcx.typeck_root_def_id_local(item_def_id);
530
531        if tcx.def_kind(anon_const_def_id) != DefKind::AnonConst {
532            return None;
533        }
534
535        match tcx.anon_const_kind(anon_const_def_id) {
536            ty::AnonConstKind::MCG => Some(ForbidParamContext::ConstArgument),
537            ty::AnonConstKind::NonTypeSystemAnon => {
538                // NonTypeSystem anon consts only have accessible generic parameters in specific
539                // positions (ty patterns and field defaults — see `generics_of`). In all other
540                // positions (e.g. enum discriminants) generic parameters are not in scope.
541                if tcx.generics_of(anon_const_def_id).count() == 0 {
542                    Some(ForbidParamContext::EnumDiscriminant)
543                } else {
544                    None
545                }
546            }
547            ty::AnonConstKind::NonTypeSystemInline
548            | ty::AnonConstKind::GCE
549            | ty::AnonConstKind::RepeatExprCount => None,
550        }
551    }
552
553    /// Check for uses of generic parameters that are not in scope due to this being
554    /// in a non-generic anon const context (e.g. MCG or an enum discriminant).
555    ///
556    /// Name resolution rejects most invalid uses, but cannot handle `Self` aliasing a
557    /// generic type or generic parameters introduced by type-dependent name resolution.
558    #[must_use = "need to use transformed output"]
559    fn check_param_uses_if_mcg<T>(&self, term: T, span: Span, is_self_alias: bool) -> T
560    where
561        T: ty::TypeFoldable<TyCtxt<'tcx>>,
562    {
563        let tcx = self.tcx();
564        if let Some(context) = self.anon_const_forbids_generic_params()
565            // Fast path if contains no params/escaping bound vars.
566            && (term.has_param() || term.has_escaping_bound_vars())
567        {
568            let anon_const_def_id = self.item_def_id();
569            let mut folder =
570                ForbidParamUsesFolder { tcx, anon_const_def_id, span, is_self_alias, context };
571            term.fold_with(&mut folder)
572        } else {
573            term
574        }
575    }
576
577    /// Lower a lifetime from the HIR to our internal notion of a lifetime called a *region*.
578    {}
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("lower_lifetime",
                                "rustc_hir_analysis::hir_ty_lowering",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                ::tracing_core::__macro_support::Option::Some(578u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("lifetime")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("lifetime");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("reason")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("reason");
                                                    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(&lifetime)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&reason)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[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: ty::Region<'tcx> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        if let Some(resolved) =
                                self.tcx().named_bound_var(lifetime.hir_id) {
                            let region = self.lower_resolved_lifetime(resolved);
                            self.check_param_uses_if_mcg(region, lifetime.ident.span,
                                false)
                        } else { self.re_infer(lifetime.ident.span, reason) }
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:578",
                        "rustc_hir_analysis::hir_ty_lowering",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(578u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
579    pub fn lower_lifetime(
580        &self,
581        lifetime: &hir::Lifetime,
582        reason: RegionInferReason<'_>,
583    ) -> ty::Region<'tcx> {
584        if let Some(resolved) = self.tcx().named_bound_var(lifetime.hir_id) {
585            let region = self.lower_resolved_lifetime(resolved);
586            self.check_param_uses_if_mcg(region, lifetime.ident.span, false)
587        } else {
588            self.re_infer(lifetime.ident.span, reason)
589        }
590    }
591
592    /// Lower a lifetime from the HIR to our internal notion of a lifetime called a *region*.
593    {}
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("lower_resolved_lifetime",
                                "rustc_hir_analysis::hir_ty_lowering",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                ::tracing_core::__macro_support::Option::Some(593u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("resolved")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("resolved");
                                                    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(&resolved)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[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: ty::Region<'tcx> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        let tcx = self.tcx();
                        match resolved {
                            rbv::ResolvedArg::StaticLifetime => tcx.lifetimes.re_static,
                            rbv::ResolvedArg::LateBound(debruijn, index, def_id) => {
                                let br =
                                    ty::BoundRegion {
                                        var: ty::BoundVar::from_u32(index),
                                        kind: ty::BoundRegionKind::Named(def_id.to_def_id()),
                                    };
                                ty::Region::new_bound(tcx, debruijn, br)
                            }
                            rbv::ResolvedArg::EarlyBound(def_id) => {
                                let name = tcx.hir_ty_param_name(def_id);
                                let item_def_id = tcx.hir_ty_param_owner(def_id);
                                let generics = tcx.generics_of(item_def_id);
                                let index =
                                    generics.param_def_id_to_index[&def_id.to_def_id()];
                                ty::Region::new_early_param(tcx,
                                    ty::EarlyParamRegion { index, name })
                            }
                            rbv::ResolvedArg::Free(scope, id) => {
                                ty::Region::new_late_param(tcx, scope.to_def_id(),
                                    ty::LateParamRegionKind::Named(id.to_def_id()))
                            }
                            rbv::ResolvedArg::Error(guar) =>
                                ty::Region::new_error(tcx, guar),
                        }
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:593",
                        "rustc_hir_analysis::hir_ty_lowering",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(593u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
594    fn lower_resolved_lifetime(&self, resolved: rbv::ResolvedArg) -> ty::Region<'tcx> {
595        let tcx = self.tcx();
596
597        match resolved {
598            rbv::ResolvedArg::StaticLifetime => tcx.lifetimes.re_static,
599
600            rbv::ResolvedArg::LateBound(debruijn, index, def_id) => {
601                let br = ty::BoundRegion {
602                    var: ty::BoundVar::from_u32(index),
603                    kind: ty::BoundRegionKind::Named(def_id.to_def_id()),
604                };
605                ty::Region::new_bound(tcx, debruijn, br)
606            }
607
608            rbv::ResolvedArg::EarlyBound(def_id) => {
609                let name = tcx.hir_ty_param_name(def_id);
610                let item_def_id = tcx.hir_ty_param_owner(def_id);
611                let generics = tcx.generics_of(item_def_id);
612                let index = generics.param_def_id_to_index[&def_id.to_def_id()];
613                ty::Region::new_early_param(tcx, ty::EarlyParamRegion { index, name })
614            }
615
616            rbv::ResolvedArg::Free(scope, id) => {
617                ty::Region::new_late_param(
618                    tcx,
619                    scope.to_def_id(),
620                    ty::LateParamRegionKind::Named(id.to_def_id()),
621                )
622
623                // (*) -- not late-bound, won't change
624            }
625
626            rbv::ResolvedArg::Error(guar) => ty::Region::new_error(tcx, guar),
627        }
628    }
629
630    pub fn lower_generic_args_of_path_segment(
631        &self,
632        span: Span,
633        def_id: DefId,
634        item_segment: &hir::PathSegment<'_>,
635    ) -> ty::GenericArgs<'tcx> {
636        let (args, _) = self.lower_generic_args_of_path(span, def_id, &[], item_segment, None);
637        if let Some(c) = item_segment.args().constraints.first() {
638            prohibit_assoc_item_constraint(self, c, Some((def_id, item_segment, span)));
639        }
640        args
641    }
642
643    /// Lower the generic arguments provided to some path.
644    ///
645    /// If this is a trait reference, you also need to pass the self type `self_ty`.
646    /// The lowering process may involve applying defaulted type parameters.
647    ///
648    /// Associated item constraints are not handled here! They are either lowered via
649    /// `lower_assoc_item_constraint` or rejected via `prohibit_assoc_item_constraint`.
650    ///
651    /// ### Example
652    ///
653    /// ```ignore (illustrative)
654    ///    T: std::ops::Index<usize, Output = u32>
655    /// // ^1 ^^^^^^^^^^^^^^2 ^^^^3  ^^^^^^^^^^^4
656    /// ```
657    ///
658    /// 1. The `self_ty` here would refer to the type `T`.
659    /// 2. The path in question is the path to the trait `std::ops::Index`,
660    ///    which will have been resolved to a `def_id`
661    /// 3. The `generic_args` contains info on the `<...>` contents. The `usize` type
662    ///    parameters are returned in the `GenericArgs`
663    /// 4. Associated item constraints like `Output = u32` are contained in `generic_args.constraints`.
664    ///
665    /// Note that the type listing given here is *exactly* what the user provided.
666    ///
667    /// For (generic) associated types
668    ///
669    /// ```ignore (illustrative)
670    /// <Vec<u8> as Iterable<u8>>::Iter::<'a>
671    /// ```
672    ///
673    /// We have the parent args are the args for the parent trait:
674    /// `[Vec<u8>, u8]` and `generic_args` are the arguments for the associated
675    /// type itself: `['a]`. The returned `GenericArgs` concatenates these two
676    /// lists: `[Vec<u8>, u8, 'a]`.
677    {}
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("lower_generic_args_of_path",
                                "rustc_hir_analysis::hir_ty_lowering",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                ::tracing_core::__macro_support::Option::Some(677u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("def_id")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("def_id");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("parent_args")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("parent_args");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("segment")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("segment");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("self_ty")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("self_ty");
                                                    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(&def_id)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&parent_args)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&segment)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[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:
                                (ty::GenericArgs<'tcx>, GenericArgCountResult) = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        let tcx = self.tcx();
                        let generics = tcx.generics_of(def_id);
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:692",
                                                "rustc_hir_analysis::hir_ty_lowering",
                                                ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                                ::tracing_core::__macro_support::Option::Some(692u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("generics")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("generics");
                                                                    NAME.as_str()
                                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                ::tracing::metadata::Kind::EVENT)
                                        };
                                    ::tracing::callsite::DefaultCallsite::new(&META)
                                };
                            let enabled =
                                ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                        ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::LevelFilter::current() &&
                                    {
                                        let interest = __CALLSITE.interest();
                                        !interest.is_never() &&
                                            ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                interest)
                                    };
                            if enabled {
                                (|value_set: ::tracing::field::ValueSet|
                                            {
                                                let meta = __CALLSITE.metadata();
                                                ::tracing::Event::dispatch(meta, &value_set);
                                                ;
                                            })({
                                        #[allow(unused_imports)]
                                        use ::tracing::field::{debug, display, Value};
                                        __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&generics)
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        if generics.has_self {
                            if generics.parent.is_some() {
                                if !!parent_args.is_empty() {
                                    ::core::panicking::panic("assertion failed: !parent_args.is_empty()")
                                }
                            } else {
                                if !self_ty.is_some() {
                                    ::core::panicking::panic("assertion failed: self_ty.is_some()")
                                };
                            }
                        } else {
                            if !self_ty.is_none() {
                                ::core::panicking::panic("assertion failed: self_ty.is_none()")
                            };
                        }
                        let arg_count =
                            check_generic_arg_count(self, def_id, segment, generics,
                                GenericArgPosition::Type, self_ty.is_some());
                        if generics.is_own_empty() {
                            return (tcx.mk_args(parent_args), arg_count);
                        }
                        struct GenericArgsCtxt<'a, 'tcx> {
                            lowerer: &'a dyn HirTyLowerer<'tcx>,
                            def_id: DefId,
                            generic_args: &'a GenericArgs<'a>,
                            span: Span,
                            infer_args: bool,
                            create_synth_args: bool,
                            incorrect_args: &'a Result<(), GenericArgCountMismatch>,
                        }
                        impl<'a, 'tcx> GenericArgsLowerer<'a, 'tcx> for
                            GenericArgsCtxt<'a, 'tcx> {
                            fn args_for_def_id(&mut self, did: DefId)
                                -> (Option<&'a GenericArgs<'a>>, bool) {
                                if did == self.def_id {
                                    (Some(self.generic_args), self.infer_args)
                                } else { (None, false) }
                            }
                            fn provided_kind(&mut self,
                                preceding_args: &[ty::GenericArg<'tcx>],
                                param: &ty::GenericParamDef, arg: &GenericArg<'_>)
                                -> ty::GenericArg<'tcx> {
                                let tcx = self.lowerer.tcx();
                                if let Err(incorrect) = self.incorrect_args {
                                    if incorrect.invalid_args.contains(&(param.index as usize))
                                        {
                                        return param.to_error(tcx);
                                    }
                                }
                                let handle_ty_args =
                                    |has_default, ty: &hir::Ty<'_>|
                                        {
                                            if has_default {
                                                tcx.check_optional_stability(param.def_id,
                                                    Some(arg.hir_id()), arg.span(), None, AllowUnstable::No,
                                                    |_, _| {});
                                            }
                                            self.lowerer.lower_ty(ty).into()
                                        };
                                match (&param.kind, arg) {
                                    (GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) =>
                                        {
                                        self.lowerer.lower_lifetime(lt,
                                                RegionInferReason::Param(param)).into()
                                    }
                                    (&GenericParamDefKind::Type { has_default, .. },
                                        GenericArg::Type(ty)) => {
                                        handle_ty_args(has_default, ty.as_unambig_ty())
                                    }
                                    (&GenericParamDefKind::Type { has_default, .. },
                                        GenericArg::Infer(inf)) => {
                                        handle_ty_args(has_default, &inf.to_ty())
                                    }
                                    (GenericParamDefKind::Const { .. }, GenericArg::Const(ct))
                                        =>
                                        self.lowerer.lower_const_arg(ct.as_unambig_ct(),
                                                tcx.type_of(param.def_id).instantiate(tcx,
                                                        preceding_args).skip_norm_wip()).into(),
                                    (&GenericParamDefKind::Const { .. }, GenericArg::Infer(inf))
                                        => {
                                        self.lowerer.ct_infer(Some(param), inf.span).into()
                                    }
                                    (kind, arg) =>
                                        ::rustc_span::macros::bug_impl(Some(self.span),
                                            format_args!("mismatched path argument for kind {0:?}: found arg {1:?}",
                                                kind, arg), Location::caller()),
                                }
                            }
                            fn inferred_kind(&mut self,
                                preceding_args: &[ty::GenericArg<'tcx>],
                                param: &ty::GenericParamDef, infer_args: bool)
                                -> ty::GenericArg<'tcx> {
                                let tcx = self.lowerer.tcx();
                                if let Err(incorrect) = self.incorrect_args {
                                    if incorrect.invalid_args.contains(&(param.index as usize))
                                        {
                                        return param.to_error(tcx);
                                    }
                                }
                                match param.kind {
                                    GenericParamDefKind::Lifetime => {
                                        self.lowerer.re_infer(self.span,
                                                RegionInferReason::Param(param)).into()
                                    }
                                    GenericParamDefKind::Type { has_default, synthetic } => {
                                        if !infer_args && has_default {
                                            if let Some(prev) =
                                                    preceding_args.iter().find_map(|arg|
                                                            match arg.kind() {
                                                                GenericArgKind::Type(ty) => ty.error_reported().err(),
                                                                _ => None,
                                                            }) {
                                                return Ty::new_error(tcx, prev).into();
                                            }
                                            tcx.at(self.span).type_of(param.def_id).instantiate(tcx,
                                                        preceding_args).skip_norm_wip().into()
                                        } else if self.create_synth_args && synthetic {
                                            Ty::new_param(tcx, param.index, param.name).into()
                                        } else if infer_args {
                                            self.lowerer.ty_infer(Some(param), self.span).into()
                                        } else { Ty::new_misc_error(tcx).into() }
                                    }
                                    GenericParamDefKind::Const { has_default, .. } => {
                                        let ty =
                                            tcx.at(self.span).type_of(param.def_id).instantiate(tcx,
                                                    preceding_args).skip_norm_wip();
                                        if let Err(guar) = ty.error_reported() {
                                            return ty::Const::new_error(tcx, guar).into();
                                        }
                                        if !infer_args && has_default {
                                            tcx.const_param_default(param.def_id).instantiate(tcx,
                                                        preceding_args).skip_norm_wip().into()
                                        } else if infer_args {
                                            self.lowerer.ct_infer(Some(param), self.span).into()
                                        } else { ty::Const::new_misc_error(tcx).into() }
                                    }
                                }
                            }
                        }
                        let mut args_ctx =
                            GenericArgsCtxt {
                                lowerer: self,
                                def_id,
                                span,
                                generic_args: segment.args(),
                                infer_args: segment.infer_args,
                                create_synth_args: segment.delegation_child_segment,
                                incorrect_args: &arg_count.correct,
                            };
                        let args =
                            lower_generic_args(self, def_id, parent_args,
                                self_ty.is_some(), self_ty, &arg_count, &mut args_ctx);
                        (args, arg_count)
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:677",
                        "rustc_hir_analysis::hir_ty_lowering",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(677u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip(self, span), ret)]
678    pub(crate) fn lower_generic_args_of_path(
679        &self,
680        span: Span,
681        def_id: DefId,
682        parent_args: &[ty::GenericArg<'tcx>],
683        segment: &hir::PathSegment<'_>,
684        self_ty: Option<Ty<'tcx>>,
685    ) -> (ty::GenericArgs<'tcx>, GenericArgCountResult) {
686        // If the type is parameterized by this region, then replace this
687        // region with the current anon region binding (in other words,
688        // whatever & would get replaced with).
689
690        let tcx = self.tcx();
691        let generics = tcx.generics_of(def_id);
692        debug!(?generics);
693
694        if generics.has_self {
695            if generics.parent.is_some() {
696                // The parent is a trait so it should have at least one
697                // generic parameter for the `Self` type.
698                assert!(!parent_args.is_empty())
699            } else {
700                // This item (presumably a trait) needs a self-type.
701                assert!(self_ty.is_some());
702            }
703        } else {
704            assert!(self_ty.is_none());
705        }
706
707        let arg_count = check_generic_arg_count(
708            self,
709            def_id,
710            segment,
711            generics,
712            GenericArgPosition::Type,
713            self_ty.is_some(),
714        );
715
716        // Skip processing if type has no generic parameters.
717        // Traits always have `Self` as a generic parameter, which means they will not return early
718        // here and so associated item constraints will be handled regardless of whether there are
719        // any non-`Self` generic parameters.
720        if generics.is_own_empty() {
721            return (tcx.mk_args(parent_args), arg_count);
722        }
723
724        struct GenericArgsCtxt<'a, 'tcx> {
725            lowerer: &'a dyn HirTyLowerer<'tcx>,
726            def_id: DefId,
727            generic_args: &'a GenericArgs<'a>,
728            span: Span,
729            infer_args: bool,
730            create_synth_args: bool,
731            incorrect_args: &'a Result<(), GenericArgCountMismatch>,
732        }
733
734        impl<'a, 'tcx> GenericArgsLowerer<'a, 'tcx> for GenericArgsCtxt<'a, 'tcx> {
735            fn args_for_def_id(&mut self, did: DefId) -> (Option<&'a GenericArgs<'a>>, bool) {
736                if did == self.def_id {
737                    (Some(self.generic_args), self.infer_args)
738                } else {
739                    // The last component of this tuple is unimportant.
740                    (None, false)
741                }
742            }
743
744            fn provided_kind(
745                &mut self,
746                preceding_args: &[ty::GenericArg<'tcx>],
747                param: &ty::GenericParamDef,
748                arg: &GenericArg<'_>,
749            ) -> ty::GenericArg<'tcx> {
750                let tcx = self.lowerer.tcx();
751
752                if let Err(incorrect) = self.incorrect_args {
753                    if incorrect.invalid_args.contains(&(param.index as usize)) {
754                        return param.to_error(tcx);
755                    }
756                }
757
758                let handle_ty_args = |has_default, ty: &hir::Ty<'_>| {
759                    if has_default {
760                        tcx.check_optional_stability(
761                            param.def_id,
762                            Some(arg.hir_id()),
763                            arg.span(),
764                            None,
765                            AllowUnstable::No,
766                            |_, _| {
767                                // Default generic parameters may not be marked
768                                // with stability attributes, i.e. when the
769                                // default parameter was defined at the same time
770                                // as the rest of the type. As such, we ignore missing
771                                // stability attributes.
772                            },
773                        );
774                    }
775                    self.lowerer.lower_ty(ty).into()
776                };
777
778                match (&param.kind, arg) {
779                    (GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => {
780                        self.lowerer.lower_lifetime(lt, RegionInferReason::Param(param)).into()
781                    }
782                    (&GenericParamDefKind::Type { has_default, .. }, GenericArg::Type(ty)) => {
783                        // We handle the other parts of `Ty` in the match arm below
784                        handle_ty_args(has_default, ty.as_unambig_ty())
785                    }
786                    (&GenericParamDefKind::Type { has_default, .. }, GenericArg::Infer(inf)) => {
787                        handle_ty_args(has_default, &inf.to_ty())
788                    }
789                    (GenericParamDefKind::Const { .. }, GenericArg::Const(ct)) => self
790                        .lowerer
791                        // Ambig portions of `ConstArg` are handled in the match arm below
792                        .lower_const_arg(
793                            ct.as_unambig_ct(),
794                            tcx.type_of(param.def_id)
795                                .instantiate(tcx, preceding_args)
796                                .skip_norm_wip(),
797                        )
798                        .into(),
799                    (&GenericParamDefKind::Const { .. }, GenericArg::Infer(inf)) => {
800                        self.lowerer.ct_infer(Some(param), inf.span).into()
801                    }
802                    (kind, arg) => span_bug!(
803                        self.span,
804                        "mismatched path argument for kind {kind:?}: found arg {arg:?}"
805                    ),
806                }
807            }
808
809            fn inferred_kind(
810                &mut self,
811                preceding_args: &[ty::GenericArg<'tcx>],
812                param: &ty::GenericParamDef,
813                infer_args: bool,
814            ) -> ty::GenericArg<'tcx> {
815                let tcx = self.lowerer.tcx();
816
817                if let Err(incorrect) = self.incorrect_args {
818                    if incorrect.invalid_args.contains(&(param.index as usize)) {
819                        return param.to_error(tcx);
820                    }
821                }
822                match param.kind {
823                    GenericParamDefKind::Lifetime => {
824                        self.lowerer.re_infer(self.span, RegionInferReason::Param(param)).into()
825                    }
826                    GenericParamDefKind::Type { has_default, synthetic } => {
827                        if !infer_args && has_default {
828                            // No type parameter provided, but a default exists.
829                            if let Some(prev) =
830                                preceding_args.iter().find_map(|arg| match arg.kind() {
831                                    GenericArgKind::Type(ty) => ty.error_reported().err(),
832                                    _ => None,
833                                })
834                            {
835                                // Avoid ICE #86756 when type error recovery goes awry.
836                                return Ty::new_error(tcx, prev).into();
837                            }
838                            tcx.at(self.span)
839                                .type_of(param.def_id)
840                                .instantiate(tcx, preceding_args)
841                                .skip_norm_wip()
842                                .into()
843                        } else if self.create_synth_args && synthetic {
844                            Ty::new_param(tcx, param.index, param.name).into()
845                        } else if infer_args {
846                            self.lowerer.ty_infer(Some(param), self.span).into()
847                        } else {
848                            // We've already errored above about the mismatch.
849                            Ty::new_misc_error(tcx).into()
850                        }
851                    }
852                    GenericParamDefKind::Const { has_default, .. } => {
853                        let ty = tcx
854                            .at(self.span)
855                            .type_of(param.def_id)
856                            .instantiate(tcx, preceding_args)
857                            .skip_norm_wip();
858                        if let Err(guar) = ty.error_reported() {
859                            return ty::Const::new_error(tcx, guar).into();
860                        }
861                        if !infer_args && has_default {
862                            tcx.const_param_default(param.def_id)
863                                .instantiate(tcx, preceding_args)
864                                .skip_norm_wip()
865                                .into()
866                        } else if infer_args {
867                            self.lowerer.ct_infer(Some(param), self.span).into()
868                        } else {
869                            // We've already errored above about the mismatch.
870                            ty::Const::new_misc_error(tcx).into()
871                        }
872                    }
873                }
874            }
875        }
876
877        let mut args_ctx = GenericArgsCtxt {
878            lowerer: self,
879            def_id,
880            span,
881            generic_args: segment.args(),
882            infer_args: segment.infer_args,
883            create_synth_args: segment.delegation_child_segment,
884            incorrect_args: &arg_count.correct,
885        };
886
887        let args = lower_generic_args(
888            self,
889            def_id,
890            parent_args,
891            self_ty.is_some(),
892            self_ty,
893            &arg_count,
894            &mut args_ctx,
895        );
896
897        (args, arg_count)
898    }
899
900    {}
#[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("lower_generic_args_of_assoc_item",
                                    "rustc_hir_analysis::hir_ty_lowering",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(900u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("span")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("span");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("item_def_id")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("item_def_id");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("item_segment")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("item_segment");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("parent_args")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("parent_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(&span)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&item_def_id)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&item_segment)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&parent_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: ty::GenericArgs<'tcx> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let (args, _) =
                self.lower_generic_args_of_path(span, item_def_id,
                    parent_args.as_slice(), item_segment, None);
            if let Some(c) = item_segment.args().constraints.first() {
                prohibit_assoc_item_constraint(self, c,
                    Some((item_def_id, item_segment, span)));
            }
            args
        }
    }
}#[instrument(level = "debug", skip(self))]
901    pub fn lower_generic_args_of_assoc_item(
902        &self,
903        span: Span,
904        item_def_id: DefId,
905        item_segment: &hir::PathSegment<'_>,
906        parent_args: ty::GenericArgs<'tcx>,
907    ) -> ty::GenericArgs<'tcx> {
908        let (args, _) = self.lower_generic_args_of_path(
909            span,
910            item_def_id,
911            parent_args.as_slice(),
912            item_segment,
913            None,
914        );
915        if let Some(c) = item_segment.args().constraints.first() {
916            prohibit_assoc_item_constraint(self, c, Some((item_def_id, item_segment, span)));
917        }
918        args
919    }
920
921    /// Lower a trait reference as found in an impl header as the implementee.
922    ///
923    /// The self type `self_ty` is the implementer of the trait.
924    pub fn lower_impl_trait_ref(
925        &self,
926        trait_ref: &hir::TraitRef<'tcx>,
927        self_ty: Ty<'tcx>,
928    ) -> ty::TraitRef<'tcx> {
929        let [leading_segments @ .., segment] = trait_ref.path.segments else { ::rustc_span::macros::bug_impl(None, format_args!("impossible case reached"),
    Location::caller())bug!() };
930
931        let _ = self.prohibit_generic_args(leading_segments.iter(), GenericsArgsErrExtend::None);
932
933        self.lower_mono_trait_ref(
934            trait_ref.path.span,
935            trait_ref.trait_def_id().unwrap_or_else(|| FatalError.raise()),
936            self_ty,
937            segment,
938            true,
939        )
940    }
941
942    /// Lower a polymorphic trait reference given a self type into `bounds`.
943    ///
944    /// *Polymorphic* in the sense that it may bind late-bound vars.
945    ///
946    /// This may generate auxiliary bounds iff the trait reference contains associated item constraints.
947    ///
948    /// ### Example
949    ///
950    /// Given the trait ref `Iterator<Item = u32>` and the self type `Ty`, this will add the
951    ///
952    /// 1. *trait predicate* `<Ty as Iterator>` (known as `Ty: Iterator` in the surface syntax) and the
953    /// 2. *projection predicate* `<Ty as Iterator>::Item = u32`
954    ///
955    /// to `bounds`.
956    ///
957    /// ### A Note on Binders
958    ///
959    /// Against our usual convention, there is an implied binder around the `self_ty` and the
960    /// `trait_ref` here. So they may reference late-bound vars.
961    ///
962    /// If for example you had `for<'a> Foo<'a>: Bar<'a>`, then the `self_ty` would be `Foo<'a>`
963    /// where `'a` is a bound region at depth 0. Similarly, the `trait_ref` would be `Bar<'a>`.
964    /// The lowered poly-trait-ref will track this binder explicitly, however.
965    {}
#[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("lower_poly_trait_ref",
                                    "rustc_hir_analysis::hir_ty_lowering",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(965u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("bound_generic_params")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("bound_generic_params");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("constness")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("constness");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("polarity")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("polarity");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("trait_ref")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("trait_ref");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("span")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("span");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("self_ty")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("self_ty");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("predicate_filter")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("predicate_filter");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("overlapping_assoc_item_constraints")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("overlapping_assoc_item_constraints");
                                                        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(&bound_generic_params)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&constness)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&polarity)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_ref)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&predicate_filter)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&overlapping_assoc_item_constraints)
                                                            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: GenericArgCountResult = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let tcx = self.tcx();
            let _ = bound_generic_params;
            let trait_def_id =
                trait_ref.trait_def_id().unwrap_or_else(||
                        FatalError.raise());
            let transient =
                match polarity {
                    hir::BoundPolarity::Positive => {
                        tcx.is_lang_item(trait_def_id, LangItem::PointeeSized)
                    }
                    hir::BoundPolarity::Negative(_) => false,
                    hir::BoundPolarity::Maybe(_) => {
                        self.require_bound_to_relax_default_trait(trait_ref, span);
                        true
                    }
                };
            let bounds = if transient { &mut Vec::new() } else { bounds };
            let polarity =
                match polarity {
                    hir::BoundPolarity::Positive | hir::BoundPolarity::Maybe(_)
                        => {
                        ty::ClausePolarity::Positive
                    }
                    hir::BoundPolarity::Negative(_) =>
                        ty::ClausePolarity::Negative,
                };
            let [leading_segments @ .., segment] =
                trait_ref.path.segments else {
                    ::rustc_span::macros::bug_impl(None,
                        format_args!("impossible case reached"), Location::caller())
                };
            let _ =
                self.prohibit_generic_args(leading_segments.iter(),
                    GenericsArgsErrExtend::None);
            self.report_internal_fn_trait(span, trait_def_id, segment, false);
            let (generic_args, arg_count) =
                self.lower_generic_args_of_path(trait_ref.path.span,
                    trait_def_id, &[], segment, Some(self_ty));
            let constraints = segment.args().constraints;
            if transient &&
                    (!generic_args.as_slice()[1..].is_empty() ||
                            !constraints.is_empty()) {
                self.dcx().span_delayed_bug(span,
                    "transient bound should not have args or constraints");
            }
            let bound_vars = tcx.late_bound_vars(trait_ref.hir_ref_id);
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1045",
                                    "rustc_hir_analysis::hir_ty_lowering",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1045u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("bound_vars")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("bound_vars");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&bound_vars)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            let poly_trait_ref =
                ty::Binder::bind_with_vars(ty::TraitRef::new_from_args(tcx,
                        trait_def_id, generic_args), bound_vars);
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1052",
                                    "rustc_hir_analysis::hir_ty_lowering",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1052u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("poly_trait_ref")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("poly_trait_ref");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&poly_trait_ref)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            match predicate_filter {
                PredicateFilter::All | PredicateFilter::SelfOnly |
                    PredicateFilter::SelfTraitThatDefines(..) |
                    PredicateFilter::SelfAndAssociatedTypeBounds => {
                    let bound =
                        poly_trait_ref.map_bound(|trait_ref|
                                {
                                    ty::ClauseKind::Trait(ty::TraitClause {
                                            trait_ref,
                                            polarity,
                                        })
                                });
                    let bound = (bound.upcast(tcx), span);
                    if tcx.is_lang_item(trait_def_id, LangItem::Sized) {
                        bounds.insert(0, bound);
                    } else { bounds.push(bound); }
                }
                PredicateFilter::ConstIfConst |
                    PredicateFilter::SelfConstIfConst => {}
            }
            if let hir::BoundConstness::Always(span) |
                        hir::BoundConstness::Maybe(span) = constness &&
                    !tcx.is_const_trait(trait_def_id) {
                let (def_span, suggestion, suggestion_pre) =
                    match (trait_def_id.as_local(), tcx.sess.is_nightly_build())
                        {
                        (Some(trait_def_id), true) => {
                            let span = tcx.hir_expect_item(trait_def_id).vis_span;
                            let span =
                                tcx.sess.source_map().span_extend_while_whitespace(span);
                            (None, Some(span.shrink_to_hi()),
                                if self.tcx().features().const_trait_impl() {
                                    ""
                                } else {
                                    "enable `#![feature(const_trait_impl)]` in your crate and "
                                })
                        }
                        (None, _) | (_, false) =>
                            (Some(tcx.def_span(trait_def_id)), None, ""),
                    };
                self.dcx().emit_err(crate::diagnostics::ConstBoundForNonConstTrait {
                        span,
                        modifier: constness.as_str(),
                        def_span,
                        trait_name: tcx.def_path_str(trait_def_id),
                        suggestion,
                        suggestion_pre,
                    });
            } else {
                match predicate_filter {
                    PredicateFilter::SelfTraitThatDefines(..) => {}
                    PredicateFilter::All | PredicateFilter::SelfOnly |
                        PredicateFilter::SelfAndAssociatedTypeBounds => {
                        match constness {
                            hir::BoundConstness::Always(_) => {
                                if polarity == ty::ClausePolarity::Positive {
                                    bounds.push((poly_trait_ref.to_host_effect_clause(tcx,
                                                ty::BoundConstness::Const), span));
                                }
                            }
                            hir::BoundConstness::Maybe(_) => {}
                            hir::BoundConstness::Never => {}
                        }
                    }
                    PredicateFilter::ConstIfConst |
                        PredicateFilter::SelfConstIfConst => {
                        match constness {
                            hir::BoundConstness::Maybe(_) => {
                                if polarity == ty::ClausePolarity::Positive {
                                    bounds.push((poly_trait_ref.to_host_effect_clause(tcx,
                                                ty::BoundConstness::Maybe), span));
                                }
                            }
                            hir::BoundConstness::Always(_) | hir::BoundConstness::Never
                                => {}
                        }
                    }
                }
            }
            let mut dup_constraints =
                (overlapping_assoc_item_constraints ==
                            OverlappingAsssocItemConstraints::Forbidden).then_some(FxIndexMap::default());
            for constraint in constraints {
                if polarity == ty::ClausePolarity::Negative {
                    self.dcx().span_delayed_bug(constraint.span,
                        "negative trait bounds should not have assoc item constraints");
                    break;
                }
                let _: Result<_, ErrorGuaranteed> =
                    self.lower_assoc_item_constraint(trait_ref.hir_ref_id,
                        poly_trait_ref, constraint, bounds,
                        dup_constraints.as_mut(), constraint.span,
                        predicate_filter);
            }
            arg_count
        }
    }
}#[instrument(level = "debug", skip(self, bounds))]
966    pub(crate) fn lower_poly_trait_ref(
967        &self,
968        &hir::PolyTraitRef {
969            bound_generic_params,
970            modifiers: hir::TraitBoundModifiers { constness, polarity },
971            trait_ref,
972            span,
973        }: &hir::PolyTraitRef<'_>,
974        self_ty: Ty<'tcx>,
975        bounds: &mut Vec<(ty::Clause<'tcx>, Span)>,
976        predicate_filter: PredicateFilter,
977        overlapping_assoc_item_constraints: OverlappingAsssocItemConstraints,
978    ) -> GenericArgCountResult {
979        let tcx = self.tcx();
980
981        // We use the *resolved* bound vars later instead of the HIR ones since the former
982        // also include the bound vars of the overarching predicate if applicable.
983        let _ = bound_generic_params;
984
985        let trait_def_id = trait_ref.trait_def_id().unwrap_or_else(|| FatalError.raise());
986
987        // Relaxed bounds `?Trait` and `PointeeSized` bounds aren't represented in the middle::ty IR
988        // as they denote the *absence* of a default bound. However, we can't bail out early here since
989        // we still need to perform several validation steps (see below). Instead, simply "pour" all
990        // resulting bounds "down the drain", i.e., into a new `Vec` that just gets dropped at the end.
991        let transient = match polarity {
992            hir::BoundPolarity::Positive => {
993                // To elaborate on the comment directly above, regarding `PointeeSized` specifically,
994                // we don't "reify" such bounds to avoid trait system limitations -- namely,
995                // non-global where-clauses being preferred over item bounds (where `PointeeSized`
996                // bounds would be proven) -- which can result in errors when a `PointeeSized`
997                // supertrait / bound / predicate is added to some items.
998                tcx.is_lang_item(trait_def_id, LangItem::PointeeSized)
999            }
1000            hir::BoundPolarity::Negative(_) => false,
1001            hir::BoundPolarity::Maybe(_) => {
1002                self.require_bound_to_relax_default_trait(trait_ref, span);
1003                true
1004            }
1005        };
1006        let bounds = if transient { &mut Vec::new() } else { bounds };
1007
1008        let polarity = match polarity {
1009            hir::BoundPolarity::Positive | hir::BoundPolarity::Maybe(_) => {
1010                ty::ClausePolarity::Positive
1011            }
1012            hir::BoundPolarity::Negative(_) => ty::ClausePolarity::Negative,
1013        };
1014
1015        let [leading_segments @ .., segment] = trait_ref.path.segments else { bug!() };
1016
1017        let _ = self.prohibit_generic_args(leading_segments.iter(), GenericsArgsErrExtend::None);
1018        self.report_internal_fn_trait(span, trait_def_id, segment, false);
1019
1020        let (generic_args, arg_count) = self.lower_generic_args_of_path(
1021            trait_ref.path.span,
1022            trait_def_id,
1023            &[],
1024            segment,
1025            Some(self_ty),
1026        );
1027
1028        let constraints = segment.args().constraints;
1029
1030        if transient && (!generic_args.as_slice()[1..].is_empty() || !constraints.is_empty()) {
1031            // Since the bound won't be present in the middle::ty IR as established above, any
1032            // arguments or constraints won't be checked for well-formedness in later passes.
1033            //
1034            // This is only an issue if the trait ref is otherwise valid which can only happen if
1035            // the corresponding default trait has generic parameters or associated items. Such a
1036            // trait would be degenerate. We delay a bug to detect and guard us against these.
1037            //
1038            // E.g: Given `/*default*/ trait Bound<'a: 'static, T, const N: usize> {}`,
1039            // `?Bound<Vec<str>, { panic!() }>` won't be wfchecked.
1040            self.dcx()
1041                .span_delayed_bug(span, "transient bound should not have args or constraints");
1042        }
1043
1044        let bound_vars = tcx.late_bound_vars(trait_ref.hir_ref_id);
1045        debug!(?bound_vars);
1046
1047        let poly_trait_ref = ty::Binder::bind_with_vars(
1048            ty::TraitRef::new_from_args(tcx, trait_def_id, generic_args),
1049            bound_vars,
1050        );
1051
1052        debug!(?poly_trait_ref);
1053
1054        // We deal with const conditions later.
1055        match predicate_filter {
1056            PredicateFilter::All
1057            | PredicateFilter::SelfOnly
1058            | PredicateFilter::SelfTraitThatDefines(..)
1059            | PredicateFilter::SelfAndAssociatedTypeBounds => {
1060                let bound = poly_trait_ref.map_bound(|trait_ref| {
1061                    ty::ClauseKind::Trait(ty::TraitClause { trait_ref, polarity })
1062                });
1063                let bound = (bound.upcast(tcx), span);
1064                // FIXME(-Znext-solver): We can likely remove this hack once the
1065                // new trait solver lands. This fixed an overflow in the old solver.
1066                // This may have performance implications, so please check perf when
1067                // removing it.
1068                // This was added in <https://github.com/rust-lang/rust/pull/123302>.
1069                if tcx.is_lang_item(trait_def_id, LangItem::Sized) {
1070                    bounds.insert(0, bound);
1071                } else {
1072                    bounds.push(bound);
1073                }
1074            }
1075            PredicateFilter::ConstIfConst | PredicateFilter::SelfConstIfConst => {}
1076        }
1077
1078        if let hir::BoundConstness::Always(span) | hir::BoundConstness::Maybe(span) = constness
1079            && !tcx.is_const_trait(trait_def_id)
1080        {
1081            let (def_span, suggestion, suggestion_pre) =
1082                match (trait_def_id.as_local(), tcx.sess.is_nightly_build()) {
1083                    (Some(trait_def_id), true) => {
1084                        let span = tcx.hir_expect_item(trait_def_id).vis_span;
1085                        let span = tcx.sess.source_map().span_extend_while_whitespace(span);
1086
1087                        (
1088                            None,
1089                            Some(span.shrink_to_hi()),
1090                            if self.tcx().features().const_trait_impl() {
1091                                ""
1092                            } else {
1093                                "enable `#![feature(const_trait_impl)]` in your crate and "
1094                            },
1095                        )
1096                    }
1097                    (None, _) | (_, false) => (Some(tcx.def_span(trait_def_id)), None, ""),
1098                };
1099            self.dcx().emit_err(crate::diagnostics::ConstBoundForNonConstTrait {
1100                span,
1101                modifier: constness.as_str(),
1102                def_span,
1103                trait_name: tcx.def_path_str(trait_def_id),
1104                suggestion,
1105                suggestion_pre,
1106            });
1107        } else {
1108            match predicate_filter {
1109                // This is only concerned with trait predicates.
1110                PredicateFilter::SelfTraitThatDefines(..) => {}
1111                PredicateFilter::All
1112                | PredicateFilter::SelfOnly
1113                | PredicateFilter::SelfAndAssociatedTypeBounds => {
1114                    match constness {
1115                        hir::BoundConstness::Always(_) => {
1116                            if polarity == ty::ClausePolarity::Positive {
1117                                bounds.push((
1118                                    poly_trait_ref
1119                                        .to_host_effect_clause(tcx, ty::BoundConstness::Const),
1120                                    span,
1121                                ));
1122                            }
1123                        }
1124                        hir::BoundConstness::Maybe(_) => {
1125                            // We don't emit a const bound here, since that would mean that we
1126                            // unconditionally need to prove a `HostEffect` predicate, even when
1127                            // the predicates are being instantiated in a non-const context. This
1128                            // is instead handled in the `const_conditions` query.
1129                        }
1130                        hir::BoundConstness::Never => {}
1131                    }
1132                }
1133                // On the flip side, when filtering `ConstIfConst` bounds, we only need to convert
1134                // `[const]` bounds. All other predicates are handled in their respective queries.
1135                //
1136                // Note that like `PredicateFilter::SelfOnly`, we don't need to do any filtering
1137                // here because we only call this on self bounds, and deal with the recursive case
1138                // in `lower_assoc_item_constraint`.
1139                PredicateFilter::ConstIfConst | PredicateFilter::SelfConstIfConst => {
1140                    match constness {
1141                        hir::BoundConstness::Maybe(_) => {
1142                            if polarity == ty::ClausePolarity::Positive {
1143                                bounds.push((
1144                                    poly_trait_ref
1145                                        .to_host_effect_clause(tcx, ty::BoundConstness::Maybe),
1146                                    span,
1147                                ));
1148                            }
1149                        }
1150                        hir::BoundConstness::Always(_) | hir::BoundConstness::Never => {}
1151                    }
1152                }
1153            }
1154        }
1155
1156        let mut dup_constraints = (overlapping_assoc_item_constraints
1157            == OverlappingAsssocItemConstraints::Forbidden)
1158            .then_some(FxIndexMap::default());
1159
1160        for constraint in constraints {
1161            // Don't register any associated item constraints for negative bounds,
1162            // since we should have emitted an error for them earlier, and they
1163            // would not be well-formed!
1164            if polarity == ty::ClausePolarity::Negative {
1165                self.dcx().span_delayed_bug(
1166                    constraint.span,
1167                    "negative trait bounds should not have assoc item constraints",
1168                );
1169                break;
1170            }
1171
1172            // Specify type to assert that error was already reported in `Err` case.
1173            let _: Result<_, ErrorGuaranteed> = self.lower_assoc_item_constraint(
1174                trait_ref.hir_ref_id,
1175                poly_trait_ref,
1176                constraint,
1177                bounds,
1178                dup_constraints.as_mut(),
1179                constraint.span,
1180                predicate_filter,
1181            );
1182            // Okay to ignore `Err` because of `ErrorGuaranteed` (see above).
1183        }
1184
1185        arg_count
1186    }
1187
1188    /// Lower a monomorphic trait reference given a self type while prohibiting associated item bindings.
1189    ///
1190    /// *Monomorphic* in the sense that it doesn't bind any late-bound vars.
1191    fn lower_mono_trait_ref(
1192        &self,
1193        span: Span,
1194        trait_def_id: DefId,
1195        self_ty: Ty<'tcx>,
1196        trait_segment: &hir::PathSegment<'_>,
1197        is_impl: bool,
1198    ) -> ty::TraitRef<'tcx> {
1199        self.report_internal_fn_trait(span, trait_def_id, trait_segment, is_impl);
1200
1201        let (generic_args, _) =
1202            self.lower_generic_args_of_path(span, trait_def_id, &[], trait_segment, Some(self_ty));
1203        if let Some(c) = trait_segment.args().constraints.first() {
1204            prohibit_assoc_item_constraint(self, c, Some((trait_def_id, trait_segment, span)));
1205        }
1206        ty::TraitRef::new_from_args(self.tcx(), trait_def_id, generic_args)
1207    }
1208
1209    fn probe_trait_that_defines_assoc_item(
1210        &self,
1211        trait_def_id: DefId,
1212        assoc_tag: ty::AssocTag,
1213        assoc_ident: Ident,
1214    ) -> bool {
1215        self.tcx()
1216            .associated_items(trait_def_id)
1217            .find_by_ident_and_kind(self.tcx(), assoc_ident, assoc_tag, trait_def_id)
1218            .is_some()
1219    }
1220
1221    fn lower_path_segment(
1222        &self,
1223        span: Span,
1224        def_id: DefId,
1225        item_segment: &hir::PathSegment<'_>,
1226    ) -> Ty<'tcx> {
1227        let tcx = self.tcx();
1228        let args = self.lower_generic_args_of_path_segment(span, def_id, item_segment);
1229
1230        if let DefKind::TyAlias = tcx.def_kind(def_id)
1231            && tcx.type_alias_is_checked(def_id)
1232        {
1233            // Type aliases defined in crates that have the
1234            // feature `checked_type_alias` enabled get encoded as a type alias that normalization will
1235            // then actually instantiate the where bounds of.
1236            let alias_ty = ty::AliasTy::new_from_args(tcx, ty::Free { def_id }, args);
1237            Ty::new_alias(tcx, ty::IsRigid::No, alias_ty)
1238        } else {
1239            tcx.at(span).type_of(def_id).instantiate(tcx, args).skip_norm_wip()
1240        }
1241    }
1242
1243    /// Search for a trait bound on a type parameter whose trait defines the associated item
1244    /// given by `assoc_ident` and `kind`.
1245    ///
1246    /// This fails if there is no such bound in the list of candidates or if there are multiple
1247    /// candidates in which case it reports ambiguity.
1248    ///
1249    /// `ty_param_def_id` is the `LocalDefId` of the type parameter.
1250    {}
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("probe_single_ty_param_bound_for_assoc_item",
                                "rustc_hir_analysis::hir_ty_lowering",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                ::tracing_core::__macro_support::Option::Some(1250u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                ::tracing_core::field::FieldSet::new(&[],
                                    ::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,
                    &{ meta.fields().value_set_all(&[]) })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[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:
                                Result<ty::PolyTraitRef<'tcx>, ErrorGuaranteed> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1259",
                                                "rustc_hir_analysis::hir_ty_lowering",
                                                ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                                ::tracing_core::__macro_support::Option::Some(1259u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("ty_param_def_id")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("ty_param_def_id");
                                                                    NAME.as_str()
                                                                },
                                                                {
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("assoc_ident")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("assoc_ident");
                                                                    NAME.as_str()
                                                                },
                                                                {
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("span")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("span");
                                                                    NAME.as_str()
                                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                ::tracing::metadata::Kind::EVENT)
                                        };
                                    ::tracing::callsite::DefaultCallsite::new(&META)
                                };
                            let enabled =
                                ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                        ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::LevelFilter::current() &&
                                    {
                                        let interest = __CALLSITE.interest();
                                        !interest.is_never() &&
                                            ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                interest)
                                    };
                            if enabled {
                                (|value_set: ::tracing::field::ValueSet|
                                            {
                                                let meta = __CALLSITE.metadata();
                                                ::tracing::Event::dispatch(meta, &value_set);
                                                ;
                                            })({
                                        #[allow(unused_imports)]
                                        use ::tracing::field::{debug, display, Value};
                                        __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ty_param_def_id)
                                                                    as &dyn ::tracing::field::Value)),
                                                        (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&assoc_ident)
                                                                    as &dyn ::tracing::field::Value)),
                                                        (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        let tcx = self.tcx();
                        let predicates =
                            &self.probe_ty_param_bounds(span, ty_param_def_id,
                                    assoc_ident);
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1263",
                                                "rustc_hir_analysis::hir_ty_lowering",
                                                ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                                ::tracing_core::__macro_support::Option::Some(1263u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                                ::tracing_core::field::FieldSet::new(&["message"],
                                                    ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                ::tracing::metadata::Kind::EVENT)
                                        };
                                    ::tracing::callsite::DefaultCallsite::new(&META)
                                };
                            let enabled =
                                ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                        ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::LevelFilter::current() &&
                                    {
                                        let interest = __CALLSITE.interest();
                                        !interest.is_never() &&
                                            ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                interest)
                                    };
                            if enabled {
                                (|value_set: ::tracing::field::ValueSet|
                                            {
                                                let meta = __CALLSITE.metadata();
                                                ::tracing::Event::dispatch(meta, &value_set);
                                                ;
                                            })({
                                        #[allow(unused_imports)]
                                        use ::tracing::field::{debug, display, Value};
                                        __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("predicates={0:#?}",
                                                                            predicates) as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        self.probe_single_bound_for_assoc_item(||
                                {
                                    let trait_refs =
                                        predicates.iter_identity_copied().map(Unnormalized::skip_norm_wip).filter_map(|(p,
                                                    _)| Some(p.as_trait_clause()?.map_bound(|t| t.trait_ref)));
                                    traits::transitive_bounds_that_define_assoc_item(tcx,
                                        trait_refs, assoc_ident)
                                }, AssocItemQSelf::TyParam(ty_param_def_id, ty_param_span),
                            assoc_tag, assoc_ident, span, None)
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1250",
                        "rustc_hir_analysis::hir_ty_lowering",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(1250u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip_all, ret)]
1251    fn probe_single_ty_param_bound_for_assoc_item(
1252        &self,
1253        ty_param_def_id: LocalDefId,
1254        ty_param_span: Span,
1255        assoc_tag: ty::AssocTag,
1256        assoc_ident: Ident,
1257        span: Span,
1258    ) -> Result<ty::PolyTraitRef<'tcx>, ErrorGuaranteed> {
1259        debug!(?ty_param_def_id, ?assoc_ident, ?span);
1260        let tcx = self.tcx();
1261
1262        let predicates = &self.probe_ty_param_bounds(span, ty_param_def_id, assoc_ident);
1263        debug!("predicates={:#?}", predicates);
1264
1265        self.probe_single_bound_for_assoc_item(
1266            || {
1267                let trait_refs = predicates
1268                    .iter_identity_copied()
1269                    .map(Unnormalized::skip_norm_wip)
1270                    .filter_map(|(p, _)| Some(p.as_trait_clause()?.map_bound(|t| t.trait_ref)));
1271                traits::transitive_bounds_that_define_assoc_item(tcx, trait_refs, assoc_ident)
1272            },
1273            AssocItemQSelf::TyParam(ty_param_def_id, ty_param_span),
1274            assoc_tag,
1275            assoc_ident,
1276            span,
1277            None,
1278        )
1279    }
1280
1281    /// When there are multiple traits which contain an identically named
1282    /// associated item, this function eliminates any traits which are a
1283    /// supertrait of another candidate trait.
1284    ///
1285    /// This is the type-level analogue of
1286    /// `rustc_hir_typeck::method::probe::ProbeContext::collapse_candidates_to_subtrait_pick`;
1287    /// keep both implementations in sync.
1288    ///
1289    /// This implements RFC #3624.
1290    fn collapse_candidates_to_subtrait_pick(
1291        &self,
1292        matching_candidates: &[ty::PolyTraitRef<'tcx>],
1293    ) -> Option<ty::PolyTraitRef<'tcx>> {
1294        if !self.tcx().features().supertrait_item_shadowing() {
1295            return None;
1296        }
1297
1298        let mut child_trait = matching_candidates[0];
1299        let mut supertraits: SsoHashSet<_> =
1300            traits::supertrait_def_ids(self.tcx(), child_trait.def_id()).collect();
1301
1302        let mut remaining_candidates: Vec<_> = matching_candidates[1..].iter().copied().collect();
1303        while !remaining_candidates.is_empty() {
1304            let mut made_progress = false;
1305            let mut next_round = ::alloc::vec::Vec::new()vec![];
1306
1307            for remaining_trait in remaining_candidates {
1308                if supertraits.contains(&remaining_trait.def_id()) {
1309                    made_progress = true;
1310                    continue;
1311                }
1312
1313                // This candidate is not a supertrait of the `child_trait`.
1314                // Check if it's a subtrait of the `child_trait`, instead.
1315                // If it is, then it must have been a subtrait of every
1316                // other pick we've eliminated at this point. It will
1317                // take over at this point.
1318                let remaining_trait_supertraits: SsoHashSet<_> =
1319                    traits::supertrait_def_ids(self.tcx(), remaining_trait.def_id()).collect();
1320                if remaining_trait_supertraits.contains(&child_trait.def_id()) {
1321                    child_trait = remaining_trait;
1322                    supertraits = remaining_trait_supertraits;
1323                    made_progress = true;
1324                    continue;
1325                }
1326
1327                // Neither `child_trait` or the current candidate are
1328                // supertraits of each other.
1329                // Don't bail here, since we may be comparing two supertraits
1330                // of a common subtrait. These two supertraits won't be related
1331                // at all, but we will pick them up next round when we find their
1332                // child as we continue iterating in this round.
1333                next_round.push(remaining_trait);
1334            }
1335
1336            if made_progress {
1337                // If we've made progress, iterate again.
1338                remaining_candidates = next_round;
1339            } else {
1340                // Otherwise, we must have at least two candidates which
1341                // are not related to each other at all.
1342                return None;
1343            }
1344        }
1345
1346        Some(child_trait)
1347    }
1348
1349    /// Search for a single trait bound whose trait defines the associated item given by
1350    /// `assoc_ident`.
1351    ///
1352    /// This fails if there is no such bound in the list of candidates or if there are multiple
1353    /// candidates in which case it reports ambiguity.
1354    {}
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("probe_single_bound_for_assoc_item",
                                "rustc_hir_analysis::hir_ty_lowering",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                ::tracing_core::__macro_support::Option::Some(1354u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("assoc_tag")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("assoc_tag");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("assoc_ident")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("assoc_ident");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("span")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("span");
                                                    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(&assoc_tag)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&assoc_ident)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[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:
                                Result<ty::PolyTraitRef<'tcx>, ErrorGuaranteed> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        let mut matching_candidates =
                            all_candidates().filter(|r|
                                    {
                                        self.probe_trait_that_defines_assoc_item(r.def_id(),
                                            assoc_tag, assoc_ident)
                                    });
                        let Some(bound1) =
                            matching_candidates.next() else {
                                return Err(self.report_unresolved_assoc_item(all_candidates,
                                            qself, assoc_tag, assoc_ident, span, constraint));
                            };
                        if let Some(bound2) = matching_candidates.next() {
                            let all_matching_candidates: Vec<_> =
                                [bound1,
                                                    bound2].into_iter().chain(matching_candidates).collect();
                            if let Some(bound) =
                                    self.collapse_candidates_to_subtrait_pick(&all_matching_candidates)
                                {
                                return Ok(bound);
                            }
                            return Err(self.report_ambiguous_assoc_item(&all_matching_candidates,
                                        qself, assoc_tag, assoc_ident, span, constraint));
                        }
                        Ok(bound1)
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1354",
                        "rustc_hir_analysis::hir_ty_lowering",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(1354u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip(self, all_candidates, qself, constraint), ret)]
1355    fn probe_single_bound_for_assoc_item<I>(
1356        &self,
1357        all_candidates: impl Fn() -> I,
1358        qself: AssocItemQSelf,
1359        assoc_tag: ty::AssocTag,
1360        assoc_ident: Ident,
1361        span: Span,
1362        constraint: Option<&hir::AssocItemConstraint<'_>>,
1363    ) -> Result<ty::PolyTraitRef<'tcx>, ErrorGuaranteed>
1364    where
1365        I: Iterator<Item = ty::PolyTraitRef<'tcx>>,
1366    {
1367        let mut matching_candidates = all_candidates().filter(|r| {
1368            self.probe_trait_that_defines_assoc_item(r.def_id(), assoc_tag, assoc_ident)
1369        });
1370
1371        let Some(bound1) = matching_candidates.next() else {
1372            return Err(self.report_unresolved_assoc_item(
1373                all_candidates,
1374                qself,
1375                assoc_tag,
1376                assoc_ident,
1377                span,
1378                constraint,
1379            ));
1380        };
1381
1382        if let Some(bound2) = matching_candidates.next() {
1383            let all_matching_candidates: Vec<_> =
1384                [bound1, bound2].into_iter().chain(matching_candidates).collect();
1385            if let Some(bound) = self.collapse_candidates_to_subtrait_pick(&all_matching_candidates)
1386            {
1387                return Ok(bound);
1388            }
1389
1390            return Err(self.report_ambiguous_assoc_item(
1391                &all_matching_candidates,
1392                qself,
1393                assoc_tag,
1394                assoc_ident,
1395                span,
1396                constraint,
1397            ));
1398        }
1399
1400        Ok(bound1)
1401    }
1402
1403    /// Lower a [type-relative](hir::QPath::TypeRelative) path in type position to a type.
1404    ///
1405    /// If the path refers to an enum variant and `permit_variants` holds,
1406    /// the returned type is simply the provided self type `qself_ty`.
1407    ///
1408    /// A path like `A::B::C::D` is understood as `<A::B::C>::D`. I.e.,
1409    /// `qself_ty` / `qself` is `A::B::C` and `assoc_segment` is `D`.
1410    /// We return the lowered type and the `DefId` for the whole path.
1411    ///
1412    /// We only support associated type paths whose self type is a type parameter or a `Self`
1413    /// type alias (in a trait impl) like `T::Ty` (where `T` is a ty param) or `Self::Ty`.
1414    /// We **don't** support paths whose self type is an arbitrary type like `Struct::Ty` where
1415    /// struct `Struct` impls an in-scope trait that defines an associated type called `Ty`.
1416    /// For the latter case, we report ambiguity.
1417    /// While desirable to support, the implementation would be non-trivial. Tracked in [#22519].
1418    ///
1419    /// At the time of writing, *inherent associated types* are also resolved here. This however
1420    /// is [problematic][iat]. A proper implementation would be as non-trivial as the one
1421    /// described in the previous paragraph and their modeling of projections would likely be
1422    /// very similar in nature.
1423    ///
1424    /// [#22519]: https://github.com/rust-lang/rust/issues/22519
1425    /// [iat]: https://github.com/rust-lang/rust/issues/8995#issuecomment-1569208403
1426    //
1427    // NOTE: When this function starts resolving `Trait::AssocTy` successfully
1428    // it should also start reporting the `BARE_TRAIT_OBJECTS` lint.
1429    {}
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("lower_type_relative_ty_path",
                                "rustc_hir_analysis::hir_ty_lowering",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                ::tracing_core::__macro_support::Option::Some(1429u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                ::tracing_core::field::FieldSet::new(&[],
                                    ::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,
                    &{ meta.fields().value_set_all(&[]) })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[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:
                                Result<(Ty<'tcx>, DefKind, DefId), ErrorGuaranteed> =
                            loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        let tcx = self.tcx();
                        match self.lower_type_relative_path(self_ty, hir_self_ty,
                                    segment, qpath_hir_id, span,
                                    LowerTypeRelativePathMode::Type(permit_variants))? {
                            TypeRelativePath::AssocItem(alias_term) => {
                                let alias_ty = alias_term.expect_ty();
                                let def_id =
                                    match alias_ty.kind {
                                        ty::AliasTyKind::Projection { def_id } => def_id,
                                        ty::AliasTyKind::Inherent { def_id } => def_id,
                                        kind =>
                                            ::rustc_span::macros::bug_impl(None,
                                                format_args!("expected projection or inherent alias, got {0:?}",
                                                    kind), Location::caller()),
                                    };
                                let ty = alias_ty.to_ty(tcx, ty::IsRigid::No);
                                let ty = self.check_param_uses_if_mcg(ty, span, false);
                                Ok((ty, tcx.def_kind(def_id), def_id))
                            }
                            TypeRelativePath::Variant { adt, variant_did } => {
                                let adt = self.check_param_uses_if_mcg(adt, span, false);
                                Ok((adt, DefKind::Variant, variant_did))
                            }
                            TypeRelativePath::Ctor { .. } => {
                                let e =
                                    tcx.dcx().span_err(span,
                                        "expected type, found tuple constructor");
                                Err(e)
                            }
                        }
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1429",
                        "rustc_hir_analysis::hir_ty_lowering",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(1429u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip_all, ret)]
1430    pub fn lower_type_relative_ty_path(
1431        &self,
1432        self_ty: Ty<'tcx>,
1433        hir_self_ty: &hir::Ty<'_>,
1434        segment: &hir::PathSegment<'_>,
1435        qpath_hir_id: HirId,
1436        span: Span,
1437        permit_variants: PermitVariants,
1438    ) -> Result<(Ty<'tcx>, DefKind, DefId), ErrorGuaranteed> {
1439        let tcx = self.tcx();
1440        match self.lower_type_relative_path(
1441            self_ty,
1442            hir_self_ty,
1443            segment,
1444            qpath_hir_id,
1445            span,
1446            LowerTypeRelativePathMode::Type(permit_variants),
1447        )? {
1448            TypeRelativePath::AssocItem(alias_term) => {
1449                let alias_ty = alias_term.expect_ty();
1450                let def_id = match alias_ty.kind {
1451                    ty::AliasTyKind::Projection { def_id } => def_id,
1452                    ty::AliasTyKind::Inherent { def_id } => def_id,
1453                    kind => bug!("expected projection or inherent alias, got {kind:?}"),
1454                };
1455                let ty = alias_ty.to_ty(tcx, ty::IsRigid::No);
1456                let ty = self.check_param_uses_if_mcg(ty, span, false);
1457                Ok((ty, tcx.def_kind(def_id), def_id))
1458            }
1459            TypeRelativePath::Variant { adt, variant_did } => {
1460                let adt = self.check_param_uses_if_mcg(adt, span, false);
1461                Ok((adt, DefKind::Variant, variant_did))
1462            }
1463            TypeRelativePath::Ctor { .. } => {
1464                let e = tcx.dcx().span_err(span, "expected type, found tuple constructor");
1465                Err(e)
1466            }
1467        }
1468    }
1469
1470    /// Lower a [type-relative][hir::QPath::TypeRelative] path to a (type-level) constant.
1471    {}
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("lower_type_relative_const_path",
                                "rustc_hir_analysis::hir_ty_lowering",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                ::tracing_core::__macro_support::Option::Some(1471u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                ::tracing_core::field::FieldSet::new(&[],
                                    ::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,
                    &{ meta.fields().value_set_all(&[]) })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[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:
                                Result<Const<'tcx>, ErrorGuaranteed> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        let tcx = self.tcx();
                        match self.lower_type_relative_path(self_ty, hir_self_ty,
                                    segment, qpath_hir_id, span,
                                    LowerTypeRelativePathMode::Const)? {
                            TypeRelativePath::AssocItem(alias_term) => {
                                let alias_ct = alias_term.expect_ct();
                                self.check_const_item_in_type_system(alias_ct.kind, span)?;
                                let ct = Const::new_alias(tcx, ty::IsRigid::No, alias_ct);
                                let ct = self.check_param_uses_if_mcg(ct, span, false);
                                Ok(ct)
                            }
                            TypeRelativePath::Ctor { ctor_def_id, args } =>
                                match tcx.def_kind(ctor_def_id) {
                                    DefKind::Ctor(_, CtorKind::Fn) =>
                                        Ok(ty::Const::zero_sized(tcx,
                                                tcx.type_of(ctor_def_id).instantiate(tcx,
                                                        args).skip_norm_wip())),
                                    DefKind::Ctor(ctor_of, CtorKind::Const) => {
                                        Ok(self.construct_const_ctor_value(ctor_def_id, ctor_of,
                                                args))
                                    }
                                    _ => ::core::panicking::unreachable_default_msg(),
                                },
                            TypeRelativePath::Variant { .. } => {
                                ::rustc_span::macros::bug_impl(Some(span),
                                    format_args!("unexpected variant res for type associated const path"),
                                    Location::caller())
                            }
                        }
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1471",
                        "rustc_hir_analysis::hir_ty_lowering",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(1471u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip_all, ret)]
1472    fn lower_type_relative_const_path(
1473        &self,
1474        self_ty: Ty<'tcx>,
1475        hir_self_ty: &hir::Ty<'_>,
1476        segment: &hir::PathSegment<'_>,
1477        qpath_hir_id: HirId,
1478        span: Span,
1479    ) -> Result<Const<'tcx>, ErrorGuaranteed> {
1480        let tcx = self.tcx();
1481        match self.lower_type_relative_path(
1482            self_ty,
1483            hir_self_ty,
1484            segment,
1485            qpath_hir_id,
1486            span,
1487            LowerTypeRelativePathMode::Const,
1488        )? {
1489            TypeRelativePath::AssocItem(alias_term) => {
1490                let alias_ct = alias_term.expect_ct();
1491                self.check_const_item_in_type_system(alias_ct.kind, span)?;
1492                let ct = Const::new_alias(tcx, ty::IsRigid::No, alias_ct);
1493                let ct = self.check_param_uses_if_mcg(ct, span, false);
1494                Ok(ct)
1495            }
1496            TypeRelativePath::Ctor { ctor_def_id, args } => match tcx.def_kind(ctor_def_id) {
1497                DefKind::Ctor(_, CtorKind::Fn) => Ok(ty::Const::zero_sized(
1498                    tcx,
1499                    tcx.type_of(ctor_def_id).instantiate(tcx, args).skip_norm_wip(),
1500                )),
1501                DefKind::Ctor(ctor_of, CtorKind::Const) => {
1502                    Ok(self.construct_const_ctor_value(ctor_def_id, ctor_of, args))
1503                }
1504                _ => unreachable!(),
1505            },
1506            // FIXME(mgca): implement support for this once ready to support all adt ctor expressions,
1507            // not just const ctors
1508            TypeRelativePath::Variant { .. } => {
1509                span_bug!(span, "unexpected variant res for type associated const path")
1510            }
1511        }
1512    }
1513
1514    /// Lower a [type-relative][hir::QPath::TypeRelative] (and type-level) path.
1515    {}
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("lower_type_relative_path",
                                "rustc_hir_analysis::hir_ty_lowering",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                ::tracing_core::__macro_support::Option::Some(1515u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                ::tracing_core::field::FieldSet::new(&[],
                                    ::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,
                    &{ meta.fields().value_set_all(&[]) })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[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:
                                Result<TypeRelativePath<'tcx>, ErrorGuaranteed> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1525",
                                                "rustc_hir_analysis::hir_ty_lowering",
                                                ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                                ::tracing_core::__macro_support::Option::Some(1525u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("self_ty")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("self_ty");
                                                                    NAME.as_str()
                                                                },
                                                                {
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("segment.ident")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("segment.ident");
                                                                    NAME.as_str()
                                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                ::tracing::metadata::Kind::EVENT)
                                        };
                                    ::tracing::callsite::DefaultCallsite::new(&META)
                                };
                            let enabled =
                                ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                        ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::LevelFilter::current() &&
                                    {
                                        let interest = __CALLSITE.interest();
                                        !interest.is_never() &&
                                            ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                interest)
                                    };
                            if enabled {
                                (|value_set: ::tracing::field::ValueSet|
                                            {
                                                let meta = __CALLSITE.metadata();
                                                ::tracing::Event::dispatch(meta, &value_set);
                                                ;
                                            })({
                                        #[allow(unused_imports)]
                                        use ::tracing::field::{debug, display, Value};
                                        __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::display(&self_ty)
                                                                    as &dyn ::tracing::field::Value)),
                                                        (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&segment.ident)
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        let tcx = self.tcx();
                        let mut variant_def_id = None;
                        if let Some(adt_def) = self.probe_adt(span, self_ty) {
                            if adt_def.is_enum() {
                                let variant_def =
                                    adt_def.variants().iter().find(|vd|
                                            tcx.hygienic_eq(segment.ident, vd.ident(tcx),
                                                adt_def.did()));
                                if let Some(variant_def) = variant_def {
                                    if #[allow(non_exhaustive_omitted_patterns)] match mode {
                                                LowerTypeRelativePathMode::Const => true,
                                                _ => false,
                                            } && let Some((_, ctor_def_id)) = variant_def.ctor {
                                        tcx.check_stability(variant_def.def_id, Some(qpath_hir_id),
                                            span, None);
                                        let _ =
                                            self.prohibit_generic_args(slice::from_ref(segment).iter(),
                                                GenericsArgsErrExtend::EnumVariant {
                                                    qself: hir_self_ty,
                                                    assoc_segment: segment,
                                                    adt_def,
                                                });
                                        let ty::Adt(_, enum_args) =
                                            self_ty.kind() else {
                                                ::core::panicking::unreachable_default_msg()
                                            };
                                        return Ok(TypeRelativePath::Ctor {
                                                    ctor_def_id,
                                                    args: *enum_args,
                                                });
                                    }
                                    if let PermitVariants::Yes = mode.permit_variants() {
                                        tcx.check_stability(variant_def.def_id, Some(qpath_hir_id),
                                            span, None);
                                        let _ =
                                            self.prohibit_generic_args(slice::from_ref(segment).iter(),
                                                GenericsArgsErrExtend::EnumVariant {
                                                    qself: hir_self_ty,
                                                    assoc_segment: segment,
                                                    adt_def,
                                                });
                                        return Ok(TypeRelativePath::Variant {
                                                    adt: self_ty,
                                                    variant_did: variant_def.def_id,
                                                });
                                    } else { variant_def_id = Some(variant_def.def_id); }
                                }
                            }
                            if let Some(alias_term) =
                                    self.probe_inherent_assoc_item(segment, adt_def.did(),
                                            self_ty, qpath_hir_id, span, mode.assoc_tag())? {
                                return Ok(TypeRelativePath::AssocItem(alias_term));
                            }
                        }
                        let (item_def_id, bound) =
                            self.resolve_type_relative_path(self_ty, hir_self_ty,
                                    mode.assoc_tag(), segment, qpath_hir_id, span,
                                    variant_def_id)?;
                        let (item_def_id, args) =
                            self.lower_assoc_item_path(span, item_def_id, segment,
                                    bound)?;
                        if let Some(variant_def_id) = variant_def_id {
                            tcx.emit_node_span_lint(AMBIGUOUS_ASSOCIATED_ITEMS,
                                qpath_hir_id, span,
                                errors::AmbiguityBetweenVariantAndAssocItem {
                                    variant_def_id,
                                    item_def_id,
                                    span,
                                    segment_ident: segment.ident,
                                    bound_def_id: bound.def_id(),
                                    self_ty,
                                    tcx,
                                    mode,
                                });
                        }
                        let kind =
                            match mode {
                                LowerTypeRelativePathMode::Type(..) => {
                                    ty::AliasTermKind::ProjectionTy { def_id: item_def_id }
                                }
                                LowerTypeRelativePathMode::Const => {
                                    ty::AliasTermKind::ProjectionConst { def_id: item_def_id }
                                }
                            };
                        Ok(TypeRelativePath::AssocItem(ty::AliasTerm::new_from_args(tcx,
                                    kind, args)))
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1515",
                        "rustc_hir_analysis::hir_ty_lowering",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(1515u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip_all, ret)]
1516    fn lower_type_relative_path(
1517        &self,
1518        self_ty: Ty<'tcx>,
1519        hir_self_ty: &hir::Ty<'_>,
1520        segment: &hir::PathSegment<'_>,
1521        qpath_hir_id: HirId,
1522        span: Span,
1523        mode: LowerTypeRelativePathMode,
1524    ) -> Result<TypeRelativePath<'tcx>, ErrorGuaranteed> {
1525        debug!(%self_ty, ?segment.ident);
1526        let tcx = self.tcx();
1527
1528        // Check if we have an enum variant or an inherent associated type.
1529        let mut variant_def_id = None;
1530        if let Some(adt_def) = self.probe_adt(span, self_ty) {
1531            if adt_def.is_enum() {
1532                let variant_def = adt_def
1533                    .variants()
1534                    .iter()
1535                    .find(|vd| tcx.hygienic_eq(segment.ident, vd.ident(tcx), adt_def.did()));
1536                if let Some(variant_def) = variant_def {
1537                    // FIXME(mgca): do we want constructor resolutions to take priority over
1538                    // other possible resolutions?
1539                    if matches!(mode, LowerTypeRelativePathMode::Const)
1540                        && let Some((_, ctor_def_id)) = variant_def.ctor
1541                    {
1542                        tcx.check_stability(variant_def.def_id, Some(qpath_hir_id), span, None);
1543                        let _ = self.prohibit_generic_args(
1544                            slice::from_ref(segment).iter(),
1545                            GenericsArgsErrExtend::EnumVariant {
1546                                qself: hir_self_ty,
1547                                assoc_segment: segment,
1548                                adt_def,
1549                            },
1550                        );
1551                        let ty::Adt(_, enum_args) = self_ty.kind() else { unreachable!() };
1552                        return Ok(TypeRelativePath::Ctor { ctor_def_id, args: *enum_args });
1553                    }
1554                    if let PermitVariants::Yes = mode.permit_variants() {
1555                        tcx.check_stability(variant_def.def_id, Some(qpath_hir_id), span, None);
1556                        let _ = self.prohibit_generic_args(
1557                            slice::from_ref(segment).iter(),
1558                            GenericsArgsErrExtend::EnumVariant {
1559                                qself: hir_self_ty,
1560                                assoc_segment: segment,
1561                                adt_def,
1562                            },
1563                        );
1564                        return Ok(TypeRelativePath::Variant {
1565                            adt: self_ty,
1566                            variant_did: variant_def.def_id,
1567                        });
1568                    } else {
1569                        variant_def_id = Some(variant_def.def_id);
1570                    }
1571                }
1572            }
1573
1574            // FIXME(inherent_associated_types, #106719): Support self types other than ADTs.
1575            if let Some(alias_term) = self.probe_inherent_assoc_item(
1576                segment,
1577                adt_def.did(),
1578                self_ty,
1579                qpath_hir_id,
1580                span,
1581                mode.assoc_tag(),
1582            )? {
1583                return Ok(TypeRelativePath::AssocItem(alias_term));
1584            }
1585        }
1586
1587        let (item_def_id, bound) = self.resolve_type_relative_path(
1588            self_ty,
1589            hir_self_ty,
1590            mode.assoc_tag(),
1591            segment,
1592            qpath_hir_id,
1593            span,
1594            variant_def_id,
1595        )?;
1596
1597        let (item_def_id, args) = self.lower_assoc_item_path(span, item_def_id, segment, bound)?;
1598
1599        if let Some(variant_def_id) = variant_def_id {
1600            tcx.emit_node_span_lint(
1601                AMBIGUOUS_ASSOCIATED_ITEMS,
1602                qpath_hir_id,
1603                span,
1604                errors::AmbiguityBetweenVariantAndAssocItem {
1605                    variant_def_id,
1606                    item_def_id,
1607                    span,
1608                    segment_ident: segment.ident,
1609                    bound_def_id: bound.def_id(),
1610                    self_ty,
1611                    tcx,
1612                    mode,
1613                },
1614            );
1615        }
1616
1617        let kind = match mode {
1618            LowerTypeRelativePathMode::Type(..) => {
1619                ty::AliasTermKind::ProjectionTy { def_id: item_def_id }
1620            }
1621            LowerTypeRelativePathMode::Const => {
1622                ty::AliasTermKind::ProjectionConst { def_id: item_def_id }
1623            }
1624        };
1625
1626        Ok(TypeRelativePath::AssocItem(ty::AliasTerm::new_from_args(tcx, kind, args)))
1627    }
1628
1629    /// Resolve a [type-relative](hir::QPath::TypeRelative) (and type-level) path.
1630    fn resolve_type_relative_path(
1631        &self,
1632        self_ty: Ty<'tcx>,
1633        hir_self_ty: &hir::Ty<'_>,
1634        assoc_tag: ty::AssocTag,
1635        segment: &hir::PathSegment<'_>,
1636        qpath_hir_id: HirId,
1637        span: Span,
1638        variant_def_id: Option<DefId>,
1639    ) -> Result<(DefId, ty::PolyTraitRef<'tcx>), ErrorGuaranteed> {
1640        let tcx = self.tcx();
1641
1642        let self_ty_res = match hir_self_ty.kind {
1643            hir::TyKind::Path(hir::QPath::Resolved(_, path)) => path.res,
1644            _ => Res::Err,
1645        };
1646
1647        // Find the type of the assoc item, and the trait where the associated item is declared.
1648        let bound = match (self_ty.kind(), self_ty_res) {
1649            (_, Res::SelfTyAlias { alias_to: impl_def_id, is_trait_impl: true, .. }) => {
1650                // `Self` in an impl of a trait -- we have a concrete self type and a
1651                // trait reference.
1652                let trait_ref = tcx.impl_trait_ref(impl_def_id);
1653
1654                self.probe_single_bound_for_assoc_item(
1655                    || {
1656                        let trait_ref =
1657                            ty::Binder::dummy(trait_ref.instantiate_identity().skip_norm_wip());
1658                        traits::supertraits(tcx, trait_ref)
1659                    },
1660                    AssocItemQSelf::SelfTyAlias,
1661                    assoc_tag,
1662                    segment.ident,
1663                    span,
1664                    None,
1665                )?
1666            }
1667            (
1668                &ty::Param(_),
1669                Res::SelfTyParam { trait_: param_did } | Res::Def(DefKind::TyParam, param_did),
1670            ) => self.probe_single_ty_param_bound_for_assoc_item(
1671                param_did.expect_local(),
1672                hir_self_ty.span,
1673                assoc_tag,
1674                segment.ident,
1675                span,
1676            )?,
1677            _ => {
1678                return Err(self.report_unresolved_type_relative_path(
1679                    self_ty,
1680                    hir_self_ty,
1681                    assoc_tag,
1682                    segment.ident,
1683                    qpath_hir_id,
1684                    span,
1685                    variant_def_id,
1686                ));
1687            }
1688        };
1689
1690        let assoc_item = self
1691            .probe_assoc_item(segment.ident, assoc_tag, qpath_hir_id, span, bound.def_id())
1692            .expect("failed to find associated item");
1693
1694        Ok((assoc_item.def_id, bound))
1695    }
1696
1697    /// Search for inherent associated items for use at the type level.
1698    fn probe_inherent_assoc_item(
1699        &self,
1700        segment: &hir::PathSegment<'_>,
1701        adt_did: DefId,
1702        self_ty: Ty<'tcx>,
1703        block: HirId,
1704        span: Span,
1705        assoc_tag: ty::AssocTag,
1706    ) -> Result<Option<ty::AliasTerm<'tcx>>, ErrorGuaranteed> {
1707        let tcx = self.tcx();
1708
1709        if !tcx.features().inherent_associated_types() {
1710            match assoc_tag {
1711                // Don't attempt to look up inherent associated types when the feature is not
1712                // enabled. Theoretically it'd be fine to do so since we feature-gate their
1713                // definition site. However, the current implementation of inherent associated
1714                // items is somewhat brittle, so let's not run it by default.
1715                ty::AssocTag::Type => return Ok(None),
1716                ty::AssocTag::Const => {
1717                    // We also gate the mgca codepath for type-level uses of inherent consts
1718                    // with the inherent_associated_types feature gate since it relies on the
1719                    // same machinery and has similar rough edges.
1720                    return Err(feature_err(
1721                        &tcx.sess,
1722                        sym::inherent_associated_types,
1723                        span,
1724                        "inherent associated types are unstable",
1725                    )
1726                    .emit_err());
1727                }
1728                ty::AssocTag::Fn => ::core::panicking::unreachable_default_msg()unreachable!(),
1729            }
1730        }
1731
1732        let name = segment.ident;
1733        let candidates: Vec<_> = tcx
1734            .inherent_impls(adt_did)
1735            .iter()
1736            .filter_map(|&impl_| {
1737                let (item, scope) = self.probe_assoc_item_unchecked(name, assoc_tag, impl_)?;
1738                Some(InherentAssocCandidate { impl_, assoc_item: item.def_id, scope })
1739            })
1740            .collect();
1741
1742        // At the moment, we actually bail out with a hard error if the selection of an inherent
1743        // associated item fails (see below). This means we never consider trait associated items
1744        // as potential fallback candidates (#142006). To temporarily mask that issue, let's not
1745        // select at all if there are no early inherent candidates.
1746        if candidates.is_empty() {
1747            return Ok(None);
1748        }
1749
1750        let (applicable_candidates, fulfillment_errors) =
1751            self.select_inherent_assoc_candidates(span, self_ty, candidates.clone());
1752
1753        // FIXME(#142006): Don't eagerly error here, there might be applicable trait candidates.
1754        let InherentAssocCandidate { impl_, assoc_item, scope: def_scope } =
1755            match &applicable_candidates[..] {
1756                &[] => Err(self.report_unresolved_inherent_assoc_item(
1757                    name,
1758                    self_ty,
1759                    candidates,
1760                    fulfillment_errors,
1761                    span,
1762                    assoc_tag,
1763                )),
1764
1765                &[applicable_candidate] => Ok(applicable_candidate),
1766
1767                &[_, ..] => Err(self.report_ambiguous_inherent_assoc_item(
1768                    name,
1769                    candidates.into_iter().map(|cand| cand.assoc_item).collect(),
1770                    span,
1771                )),
1772            }?;
1773
1774        // FIXME(#142006): Don't eagerly validate here, there might be trait candidates that are
1775        // accessible (visible and stable) contrary to the inherent candidate.
1776        self.check_assoc_item(assoc_item, name, def_scope, block, span);
1777
1778        // FIXME(fmease): Currently creating throwaway `parent_args` to please
1779        // `lower_generic_args_of_assoc_item`. Modify the latter instead (or sth. similar) to
1780        // not require the parent args logic.
1781        let parent_args = ty::GenericArgs::identity_for_item(tcx, impl_);
1782        let args = self.lower_generic_args_of_assoc_item(span, assoc_item, segment, parent_args);
1783        let args = tcx.mk_args_from_iter(
1784            std::iter::once(ty::GenericArg::from(self_ty))
1785                .chain(args.into_iter().skip(parent_args.len())),
1786        );
1787
1788        let kind = match assoc_tag {
1789            ty::AssocTag::Type => ty::AliasTermKind::InherentTy { def_id: assoc_item },
1790            ty::AssocTag::Const => ty::AliasTermKind::InherentConstSelf { def_id: assoc_item },
1791            ty::AssocTag::Fn => ::core::panicking::unreachable_default_msg()unreachable!(),
1792        };
1793
1794        Ok(Some(ty::AliasTerm::new_from_args(tcx, kind, args)))
1795    }
1796
1797    /// Given name and kind search for the assoc item in the provided scope and check if it's accessible[^1].
1798    ///
1799    /// [^1]: I.e., accessible in the provided scope wrt. visibility and stability.
1800    fn probe_assoc_item(
1801        &self,
1802        ident: Ident,
1803        assoc_tag: ty::AssocTag,
1804        block: HirId,
1805        span: Span,
1806        scope: DefId,
1807    ) -> Option<ty::AssocItem> {
1808        let (item, scope) = self.probe_assoc_item_unchecked(ident, assoc_tag, scope)?;
1809        self.check_assoc_item(item.def_id, ident, scope, block, span);
1810        Some(item)
1811    }
1812
1813    /// Given name and kind search for the assoc item in the provided scope
1814    /// *without* checking if it's accessible[^1].
1815    ///
1816    /// [^1]: I.e., accessible in the provided scope wrt. visibility and stability.
1817    fn probe_assoc_item_unchecked(
1818        &self,
1819        ident: Ident,
1820        assoc_tag: ty::AssocTag,
1821        scope: DefId,
1822    ) -> Option<(ty::AssocItem, /*scope*/ ModId)> {
1823        let tcx = self.tcx();
1824
1825        let (ident, def_scope) = tcx.adjust_ident_and_get_scope(ident, scope, self.mod_id());
1826        // We have already adjusted the item name above, so compare with `.normalize_to_macros_2_0()`
1827        // instead of calling `filter_by_name_and_kind` which would needlessly normalize the
1828        // `ident` again and again.
1829        let item = tcx
1830            .associated_items(scope)
1831            .filter_by_name_unhygienic(ident.name)
1832            .find(|i| i.tag() == assoc_tag && i.ident(tcx).normalize_to_macros_2_0() == ident)?;
1833
1834        Some((*item, def_scope))
1835    }
1836
1837    /// Check if the given assoc item is accessible in the provided scope wrt. visibility and stability.
1838    fn check_assoc_item(
1839        &self,
1840        item_def_id: DefId,
1841        ident: Ident,
1842        scope: ModId,
1843        block: HirId,
1844        span: Span,
1845    ) {
1846        let tcx = self.tcx();
1847
1848        if !tcx.visibility(item_def_id).is_accessible_from(scope, tcx) {
1849            self.dcx().emit_err(crate::diagnostics::AssocItemIsPrivate {
1850                span,
1851                kind: tcx.def_descr(item_def_id),
1852                name: ident,
1853                defined_here_label: tcx.def_span(item_def_id),
1854            });
1855        }
1856
1857        tcx.check_stability(item_def_id, Some(block), span, None);
1858    }
1859
1860    fn probe_traits_that_match_assoc_ty(
1861        &self,
1862        qself_ty: Ty<'tcx>,
1863        assoc_ident: Ident,
1864    ) -> Vec<String> {
1865        let tcx = self.tcx();
1866
1867        // In contexts that have no inference context, just make a new one.
1868        // We do need a local variable to store it, though.
1869        let infcx_;
1870        let infcx = if let Some(infcx) = self.infcx() {
1871            infcx
1872        } else {
1873            if !!qself_ty.has_infer() {
    ::core::panicking::panic("assertion failed: !qself_ty.has_infer()")
};assert!(!qself_ty.has_infer());
1874            infcx_ = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
1875            &infcx_
1876        };
1877
1878        tcx.all_traits_including_private()
1879            .filter(|trait_def_id| {
1880                // Consider only traits with the associated type
1881                tcx.associated_items(*trait_def_id)
1882                        .in_definition_order()
1883                        .any(|i| {
1884                            i.is_type()
1885                                && !i.is_impl_trait_in_trait()
1886                                && i.ident(tcx).normalize_to_macros_2_0() == assoc_ident
1887                        })
1888                    // Consider only accessible traits
1889                    && tcx.visibility(*trait_def_id)
1890                        .is_accessible_from(self.mod_id(), tcx)
1891                    && tcx.all_impls(*trait_def_id)
1892                        .any(|impl_def_id| {
1893                            let header = tcx.impl_trait_header(impl_def_id);
1894                            let trait_ref = header.trait_ref.instantiate(tcx, infcx.fresh_args_for_item(DUMMY_SP, impl_def_id)).skip_norm_wip();
1895
1896                            let value = fold_regions(tcx, qself_ty, |_, _| tcx.lifetimes.re_erased);
1897                            // FIXME: Don't bother dealing with non-lifetime binders here...
1898                            if value.has_escaping_bound_vars() {
1899                                return false;
1900                            }
1901                            infcx
1902                                .can_eq(
1903                                    ty::ParamEnv::empty(),
1904                                    trait_ref.self_ty(),
1905                                    value,
1906                                ) && header.polarity != ty::ImplPolarity::Negative
1907                        })
1908            })
1909            .map(|trait_def_id| tcx.def_path_str(trait_def_id))
1910            .collect()
1911    }
1912
1913    /// Lower a [resolved][hir::QPath::Resolved] associated type path to a projection.
1914    {}
#[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("lower_resolved_assoc_ty_path",
                                    "rustc_hir_analysis::hir_ty_lowering",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1914u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                    ::tracing_core::field::FieldSet::new(&[],
                                        ::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,
                        &{ meta.fields().value_set_all(&[]) })
                } 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: Ty<'tcx> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            match self.lower_resolved_assoc_item_path(span, opt_self_ty,
                    item_def_id, trait_segment, item_segment,
                    ty::AssocTag::Type) {
                Ok((item_def_id, item_args)) => {
                    Ty::new_projection_from_args(self.tcx(), ty::IsRigid::No,
                        item_def_id, item_args)
                }
                Err(guar) => Ty::new_error(self.tcx(), guar),
            }
        }
    }
}#[instrument(level = "debug", skip_all)]
1915    fn lower_resolved_assoc_ty_path(
1916        &self,
1917        span: Span,
1918        opt_self_ty: Option<Ty<'tcx>>,
1919        item_def_id: DefId,
1920        trait_segment: Option<&hir::PathSegment<'_>>,
1921        item_segment: &hir::PathSegment<'_>,
1922    ) -> Ty<'tcx> {
1923        match self.lower_resolved_assoc_item_path(
1924            span,
1925            opt_self_ty,
1926            item_def_id,
1927            trait_segment,
1928            item_segment,
1929            ty::AssocTag::Type,
1930        ) {
1931            Ok((item_def_id, item_args)) => {
1932                Ty::new_projection_from_args(self.tcx(), ty::IsRigid::No, item_def_id, item_args)
1933            }
1934            Err(guar) => Ty::new_error(self.tcx(), guar),
1935        }
1936    }
1937
1938    /// Lower a [resolved][hir::QPath::Resolved] associated const path to a (type-level) constant.
1939    {}
#[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("lower_resolved_assoc_const_path",
                                    "rustc_hir_analysis::hir_ty_lowering",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1939u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                    ::tracing_core::field::FieldSet::new(&[],
                                        ::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,
                        &{ meta.fields().value_set_all(&[]) })
                } 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:
                    Result<Const<'tcx>, ErrorGuaranteed> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let tcx = self.tcx();
            let (item_def_id, item_args) =
                self.lower_resolved_assoc_item_path(span, opt_self_ty,
                        item_def_id, trait_segment, item_segment,
                        ty::AssocTag::Const)?;
            let kind = ty::AliasConstKind::Projection { def_id: item_def_id };
            self.check_const_item_in_type_system(kind, span)?;
            let alias = ty::AliasConst::new(tcx, kind, item_args);
            Ok(Const::new_alias(tcx, ty::IsRigid::No, alias))
        }
    }
}#[instrument(level = "debug", skip_all)]
1940    fn lower_resolved_assoc_const_path(
1941        &self,
1942        span: Span,
1943        opt_self_ty: Option<Ty<'tcx>>,
1944        item_def_id: DefId,
1945        trait_segment: Option<&hir::PathSegment<'_>>,
1946        item_segment: &hir::PathSegment<'_>,
1947    ) -> Result<Const<'tcx>, ErrorGuaranteed> {
1948        let tcx = self.tcx();
1949        let (item_def_id, item_args) = self.lower_resolved_assoc_item_path(
1950            span,
1951            opt_self_ty,
1952            item_def_id,
1953            trait_segment,
1954            item_segment,
1955            ty::AssocTag::Const,
1956        )?;
1957        let kind = ty::AliasConstKind::Projection { def_id: item_def_id };
1958        self.check_const_item_in_type_system(kind, span)?;
1959        let alias = ty::AliasConst::new(tcx, kind, item_args);
1960        Ok(Const::new_alias(tcx, ty::IsRigid::No, alias))
1961    }
1962
1963    /// Lower a [resolved][hir::QPath::Resolved] (type-level) associated item path.
1964    {}
#[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("lower_resolved_assoc_item_path",
                                    "rustc_hir_analysis::hir_ty_lowering",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1964u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                    ::tracing_core::field::FieldSet::new(&[],
                                        ::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,
                        &{ meta.fields().value_set_all(&[]) })
                } 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:
                    Result<(DefId, ty::GenericArgs<'tcx>), ErrorGuaranteed> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            let tcx = self.tcx();
            let trait_def_id = tcx.parent(item_def_id);
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1977",
                                    "rustc_hir_analysis::hir_ty_lowering",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1977u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("trait_def_id")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("trait_def_id");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_def_id)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            let Some(self_ty) =
                opt_self_ty else {
                    return Err(self.report_missing_self_ty_for_resolved_path(trait_def_id,
                                span, item_segment, assoc_tag));
                };
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1987",
                                    "rustc_hir_analysis::hir_ty_lowering",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1987u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("self_ty")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("self_ty");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            let trait_ref =
                self.lower_mono_trait_ref(span, trait_def_id, self_ty,
                    trait_segment.unwrap(), false);
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1991",
                                    "rustc_hir_analysis::hir_ty_lowering",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1991u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("trait_ref")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("trait_ref");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_ref)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            let item_args =
                self.lower_generic_args_of_assoc_item(span, item_def_id,
                    item_segment, trait_ref.args);
            Ok((item_def_id, item_args))
        }
    }
}#[instrument(level = "debug", skip_all)]
1965    fn lower_resolved_assoc_item_path(
1966        &self,
1967        span: Span,
1968        opt_self_ty: Option<Ty<'tcx>>,
1969        item_def_id: DefId,
1970        trait_segment: Option<&hir::PathSegment<'_>>,
1971        item_segment: &hir::PathSegment<'_>,
1972        assoc_tag: ty::AssocTag,
1973    ) -> Result<(DefId, ty::GenericArgs<'tcx>), ErrorGuaranteed> {
1974        let tcx = self.tcx();
1975
1976        let trait_def_id = tcx.parent(item_def_id);
1977        debug!(?trait_def_id);
1978
1979        let Some(self_ty) = opt_self_ty else {
1980            return Err(self.report_missing_self_ty_for_resolved_path(
1981                trait_def_id,
1982                span,
1983                item_segment,
1984                assoc_tag,
1985            ));
1986        };
1987        debug!(?self_ty);
1988
1989        let trait_ref =
1990            self.lower_mono_trait_ref(span, trait_def_id, self_ty, trait_segment.unwrap(), false);
1991        debug!(?trait_ref);
1992
1993        let item_args =
1994            self.lower_generic_args_of_assoc_item(span, item_def_id, item_segment, trait_ref.args);
1995
1996        Ok((item_def_id, item_args))
1997    }
1998
1999    pub fn prohibit_generic_args<'a>(
2000        &self,
2001        segments: impl Iterator<Item = &'a hir::PathSegment<'a>> + Clone,
2002        err_extend: GenericsArgsErrExtend<'a>,
2003    ) -> Result<(), ErrorGuaranteed> {
2004        let args_visitors = segments.clone().flat_map(|segment| segment.args().args);
2005        let mut result = Ok(());
2006        if let Some(_) = args_visitors.clone().next() {
2007            result = Err(self.report_prohibited_generic_args(
2008                segments.clone(),
2009                args_visitors,
2010                err_extend,
2011            ));
2012        }
2013
2014        for segment in segments {
2015            // Only emit the first error to avoid overloading the user with error messages.
2016            if let Some(c) = segment.args().constraints.first() {
2017                return Err(prohibit_assoc_item_constraint(self, c, None));
2018            }
2019        }
2020
2021        result
2022    }
2023
2024    /// Probe path segments that are semantically allowed to have generic arguments.
2025    ///
2026    /// ### Example
2027    ///
2028    /// ```ignore (illustrative)
2029    ///    Option::None::<()>
2030    /// //         ^^^^ permitted to have generic args
2031    ///
2032    /// // ==> [GenericPathSegment(Option_def_id, 1)]
2033    ///
2034    ///    Option::<()>::None
2035    /// // ^^^^^^        ^^^^ *not* permitted to have generic args
2036    /// // permitted to have generic args
2037    ///
2038    /// // ==> [GenericPathSegment(Option_def_id, 0)]
2039    /// ```
2040    // FIXME(eddyb, varkor) handle type paths here too, not just value ones.
2041    pub fn probe_generic_path_segments(
2042        &self,
2043        segments: &[hir::PathSegment<'_>],
2044        self_ty: Option<Ty<'tcx>>,
2045        kind: DefKind,
2046        def_id: DefId,
2047        span: Span,
2048    ) -> Vec<GenericPathSegment> {
2049        // We need to extract the generic arguments supplied by the user in
2050        // the path `path`. Due to the current setup, this is a bit of a
2051        // tricky process; the problem is that resolve only tells us the
2052        // end-point of the path resolution, and not the intermediate steps.
2053        // Luckily, we can (at least for now) deduce the intermediate steps
2054        // just from the end-point.
2055        //
2056        // There are basically five cases to consider:
2057        //
2058        // 1. Reference to a constructor of a struct:
2059        //
2060        //        struct Foo<T>(...)
2061        //
2062        //    In this case, the generic arguments are declared in the type space.
2063        //
2064        // 2. Reference to a constructor of an enum variant:
2065        //
2066        //        enum E<T> { Foo(...) }
2067        //
2068        //    In this case, the generic arguments are defined in the type space,
2069        //    but may be specified either on the type or the variant.
2070        //
2071        // 3. Reference to a free function or constant:
2072        //
2073        //        fn foo<T>() {}
2074        //
2075        //    In this case, the path will again always have the form
2076        //    `a::b::foo::<T>` where only the final segment should have generic
2077        //    arguments. However, in this case, those arguments are declared on
2078        //    a value, and hence are in the value space.
2079        //
2080        // 4. Reference to an associated function or constant:
2081        //
2082        //        impl<A> SomeStruct<A> {
2083        //            fn foo<B>(...) {}
2084        //        }
2085        //
2086        //    Here we can have a path like `a::b::SomeStruct::<A>::foo::<B>`,
2087        //    in which case generic arguments may appear in two places. The
2088        //    penultimate segment, `SomeStruct::<A>`, contains generic arguments
2089        //    in the type space, and the final segment, `foo::<B>` contains
2090        //    generic arguments in value space.
2091        //
2092        // The first step then is to categorize the segments appropriately.
2093
2094        let tcx = self.tcx();
2095
2096        if !!segments.is_empty() {
    ::core::panicking::panic("assertion failed: !segments.is_empty()")
};assert!(!segments.is_empty());
2097        let last = segments.len() - 1;
2098
2099        let mut generic_segments = ::alloc::vec::Vec::new()vec![];
2100
2101        match kind {
2102            // Case 1. Reference to a struct constructor.
2103            DefKind::Ctor(CtorOf::Struct, ..) => {
2104                // Everything but the final segment should have no
2105                // parameters at all.
2106                let generics = tcx.generics_of(def_id);
2107                // Variant and struct constructors use the
2108                // generics of their parent type definition.
2109                let generics_def_id = generics.parent.unwrap_or(def_id);
2110                generic_segments.push(GenericPathSegment(generics_def_id, last));
2111            }
2112
2113            // Case 2. Reference to a variant constructor.
2114            DefKind::Ctor(CtorOf::Variant, ..) | DefKind::Variant => {
2115                let (generics_def_id, index) = if let Some(self_ty) = self_ty {
2116                    // We have something like `<module::Enum>::Variant`.
2117
2118                    let adt_def = self.probe_adt(span, self_ty).unwrap();
2119                    if true {
    if !adt_def.is_enum() {
        ::core::panicking::panic("assertion failed: adt_def.is_enum()")
    };
};debug_assert!(adt_def.is_enum());
2120
2121                    // FIXME: Stating that the last segment (here: `Variant`) is allowed to have
2122                    // generic args is a lie! We should set the index to `None` instead as it's
2123                    // the *self type* that's allowed to have args.
2124                    // HIR typeck's `instantiate_value_path` actually contains a special case to
2125                    // reject args on `DefKind::Ctor` segments (see `is_alias_variant_ctor`).
2126                    // Using `None` here for this should allow us to get rid of that workaround.
2127                    //
2128                    // (For additional context, `DefKind::Variant` segments never actually reach
2129                    // this branch as they're interpreted as `TypeRelative` paths whose lowering
2130                    // routines manually reject args on them).
2131
2132                    (adt_def.did(), last)
2133                } else if let [.., second_to_last, _] = segments
2134                    && second_to_last.args.is_some()
2135                    && let Res::Def(DefKind::Enum, _) = second_to_last.res
2136                {
2137                    // We have something like `module::Enum::<…>::Variant`.
2138                    // No segment other than the penultimate one is allowed to have generic args.
2139
2140                    // We had to check that the second to last segment actually referred to an enum
2141                    // since at this stage it could very well refer to a module in which case we
2142                    // certainly don't want to allow generic args on it!
2143
2144                    // `DefKind::Ctor` -> `DefKind::Variant`
2145                    let def_id = match kind {
2146                        DefKind::Ctor(..) => tcx.parent(def_id),
2147                        _ => def_id,
2148                    };
2149
2150                    // `DefKind::Variant` -> `DefKind::Enum`
2151                    let enum_def_id = tcx.parent(def_id);
2152
2153                    (enum_def_id, last - 1)
2154                } else {
2155                    // We have something like `module::Enum::Variant` or `module::Variant`.
2156                    // No segment other than the final one is allowed to have generic args.
2157
2158                    // FIXME: lint here recommending `Enum::<...>::Variant` form
2159                    // instead of `Enum::Variant::<...>` form.
2160
2161                    let generics = tcx.generics_of(def_id);
2162                    // Variant and struct constructors use the
2163                    // generics of their parent type definition.
2164                    (generics.parent.unwrap_or(def_id), last)
2165                };
2166                generic_segments.push(GenericPathSegment(generics_def_id, index));
2167            }
2168
2169            // Case 3. Reference to a top-level value.
2170            DefKind::Fn | DefKind::Const | DefKind::ConstParam | DefKind::Static { .. } => {
2171                generic_segments.push(GenericPathSegment(def_id, last));
2172            }
2173
2174            // Case 4. Reference to a method or associated const.
2175            DefKind::AssocFn | DefKind::AssocConst => {
2176                if segments.len() >= 2 {
2177                    let generics = tcx.generics_of(def_id);
2178                    generic_segments.push(GenericPathSegment(generics.parent.unwrap(), last - 1));
2179                }
2180                generic_segments.push(GenericPathSegment(def_id, last));
2181            }
2182
2183            kind => ::rustc_span::macros::bug_impl(None,
    format_args!("unexpected definition kind {0:?} for {1:?}", kind, def_id),
    Location::caller())bug!("unexpected definition kind {:?} for {:?}", kind, def_id),
2184        }
2185
2186        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:2186",
                        "rustc_hir_analysis::hir_ty_lowering",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(2186u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("generic_segments")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("generic_segments");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&generic_segments)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?generic_segments);
2187
2188        generic_segments
2189    }
2190
2191    /// Lower a [resolved][hir::QPath::Resolved] path to a type.
2192    {}
#[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("lower_resolved_ty_path",
                                    "rustc_hir_analysis::hir_ty_lowering",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(2192u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                    ::tracing_core::field::FieldSet::new(&[],
                                        ::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,
                        &{ meta.fields().value_set_all(&[]) })
                } 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: Ty<'tcx> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:2200",
                                    "rustc_hir_analysis::hir_ty_lowering",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(2200u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("path.res")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("path.res");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("opt_self_ty")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("opt_self_ty");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("path.segments")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("path.segments");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&path.res)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&opt_self_ty)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&path.segments)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            let tcx = self.tcx();
            let span = path.span;
            match path.res {
                Res::Def(DefKind::OpaqueTy, did) => {
                    {
                        match tcx.opaque_ty_origin(did) {
                            hir::OpaqueTyOrigin::TyAlias { .. } => {}
                            ref left_val => {
                                ::core::panicking::assert_matches_failed(left_val,
                                    "hir::OpaqueTyOrigin::TyAlias { .. }",
                                    ::core::option::Option::None);
                            }
                        }
                    };
                    let [leading_segments @ .., segment] =
                        path.segments else {
                            ::rustc_span::macros::bug_impl(None,
                                format_args!("impossible case reached"), Location::caller())
                        };
                    let _ =
                        self.prohibit_generic_args(leading_segments.iter(),
                            GenericsArgsErrExtend::OpaqueTy);
                    let args =
                        self.lower_generic_args_of_path_segment(span, did, segment);
                    Ty::new_opaque(tcx, ty::IsRigid::No, did, args)
                }
                Res::Def(DefKind::Enum | DefKind::TyAlias | DefKind::Struct |
                    DefKind::Union | DefKind::ForeignTy, did) => {
                    {
                        match (&opt_self_ty, &None) {
                            (left_val, right_val) => {
                                if !(*left_val == *right_val) {
                                    let kind = ::core::panicking::AssertKind::Eq;
                                    ::core::panicking::assert_failed(kind, &*left_val,
                                        &*right_val, ::core::option::Option::None);
                                }
                            }
                        }
                    };
                    let [leading_segments @ .., segment] =
                        path.segments else {
                            ::rustc_span::macros::bug_impl(None,
                                format_args!("impossible case reached"), Location::caller())
                        };
                    let _ =
                        self.prohibit_generic_args(leading_segments.iter(),
                            GenericsArgsErrExtend::None);
                    self.lower_path_segment(span, did, segment)
                }
                Res::Def(kind @ DefKind::Variant, def_id) if
                    let PermitVariants::Yes = permit_variants => {
                    {
                        match (&opt_self_ty, &None) {
                            (left_val, right_val) => {
                                if !(*left_val == *right_val) {
                                    let kind = ::core::panicking::AssertKind::Eq;
                                    ::core::panicking::assert_failed(kind, &*left_val,
                                        &*right_val, ::core::option::Option::None);
                                }
                            }
                        }
                    };
                    let generic_segments =
                        self.probe_generic_path_segments(path.segments, None, kind,
                            def_id, span);
                    let indices: FxHashSet<_> =
                        generic_segments.iter().map(|GenericPathSegment(_, index)|
                                    index).collect();
                    let _ =
                        self.prohibit_generic_args(path.segments.iter().enumerate().filter_map(|(index,
                                        seg)|
                                    {
                                        if !indices.contains(&index) { Some(seg) } else { None }
                                    }), GenericsArgsErrExtend::DefVariant(&path.segments));
                    let &GenericPathSegment(def_id, index) =
                        generic_segments.last().unwrap();
                    self.lower_path_segment(span, def_id, &path.segments[index])
                }
                Res::Def(DefKind::TyParam, def_id) => {
                    {
                        match (&opt_self_ty, &None) {
                            (left_val, right_val) => {
                                if !(*left_val == *right_val) {
                                    let kind = ::core::panicking::AssertKind::Eq;
                                    ::core::panicking::assert_failed(kind, &*left_val,
                                        &*right_val, ::core::option::Option::None);
                                }
                            }
                        }
                    };
                    let _ =
                        self.prohibit_generic_args(path.segments.iter(),
                            GenericsArgsErrExtend::Param(def_id));
                    self.lower_ty_param(hir_id)
                }
                Res::SelfTyParam { .. } => {
                    {
                        match (&opt_self_ty, &None) {
                            (left_val, right_val) => {
                                if !(*left_val == *right_val) {
                                    let kind = ::core::panicking::AssertKind::Eq;
                                    ::core::panicking::assert_failed(kind, &*left_val,
                                        &*right_val, ::core::option::Option::None);
                                }
                            }
                        }
                    };
                    let _ =
                        self.prohibit_generic_args(path.segments.iter(),
                            if let [hir::PathSegment { args: Some(args), ident, .. }] =
                                    &path.segments {
                                GenericsArgsErrExtend::SelfTyParam(ident.span.shrink_to_hi().to(args.span_ext))
                            } else { GenericsArgsErrExtend::None });
                    self.check_param_uses_if_mcg(tcx.types.self_param, span,
                        false)
                }
                Res::SelfTyAlias { alias_to: def_id, .. } => {
                    {
                        match (&opt_self_ty, &None) {
                            (left_val, right_val) => {
                                if !(*left_val == *right_val) {
                                    let kind = ::core::panicking::AssertKind::Eq;
                                    ::core::panicking::assert_failed(kind, &*left_val,
                                        &*right_val, ::core::option::Option::None);
                                }
                            }
                        }
                    };
                    let ty =
                        tcx.at(span).type_of(def_id).instantiate_identity().skip_norm_wip();
                    let _ =
                        self.prohibit_generic_args(path.segments.iter(),
                            GenericsArgsErrExtend::SelfTyAlias { def_id, span });
                    self.check_param_uses_if_mcg(ty, span, true)
                }
                Res::Def(DefKind::AssocTy, def_id) => {
                    let trait_segment =
                        if let [modules @ .., trait_, _item] = path.segments {
                            let _ =
                                self.prohibit_generic_args(modules.iter(),
                                    GenericsArgsErrExtend::None);
                            Some(trait_)
                        } else { None };
                    self.lower_resolved_assoc_ty_path(span, opt_self_ty, def_id,
                        trait_segment, path.segments.last().unwrap())
                }
                Res::PrimTy(prim_ty) => {
                    {
                        match (&opt_self_ty, &None) {
                            (left_val, right_val) => {
                                if !(*left_val == *right_val) {
                                    let kind = ::core::panicking::AssertKind::Eq;
                                    ::core::panicking::assert_failed(kind, &*left_val,
                                        &*right_val, ::core::option::Option::None);
                                }
                            }
                        }
                    };
                    let _ =
                        self.prohibit_generic_args(path.segments.iter(),
                            GenericsArgsErrExtend::PrimTy(prim_ty));
                    match prim_ty {
                        hir::PrimTy::Bool => tcx.types.bool,
                        hir::PrimTy::Char => tcx.types.char,
                        hir::PrimTy::Int(it) => Ty::new_int(tcx, it),
                        hir::PrimTy::Uint(uit) => Ty::new_uint(tcx, uit),
                        hir::PrimTy::Float(ft) => Ty::new_float(tcx, ft),
                        hir::PrimTy::Str => tcx.types.str_,
                    }
                }
                Res::Err => {
                    let e =
                        self.tcx().dcx().span_delayed_bug(path.span,
                            "path with `Res::Err` but no error emitted");
                    Ty::new_error(tcx, e)
                }
                Res::Def(..) => {
                    {
                        match (&path.segments.get(0).map(|seg| seg.ident.name),
                                &Some(kw::SelfUpper)) {
                            (left_val, right_val) => {
                                if !(*left_val == *right_val) {
                                    let kind = ::core::panicking::AssertKind::Eq;
                                    ::core::panicking::assert_failed(kind, &*left_val,
                                        &*right_val,
                                        ::core::option::Option::Some(format_args!("only expected incorrect resolution for `Self`")));
                                }
                            }
                        }
                    };
                    Ty::new_error(self.tcx(),
                        self.dcx().span_delayed_bug(span,
                            "incorrect resolution for `Self`"))
                }
                _ =>
                    ::rustc_span::macros::bug_impl(Some(span),
                        format_args!("unexpected resolution: {0:?}", path.res),
                        Location::caller()),
            }
        }
    }
}#[instrument(level = "debug", skip_all)]
2193    pub fn lower_resolved_ty_path(
2194        &self,
2195        opt_self_ty: Option<Ty<'tcx>>,
2196        path: &hir::Path<'_>,
2197        hir_id: HirId,
2198        permit_variants: PermitVariants,
2199    ) -> Ty<'tcx> {
2200        debug!(?path.res, ?opt_self_ty, ?path.segments);
2201        let tcx = self.tcx();
2202
2203        let span = path.span;
2204        match path.res {
2205            Res::Def(DefKind::OpaqueTy, did) => {
2206                // Check for desugared `impl Trait`.
2207                assert_matches!(tcx.opaque_ty_origin(did), hir::OpaqueTyOrigin::TyAlias { .. });
2208                let [leading_segments @ .., segment] = path.segments else { bug!() };
2209                let _ = self.prohibit_generic_args(
2210                    leading_segments.iter(),
2211                    GenericsArgsErrExtend::OpaqueTy,
2212                );
2213                let args = self.lower_generic_args_of_path_segment(span, did, segment);
2214                Ty::new_opaque(tcx, ty::IsRigid::No, did, args)
2215            }
2216            Res::Def(
2217                DefKind::Enum
2218                | DefKind::TyAlias
2219                | DefKind::Struct
2220                | DefKind::Union
2221                | DefKind::ForeignTy,
2222                did,
2223            ) => {
2224                assert_eq!(opt_self_ty, None);
2225                let [leading_segments @ .., segment] = path.segments else { bug!() };
2226                let _ = self
2227                    .prohibit_generic_args(leading_segments.iter(), GenericsArgsErrExtend::None);
2228                self.lower_path_segment(span, did, segment)
2229            }
2230            Res::Def(kind @ DefKind::Variant, def_id)
2231                if let PermitVariants::Yes = permit_variants =>
2232            {
2233                // Lower "variant type" as if it were a real type.
2234                // The resulting `Ty` is type of the variant's enum for now.
2235                assert_eq!(opt_self_ty, None);
2236
2237                let generic_segments =
2238                    self.probe_generic_path_segments(path.segments, None, kind, def_id, span);
2239                let indices: FxHashSet<_> =
2240                    generic_segments.iter().map(|GenericPathSegment(_, index)| index).collect();
2241                let _ = self.prohibit_generic_args(
2242                    path.segments.iter().enumerate().filter_map(|(index, seg)| {
2243                        if !indices.contains(&index) { Some(seg) } else { None }
2244                    }),
2245                    GenericsArgsErrExtend::DefVariant(&path.segments),
2246                );
2247
2248                let &GenericPathSegment(def_id, index) = generic_segments.last().unwrap();
2249                self.lower_path_segment(span, def_id, &path.segments[index])
2250            }
2251            Res::Def(DefKind::TyParam, def_id) => {
2252                assert_eq!(opt_self_ty, None);
2253                let _ = self.prohibit_generic_args(
2254                    path.segments.iter(),
2255                    GenericsArgsErrExtend::Param(def_id),
2256                );
2257                self.lower_ty_param(hir_id)
2258            }
2259            Res::SelfTyParam { .. } => {
2260                // `Self` in trait or type alias.
2261                assert_eq!(opt_self_ty, None);
2262                let _ = self.prohibit_generic_args(
2263                    path.segments.iter(),
2264                    if let [hir::PathSegment { args: Some(args), ident, .. }] = &path.segments {
2265                        GenericsArgsErrExtend::SelfTyParam(
2266                            ident.span.shrink_to_hi().to(args.span_ext),
2267                        )
2268                    } else {
2269                        GenericsArgsErrExtend::None
2270                    },
2271                );
2272                self.check_param_uses_if_mcg(tcx.types.self_param, span, false)
2273            }
2274            Res::SelfTyAlias { alias_to: def_id, .. } => {
2275                // `Self` in impl (we know the concrete type).
2276                assert_eq!(opt_self_ty, None);
2277                // Try to evaluate any array length constants.
2278                let ty = tcx.at(span).type_of(def_id).instantiate_identity().skip_norm_wip();
2279                let _ = self.prohibit_generic_args(
2280                    path.segments.iter(),
2281                    GenericsArgsErrExtend::SelfTyAlias { def_id, span },
2282                );
2283                self.check_param_uses_if_mcg(ty, span, true)
2284            }
2285            Res::Def(DefKind::AssocTy, def_id) => {
2286                let trait_segment = if let [modules @ .., trait_, _item] = path.segments {
2287                    let _ = self.prohibit_generic_args(modules.iter(), GenericsArgsErrExtend::None);
2288                    Some(trait_)
2289                } else {
2290                    None
2291                };
2292                self.lower_resolved_assoc_ty_path(
2293                    span,
2294                    opt_self_ty,
2295                    def_id,
2296                    trait_segment,
2297                    path.segments.last().unwrap(),
2298                )
2299            }
2300            Res::PrimTy(prim_ty) => {
2301                assert_eq!(opt_self_ty, None);
2302                let _ = self.prohibit_generic_args(
2303                    path.segments.iter(),
2304                    GenericsArgsErrExtend::PrimTy(prim_ty),
2305                );
2306                match prim_ty {
2307                    hir::PrimTy::Bool => tcx.types.bool,
2308                    hir::PrimTy::Char => tcx.types.char,
2309                    hir::PrimTy::Int(it) => Ty::new_int(tcx, it),
2310                    hir::PrimTy::Uint(uit) => Ty::new_uint(tcx, uit),
2311                    hir::PrimTy::Float(ft) => Ty::new_float(tcx, ft),
2312                    hir::PrimTy::Str => tcx.types.str_,
2313                }
2314            }
2315            Res::Err => {
2316                let e = self
2317                    .tcx()
2318                    .dcx()
2319                    .span_delayed_bug(path.span, "path with `Res::Err` but no error emitted");
2320                Ty::new_error(tcx, e)
2321            }
2322            Res::Def(..) => {
2323                assert_eq!(
2324                    path.segments.get(0).map(|seg| seg.ident.name),
2325                    Some(kw::SelfUpper),
2326                    "only expected incorrect resolution for `Self`"
2327                );
2328                Ty::new_error(
2329                    self.tcx(),
2330                    self.dcx().span_delayed_bug(span, "incorrect resolution for `Self`"),
2331                )
2332            }
2333            _ => span_bug!(span, "unexpected resolution: {:?}", path.res),
2334        }
2335    }
2336
2337    /// Lower a type parameter from the HIR to our internal notion of a type.
2338    ///
2339    /// Early-bound type parameters get lowered to [`ty::Param`]
2340    /// and late-bound ones to [`ty::Bound`].
2341    pub(crate) fn lower_ty_param(&self, hir_id: HirId) -> Ty<'tcx> {
2342        let tcx = self.tcx();
2343
2344        let ty = match tcx.named_bound_var(hir_id) {
2345            Some(rbv::ResolvedArg::LateBound(debruijn, index, def_id)) => {
2346                let br = ty::BoundTy {
2347                    var: ty::BoundVar::from_u32(index),
2348                    kind: ty::BoundTyKind::Param(def_id.to_def_id()),
2349                };
2350                Ty::new_bound(tcx, debruijn, br)
2351            }
2352            Some(rbv::ResolvedArg::EarlyBound(def_id)) => {
2353                let item_def_id = tcx.hir_ty_param_owner(def_id);
2354                let generics = tcx.generics_of(item_def_id);
2355                let index = generics.param_def_id_to_index[&def_id.to_def_id()];
2356                Ty::new_param(tcx, index, tcx.hir_ty_param_name(def_id))
2357            }
2358            Some(rbv::ResolvedArg::Error(guar)) => Ty::new_error(tcx, guar),
2359            arg => ::rustc_span::macros::bug_impl(None,
    format_args!("unexpected bound var resolution for {0:?}: {1:?}", hir_id,
        arg), Location::caller())bug!("unexpected bound var resolution for {hir_id:?}: {arg:?}"),
2360        };
2361        self.check_param_uses_if_mcg(ty, tcx.hir_span(hir_id), false)
2362    }
2363
2364    /// Lower a const parameter from the HIR to our internal notion of a constant.
2365    ///
2366    /// Early-bound const parameters get lowered to [`ty::ConstKind::Param`]
2367    /// and late-bound ones to [`ty::ConstKind::Bound`].
2368    pub(crate) fn lower_const_param(&self, param_def_id: DefId, path_hir_id: HirId) -> Const<'tcx> {
2369        let tcx = self.tcx();
2370
2371        let ct = match tcx.named_bound_var(path_hir_id) {
2372            Some(rbv::ResolvedArg::EarlyBound(_)) => {
2373                // Find the name and index of the const parameter by indexing the generics of
2374                // the parent item and construct a `ParamConst`.
2375                let item_def_id = tcx.parent(param_def_id);
2376                let generics = tcx.generics_of(item_def_id);
2377                let index = generics.param_def_id_to_index[&param_def_id];
2378                let name = tcx.item_name(param_def_id);
2379                ty::Const::new_param(tcx, ty::ParamConst::new(index, name))
2380            }
2381            Some(rbv::ResolvedArg::LateBound(debruijn, index, _)) => ty::Const::new_bound(
2382                tcx,
2383                debruijn,
2384                ty::BoundConst::new(ty::BoundVar::from_u32(index)),
2385            ),
2386            Some(rbv::ResolvedArg::Error(guar)) => ty::Const::new_error(tcx, guar),
2387            arg => ::rustc_span::macros::bug_impl(None,
    format_args!("unexpected bound var resolution for {0:?}: {1:?}",
        path_hir_id, arg), Location::caller())bug!("unexpected bound var resolution for {:?}: {arg:?}", path_hir_id),
2388        };
2389        self.check_param_uses_if_mcg(ct, tcx.hir_span(path_hir_id), false)
2390    }
2391
2392    /// Lowers a call-argument expression into a ty::Const for an arg position
2393    /// const param.
2394    pub fn lower_const_arg_expr(&self, expr: &hir::Expr<'_>, ty: Ty<'tcx>) -> Const<'tcx> {
2395        let tcx = self.tcx();
2396        match expr.kind {
2397            hir::ExprKind::Lit(lit) => {
2398                self.lower_const_arg_literal(&lit.node, false, ty, expr.span)
2399            }
2400            hir::ExprKind::Unary(
2401                hir::UnOp::Neg,
2402                hir::Expr { kind: hir::ExprKind::Lit(lit), .. },
2403            ) => self.lower_const_arg_literal(&lit.node, true, ty, expr.span),
2404            hir::ExprKind::Path(hir::QPath::Resolved(_, hir::Path { res: Res::Local(_), .. })) => {
2405                Const::new_error(tcx, self.dcx().span_err(expr.span, "Path error"))
2406            }
2407            hir::ExprKind::Path(hir::QPath::Resolved(maybe_qself, path)) => {
2408                let opt_self_ty = maybe_qself.as_ref().map(|qself| self.lower_ty(qself));
2409                self.lower_resolved_const_path(opt_self_ty, path, expr.hir_id)
2410            }
2411            hir::ExprKind::Path(hir::QPath::TypeRelative(hir_self_ty, segment)) => {
2412                let self_ty = self.lower_ty(hir_self_ty);
2413                self.lower_type_relative_const_path(
2414                    self_ty,
2415                    hir_self_ty,
2416                    segment,
2417                    expr.hir_id,
2418                    expr.span,
2419                )
2420                .unwrap_or_else(|guard| Const::new_error(tcx, guard))
2421            }
2422            _ => Const::new_error(
2423                tcx,
2424                self.dcx().span_err(expr.span, "Some other variant we dont support"),
2425            ),
2426        }
2427    }
2428
2429    /// Lower a [`hir::ConstArg`] to a (type-level) [`ty::Const`].
2430    {}
#[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("lower_const_arg",
                                    "rustc_hir_analysis::hir_ty_lowering",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(2430u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("const_arg")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("const_arg");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("ty")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("ty");
                                                        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(&const_arg)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ty)
                                                            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: Const<'tcx> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let tcx = self.tcx();
            if let hir::ConstArgKind::Anon(anon) = &const_arg.kind {
                if tcx.features().generic_const_parameter_types() &&
                        (ty.has_free_regions() || ty.has_erased_regions()) {
                    let e =
                        self.dcx().span_err(const_arg.span,
                            "anonymous constants with lifetimes in their type are not yet supported");
                    tcx.feed_anon_const_type(anon.def_id,
                        ty::EarlyBinder::bind(tcx, Ty::new_error(tcx, e)));
                    return ty::Const::new_error(tcx, e);
                }
                if ty.has_non_region_infer() {
                    let e =
                        self.dcx().span_err(const_arg.span,
                            "anonymous constants with inferred types are not yet supported");
                    tcx.feed_anon_const_type(anon.def_id,
                        ty::EarlyBinder::bind(tcx, Ty::new_error(tcx, e)));
                    return ty::Const::new_error(tcx, e);
                }
                if ty.has_non_region_param() {
                    let e =
                        self.dcx().span_err(const_arg.span,
                            "anonymous constants referencing generics are not yet supported");
                    tcx.feed_anon_const_type(anon.def_id,
                        ty::EarlyBinder::bind(tcx, Ty::new_error(tcx, e)));
                    return ty::Const::new_error(tcx, e);
                }
                tcx.feed_anon_const_type(anon.def_id,
                    ty::EarlyBinder::bind(tcx, ty));
            }
            let hir_id = const_arg.hir_id;
            match const_arg.kind {
                hir::ConstArgKind::Tup(exprs) =>
                    self.lower_const_arg_tup(exprs, ty, const_arg.span),
                hir::ConstArgKind::Path(hir::QPath::Resolved(maybe_qself,
                    path)) => {
                    {
                        use ::tracing::__macro_support::Callsite as _;
                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                            {
                                static META: ::tracing::Metadata<'static> =
                                    {
                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:2491",
                                            "rustc_hir_analysis::hir_ty_lowering",
                                            ::tracing::Level::DEBUG,
                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                            ::tracing_core::__macro_support::Option::Some(2491u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                            ::tracing_core::field::FieldSet::new(&[{
                                                                const NAME:
                                                                    ::tracing::__macro_support::FieldName<{
                                                                        ::tracing::__macro_support::FieldName::len("maybe_qself")
                                                                    }> =
                                                                    ::tracing::__macro_support::FieldName::new("maybe_qself");
                                                                NAME.as_str()
                                                            },
                                                            {
                                                                const NAME:
                                                                    ::tracing::__macro_support::FieldName<{
                                                                        ::tracing::__macro_support::FieldName::len("path")
                                                                    }> =
                                                                    ::tracing::__macro_support::FieldName::new("path");
                                                                NAME.as_str()
                                                            }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                            ::tracing::metadata::Kind::EVENT)
                                    };
                                ::tracing::callsite::DefaultCallsite::new(&META)
                            };
                        let enabled =
                            ::tracing::Level::DEBUG <=
                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                    ::tracing::Level::DEBUG <=
                                        ::tracing::level_filters::LevelFilter::current() &&
                                {
                                    let interest = __CALLSITE.interest();
                                    !interest.is_never() &&
                                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                            interest)
                                };
                        if enabled {
                            (|value_set: ::tracing::field::ValueSet|
                                        {
                                            let meta = __CALLSITE.metadata();
                                            ::tracing::Event::dispatch(meta, &value_set);
                                            ;
                                        })({
                                    #[allow(unused_imports)]
                                    use ::tracing::field::{debug, display, Value};
                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&maybe_qself)
                                                                as &dyn ::tracing::field::Value)),
                                                    (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&path)
                                                                as &dyn ::tracing::field::Value))])
                                });
                        } else { ; }
                    };
                    let opt_self_ty =
                        maybe_qself.as_ref().map(|qself| self.lower_ty(qself));
                    self.lower_resolved_const_path(opt_self_ty, path, hir_id)
                }
                hir::ConstArgKind::Path(hir::QPath::TypeRelative(hir_self_ty,
                    segment)) => {
                    {
                        use ::tracing::__macro_support::Callsite as _;
                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                            {
                                static META: ::tracing::Metadata<'static> =
                                    {
                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:2496",
                                            "rustc_hir_analysis::hir_ty_lowering",
                                            ::tracing::Level::DEBUG,
                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                            ::tracing_core::__macro_support::Option::Some(2496u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                            ::tracing_core::field::FieldSet::new(&[{
                                                                const NAME:
                                                                    ::tracing::__macro_support::FieldName<{
                                                                        ::tracing::__macro_support::FieldName::len("hir_self_ty")
                                                                    }> =
                                                                    ::tracing::__macro_support::FieldName::new("hir_self_ty");
                                                                NAME.as_str()
                                                            },
                                                            {
                                                                const NAME:
                                                                    ::tracing::__macro_support::FieldName<{
                                                                        ::tracing::__macro_support::FieldName::len("segment")
                                                                    }> =
                                                                    ::tracing::__macro_support::FieldName::new("segment");
                                                                NAME.as_str()
                                                            }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                            ::tracing::metadata::Kind::EVENT)
                                    };
                                ::tracing::callsite::DefaultCallsite::new(&META)
                            };
                        let enabled =
                            ::tracing::Level::DEBUG <=
                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                    ::tracing::Level::DEBUG <=
                                        ::tracing::level_filters::LevelFilter::current() &&
                                {
                                    let interest = __CALLSITE.interest();
                                    !interest.is_never() &&
                                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                            interest)
                                };
                        if enabled {
                            (|value_set: ::tracing::field::ValueSet|
                                        {
                                            let meta = __CALLSITE.metadata();
                                            ::tracing::Event::dispatch(meta, &value_set);
                                            ;
                                        })({
                                    #[allow(unused_imports)]
                                    use ::tracing::field::{debug, display, Value};
                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_self_ty)
                                                                as &dyn ::tracing::field::Value)),
                                                    (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&segment)
                                                                as &dyn ::tracing::field::Value))])
                                });
                        } else { ; }
                    };
                    let self_ty = self.lower_ty(hir_self_ty);
                    self.lower_type_relative_const_path(self_ty, hir_self_ty,
                            segment, hir_id,
                            const_arg.span).unwrap_or_else(|guar|
                            Const::new_error(tcx, guar))
                }
                hir::ConstArgKind::Struct(qpath, inits) => {
                    self.lower_const_arg_struct(hir_id, qpath, inits,
                        const_arg.span)
                }
                hir::ConstArgKind::TupleCall(qpath, args) => {
                    self.lower_const_arg_tuple_call(hir_id, qpath, args,
                        const_arg.span)
                }
                hir::ConstArgKind::Array(array_expr) =>
                    self.lower_const_arg_array(array_expr, ty),
                hir::ConstArgKind::Anon(anon) =>
                    self.lower_const_arg_anon(anon),
                hir::ConstArgKind::Infer(()) =>
                    self.ct_infer(None, const_arg.span),
                hir::ConstArgKind::Error(e) => ty::Const::new_error(tcx, e),
                hir::ConstArgKind::Literal { lit, negated } => {
                    self.lower_const_arg_literal(&lit, negated, ty,
                        const_arg.span)
                }
            }
        }
    }
}#[instrument(skip(self), level = "debug")]
2431    pub fn lower_const_arg(&self, const_arg: &hir::ConstArg<'_>, ty: Ty<'tcx>) -> Const<'tcx> {
2432        let tcx = self.tcx();
2433
2434        if let hir::ConstArgKind::Anon(anon) = &const_arg.kind {
2435            // FIXME(generic_const_parameter_types): Ideally we remove these errors below when
2436            // we have the ability to intermix typeck of anon const const args with the parent
2437            // bodies typeck.
2438
2439            // We also error if the type contains any regions as effectively any region will wind
2440            // up as a region variable in mir borrowck. It would also be somewhat concerning if
2441            // hir typeck was using equality but mir borrowck wound up using subtyping as that could
2442            // result in a non-infer in hir typeck but a region variable in borrowck.
2443            if tcx.features().generic_const_parameter_types()
2444                && (ty.has_free_regions() || ty.has_erased_regions())
2445            {
2446                let e = self.dcx().span_err(
2447                    const_arg.span,
2448                    "anonymous constants with lifetimes in their type are not yet supported",
2449                );
2450                tcx.feed_anon_const_type(
2451                    anon.def_id,
2452                    ty::EarlyBinder::bind(tcx, Ty::new_error(tcx, e)),
2453                );
2454                return ty::Const::new_error(tcx, e);
2455            }
2456            // We must error if the instantiated type has any inference variables as we will
2457            // use this type to feed the `type_of` and query results must not contain inference
2458            // variables otherwise we will ICE.
2459            if ty.has_non_region_infer() {
2460                let e = self.dcx().span_err(
2461                    const_arg.span,
2462                    "anonymous constants with inferred types are not yet supported",
2463                );
2464                tcx.feed_anon_const_type(
2465                    anon.def_id,
2466                    ty::EarlyBinder::bind(tcx, Ty::new_error(tcx, e)),
2467                );
2468                return ty::Const::new_error(tcx, e);
2469            }
2470            // We error when the type contains unsubstituted generics since we do not currently
2471            // give the anon const any of the generics from the parent.
2472            if ty.has_non_region_param() {
2473                let e = self.dcx().span_err(
2474                    const_arg.span,
2475                    "anonymous constants referencing generics are not yet supported",
2476                );
2477                tcx.feed_anon_const_type(
2478                    anon.def_id,
2479                    ty::EarlyBinder::bind(tcx, Ty::new_error(tcx, e)),
2480                );
2481                return ty::Const::new_error(tcx, e);
2482            }
2483
2484            tcx.feed_anon_const_type(anon.def_id, ty::EarlyBinder::bind(tcx, ty));
2485        }
2486
2487        let hir_id = const_arg.hir_id;
2488        match const_arg.kind {
2489            hir::ConstArgKind::Tup(exprs) => self.lower_const_arg_tup(exprs, ty, const_arg.span),
2490            hir::ConstArgKind::Path(hir::QPath::Resolved(maybe_qself, path)) => {
2491                debug!(?maybe_qself, ?path);
2492                let opt_self_ty = maybe_qself.as_ref().map(|qself| self.lower_ty(qself));
2493                self.lower_resolved_const_path(opt_self_ty, path, hir_id)
2494            }
2495            hir::ConstArgKind::Path(hir::QPath::TypeRelative(hir_self_ty, segment)) => {
2496                debug!(?hir_self_ty, ?segment);
2497                let self_ty = self.lower_ty(hir_self_ty);
2498                self.lower_type_relative_const_path(
2499                    self_ty,
2500                    hir_self_ty,
2501                    segment,
2502                    hir_id,
2503                    const_arg.span,
2504                )
2505                .unwrap_or_else(|guar| Const::new_error(tcx, guar))
2506            }
2507            hir::ConstArgKind::Struct(qpath, inits) => {
2508                self.lower_const_arg_struct(hir_id, qpath, inits, const_arg.span)
2509            }
2510            hir::ConstArgKind::TupleCall(qpath, args) => {
2511                self.lower_const_arg_tuple_call(hir_id, qpath, args, const_arg.span)
2512            }
2513            hir::ConstArgKind::Array(array_expr) => self.lower_const_arg_array(array_expr, ty),
2514            hir::ConstArgKind::Anon(anon) => self.lower_const_arg_anon(anon),
2515            hir::ConstArgKind::Infer(()) => self.ct_infer(None, const_arg.span),
2516            hir::ConstArgKind::Error(e) => ty::Const::new_error(tcx, e),
2517            hir::ConstArgKind::Literal { lit, negated } => {
2518                self.lower_const_arg_literal(&lit, negated, ty, const_arg.span)
2519            }
2520        }
2521    }
2522
2523    fn lower_const_arg_array(
2524        &self,
2525        array_expr: &hir::ConstArgArrayExpr<'_>,
2526        ty: Ty<'tcx>,
2527    ) -> Const<'tcx> {
2528        let tcx = self.tcx();
2529
2530        let elem_ty = match ty.kind() {
2531            ty::Array(elem_ty, _) => elem_ty,
2532            ty::Error(e) => return Const::new_error(tcx, *e),
2533            _ => {
2534                let e = tcx
2535                    .dcx()
2536                    .span_err(array_expr.span, ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("expected `{0}`, found const array",
                ty))
    })format!("expected `{ty}`, found const array"));
2537                return Const::new_error(tcx, e);
2538            }
2539        };
2540
2541        let elems = array_expr
2542            .elems
2543            .iter()
2544            .map(|elem| self.lower_const_arg(elem, *elem_ty))
2545            .collect::<Vec<_>>();
2546
2547        // The array len passed in the type might be an infer var, or a const param, or it could
2548        // just be an incorrect constant. So, construct the resulting valtree's type based on the
2549        // provided syntax rather than the expected type. The surrounding typeck will catch any
2550        // mismatches.
2551        let valtree_ty = Ty::new_array(tcx, *elem_ty, elems.len() as u64);
2552        let valtree = ty::ValTree::from_branches(tcx, elems);
2553        ty::Const::new_value(tcx, valtree, valtree_ty)
2554    }
2555
2556    fn try_recover_misrepresented_function_call(
2557        &self,
2558        hir_self_ty: &hir::Ty<'_>,
2559        span: Span,
2560    ) -> Option<ErrorGuaranteed> {
2561        // Only an enum can host a tuple-variant constructor (`<Option<u32>>::Some(..)`).
2562        // For any other self type, a type-relative call is an associated function, not a
2563        // constructor, and must be wrapped in `const { ... }`. We catch that here, before
2564        // lowering the self type, so a generic struct/union written without its args
2565        // (`FieldName::len()`, from `tracing`'s macros) reports this clear error instead
2566        // of a spurious E0107 "missing generics" (#157152), and a primitive or foreign
2567        // type reports it instead of an opaque downstream resolution error. Enums,
2568        // aliases, `Self` and type parameters are let through: each may resolve to an
2569        // enum, so they must reach constructor lowering.
2570        let self_ty_res = match hir_self_ty.kind {
2571            hir::TyKind::Path(hir::QPath::Resolved(_, path)) => path.res,
2572            _ => Res::Err,
2573        };
2574        #[allow(non_exhaustive_omitted_patterns)] match self_ty_res {
    Res::Def(DefKind::Struct | DefKind::Union | DefKind::ForeignTy, _) |
        Res::PrimTy(_) => true,
    _ => false,
}matches!(
2575            self_ty_res,
2576            Res::Def(DefKind::Struct | DefKind::Union | DefKind::ForeignTy, _) | Res::PrimTy(_)
2577        )
2578        .then(|| self.dcx().emit_err(diagnostics::ComplexConstArg { span }))
2579    }
2580
2581    fn lower_const_arg_tuple_call(
2582        &self,
2583        hir_id: HirId,
2584        qpath: hir::QPath<'_>,
2585        args: &[hir::ConstArg<'_>],
2586        span: Span,
2587    ) -> Const<'tcx> {
2588        let tcx = self.tcx();
2589
2590        let non_adt_or_variant_res = || {
2591            let e = tcx.dcx().span_err(span, "tuple constructor with invalid base path");
2592            ty::Const::new_error(tcx, e)
2593        };
2594
2595        let ctor_const = match qpath {
2596            hir::QPath::Resolved(maybe_qself, path) => {
2597                let opt_self_ty = maybe_qself.as_ref().map(|qself| self.lower_ty(qself));
2598                self.lower_resolved_const_path(opt_self_ty, path, hir_id)
2599            }
2600            hir::QPath::TypeRelative(hir_self_ty, segment) => {
2601                if let Some(e) = self.try_recover_misrepresented_function_call(hir_self_ty, span) {
2602                    return ty::Const::new_error(tcx, e);
2603                }
2604
2605                let self_ty = self.lower_ty(hir_self_ty);
2606                match self.lower_type_relative_const_path(
2607                    self_ty,
2608                    hir_self_ty,
2609                    segment,
2610                    hir_id,
2611                    span,
2612                ) {
2613                    Ok(c) => c,
2614                    Err(_) => return non_adt_or_variant_res(),
2615                }
2616            }
2617        };
2618
2619        let Some(value) = ctor_const.try_to_value() else {
2620            return non_adt_or_variant_res();
2621        };
2622
2623        let (adt_def, adt_args, variant_did) = match value.ty.kind() {
2624            ty::FnDef(def_id, fn_args)
2625                if let DefKind::Ctor(CtorOf::Variant, _) = tcx.def_kind(*def_id) =>
2626            {
2627                let parent_did = tcx.parent(*def_id);
2628                let enum_did = tcx.parent(parent_did);
2629                (tcx.adt_def(enum_did), fn_args, parent_did)
2630            }
2631            ty::FnDef(def_id, fn_args)
2632                if let DefKind::Ctor(CtorOf::Struct, _) = tcx.def_kind(*def_id) =>
2633            {
2634                let parent_did = tcx.parent(*def_id);
2635                (tcx.adt_def(parent_did), fn_args, parent_did)
2636            }
2637            _ => {
2638                let e = self.dcx().emit_err(diagnostics::ComplexConstArg { span });
2639                return Const::new_error(tcx, e);
2640            }
2641        };
2642
2643        let variant_def = adt_def.variant_with_id(variant_did);
2644        let variant_idx = adt_def.variant_index_with_id(variant_did).as_u32();
2645
2646        if args.len() != variant_def.fields.len() {
2647            let e = tcx.dcx().span_err(
2648                span,
2649                ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("tuple constructor has {0} arguments but {1} were provided",
                variant_def.fields.len(), args.len()))
    })format!(
2650                    "tuple constructor has {} arguments but {} were provided",
2651                    variant_def.fields.len(),
2652                    args.len()
2653                ),
2654            );
2655            return ty::Const::new_error(tcx, e);
2656        }
2657
2658        let fields = variant_def
2659            .fields
2660            .iter()
2661            .zip(args)
2662            .map(|(field_def, arg)| {
2663                self.lower_const_arg(
2664                    arg,
2665                    tcx.type_of(field_def.did)
2666                        .instantiate(tcx, adt_args.no_bound_vars().unwrap())
2667                        .skip_norm_wip(),
2668                )
2669            })
2670            .collect::<Vec<_>>();
2671
2672        let opt_discr_const = if adt_def.is_enum() {
2673            let valtree = ty::ValTree::from_scalar_int(tcx, variant_idx.into());
2674            Some(ty::Const::new_value(tcx, valtree, tcx.types.u32))
2675        } else {
2676            None
2677        };
2678
2679        let valtree = ty::ValTree::from_branches(tcx, opt_discr_const.into_iter().chain(fields));
2680        let adt_ty = Ty::new_adt(tcx, adt_def, adt_args.no_bound_vars().unwrap());
2681        ty::Const::new_value(tcx, valtree, adt_ty)
2682    }
2683
2684    fn lower_const_arg_tup(
2685        &self,
2686        exprs: &[hir::ConstArg<'_>],
2687        ty: Ty<'tcx>,
2688        span: Span,
2689    ) -> Const<'tcx> {
2690        let tcx = self.tcx();
2691
2692        let found_tuple = || {
2693            tcx.sess
2694                .source_map()
2695                .span_to_snippet(span)
2696                .map(|snippet| ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("`{0}`", snippet))
    })format!("`{snippet}`"))
2697                .unwrap_or_else(|_| "const tuple".to_string())
2698        };
2699
2700        let tys = match ty.kind() {
2701            ty::Tuple(tys) => tys,
2702            ty::Error(e) => return Const::new_error(tcx, *e),
2703            _ => {
2704                let e =
2705                    tcx.dcx().span_err(span, ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("expected `{0}`, found {1}", ty,
                found_tuple()))
    })format!("expected `{}`, found {}", ty, found_tuple()));
2706                return Const::new_error(tcx, e);
2707            }
2708        };
2709
2710        if exprs.len() != tys.len() {
2711            let e = tcx.dcx().span_err(span, ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("expected `{0}`, found {1}", ty,
                found_tuple()))
    })format!("expected `{}`, found {}", ty, found_tuple()));
2712            return Const::new_error(tcx, e);
2713        }
2714
2715        let exprs = exprs
2716            .iter()
2717            .zip(tys.iter())
2718            .map(|(expr, ty)| self.lower_const_arg(expr, ty))
2719            .collect::<Vec<_>>();
2720
2721        let valtree = ty::ValTree::from_branches(tcx, exprs);
2722        ty::Const::new_value(tcx, valtree, ty)
2723    }
2724
2725    fn lower_const_arg_struct(
2726        &self,
2727        hir_id: HirId,
2728        qpath: hir::QPath<'_>,
2729        inits: &[hir::ConstArgExprField<'_>],
2730        span: Span,
2731    ) -> Const<'tcx> {
2732        // FIXME(mgca): try to deduplicate this function with
2733        // the equivalent HIR typeck logic.
2734        let tcx = self.tcx();
2735
2736        let non_adt_or_variant_res = || {
2737            let e = tcx.dcx().span_err(span, "struct expression with invalid base path");
2738            ty::Const::new_error(tcx, e)
2739        };
2740
2741        let ResolvedStructPath { res: opt_res, ty } =
2742            self.lower_path_for_struct_expr(qpath, span, hir_id);
2743
2744        let variant_did = match qpath {
2745            hir::QPath::Resolved(maybe_qself, path) => {
2746                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:2746",
                        "rustc_hir_analysis::hir_ty_lowering",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(2746u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("maybe_qself")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("maybe_qself");
                                            NAME.as_str()
                                        },
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("path")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("path");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&maybe_qself)
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&path)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?maybe_qself, ?path);
2747                let variant_did = match path.res {
2748                    Res::Def(DefKind::Variant | DefKind::Struct, did) => did,
2749                    _ => return non_adt_or_variant_res(),
2750                };
2751
2752                variant_did
2753            }
2754            hir::QPath::TypeRelative(hir_self_ty, segment) => {
2755                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:2755",
                        "rustc_hir_analysis::hir_ty_lowering",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(2755u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("hir_self_ty")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("hir_self_ty");
                                            NAME.as_str()
                                        },
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("segment")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("segment");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_self_ty)
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&segment)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?hir_self_ty, ?segment);
2756
2757                let res_def_id = match opt_res {
2758                    Ok(r)
2759                        if #[allow(non_exhaustive_omitted_patterns)] match tcx.def_kind(r.def_id()) {
    DefKind::Variant | DefKind::Struct => true,
    _ => false,
}matches!(
2760                            tcx.def_kind(r.def_id()),
2761                            DefKind::Variant | DefKind::Struct
2762                        ) =>
2763                    {
2764                        r.def_id()
2765                    }
2766                    Ok(_) => return non_adt_or_variant_res(),
2767                    Err(e) => return ty::Const::new_error(tcx, e),
2768                };
2769
2770                res_def_id
2771            }
2772        };
2773
2774        let ty::Adt(adt_def, adt_args) = ty.kind() else { ::core::panicking::unreachable_default_msg()unreachable!() };
2775
2776        let variant_def = adt_def.variant_with_id(variant_did);
2777        let variant_idx = adt_def.variant_index_with_id(variant_did).as_u32();
2778
2779        for init in inits {
2780            if !variant_def.fields.iter().any(|field_def| field_def.name == init.field.name) {
2781                let mut err = if adt_def.is_enum() {
2782                    {
    tcx.dcx().struct_span_err(init.field.span,
            ::alloc::__export::must_use({
                    ::alloc::fmt::format(format_args!("variant `{0}::{1}` has no field named `{2}`",
                            ty, variant_def.name, init.field))
                })).with_code(E0559)
}struct_span_code_err!(
2783                        tcx.dcx(),
2784                        init.field.span,
2785                        E0559,
2786                        "variant `{}::{}` has no field named `{}`",
2787                        ty,
2788                        variant_def.name,
2789                        init.field
2790                    )
2791                } else {
2792                    {
    tcx.dcx().struct_span_err(init.field.span,
            ::alloc::__export::must_use({
                    ::alloc::fmt::format(format_args!("struct `{0}` has no field named `{1}`",
                            variant_def.name, init.field))
                })).with_code(E0560)
}struct_span_code_err!(
2793                        tcx.dcx(),
2794                        init.field.span,
2795                        E0560,
2796                        "struct `{}` has no field named `{}`",
2797                        variant_def.name,
2798                        init.field
2799                    )
2800                };
2801                if adt_def.is_enum() {
2802                    err.span_label(
2803                        init.field.span,
2804                        ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("`{0}::{1}` does not have this field",
                ty, variant_def.name))
    })format!("`{}::{}` does not have this field", ty, variant_def.name),
2805                    );
2806                } else {
2807                    err.span_label(
2808                        init.field.span,
2809                        ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("`{0}` does not have this field",
                variant_def.name))
    })format!("`{}` does not have this field", variant_def.name),
2810                    );
2811                }
2812                return ty::Const::new_error(tcx, err.emit_err());
2813            }
2814        }
2815
2816        let fields = variant_def
2817            .fields
2818            .iter()
2819            .map(|field_def| {
2820                // FIXME(mgca): we aren't really handling privacy, stability,
2821                // or macro hygeniene but we should.
2822                let mut init_expr =
2823                    inits.iter().filter(|init_expr| init_expr.field.name == field_def.name);
2824
2825                match init_expr.next() {
2826                    Some(expr) => {
2827                        if let Some(expr) = init_expr.next() {
2828                            let e = tcx.dcx().span_err(
2829                                expr.span,
2830                                ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("struct expression with multiple initialisers for `{0}`",
                field_def.name))
    })format!(
2831                                    "struct expression with multiple initialisers for `{}`",
2832                                    field_def.name,
2833                                ),
2834                            );
2835                            return ty::Const::new_error(tcx, e);
2836                        }
2837
2838                        self.lower_const_arg(
2839                            expr.expr,
2840                            tcx.type_of(field_def.did).instantiate(tcx, adt_args).skip_norm_wip(),
2841                        )
2842                    }
2843                    None => {
2844                        let e = tcx.dcx().span_err(
2845                            span,
2846                            ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("struct expression with missing field initialiser for `{0}`",
                field_def.name))
    })format!(
2847                                "struct expression with missing field initialiser for `{}`",
2848                                field_def.name
2849                            ),
2850                        );
2851                        ty::Const::new_error(tcx, e)
2852                    }
2853                }
2854            })
2855            .collect::<Vec<_>>();
2856
2857        let opt_discr_const = if adt_def.is_enum() {
2858            let valtree = ty::ValTree::from_scalar_int(tcx, variant_idx.into());
2859            Some(ty::Const::new_value(tcx, valtree, tcx.types.u32))
2860        } else {
2861            None
2862        };
2863
2864        let valtree = ty::ValTree::from_branches(tcx, opt_discr_const.into_iter().chain(fields));
2865        ty::Const::new_value(tcx, valtree, ty)
2866    }
2867
2868    pub fn lower_path_for_struct_expr(
2869        &self,
2870        qpath: hir::QPath<'_>,
2871        path_span: Span,
2872        hir_id: HirId,
2873    ) -> ResolvedStructPath<'tcx> {
2874        match qpath {
2875            hir::QPath::Resolved(ref maybe_qself, path) => {
2876                let self_ty = maybe_qself.as_ref().map(|qself| self.lower_ty(qself));
2877                let ty = self.lower_resolved_ty_path(self_ty, path, hir_id, PermitVariants::Yes);
2878                ResolvedStructPath { res: Ok(path.res), ty }
2879            }
2880            hir::QPath::TypeRelative(hir_self_ty, segment) => {
2881                let self_ty = self.lower_ty(hir_self_ty);
2882
2883                let result = self.lower_type_relative_ty_path(
2884                    self_ty,
2885                    hir_self_ty,
2886                    segment,
2887                    hir_id,
2888                    path_span,
2889                    PermitVariants::Yes,
2890                );
2891                let ty = result
2892                    .map(|(ty, _, _)| ty)
2893                    .unwrap_or_else(|guar| Ty::new_error(self.tcx(), guar));
2894
2895                ResolvedStructPath {
2896                    res: result.map(|(_, kind, def_id)| Res::Def(kind, def_id)),
2897                    ty,
2898                }
2899            }
2900        }
2901    }
2902
2903    /// Lower a [resolved][hir::QPath::Resolved] path to a (type-level) constant.
2904    fn lower_resolved_const_path(
2905        &self,
2906        opt_self_ty: Option<Ty<'tcx>>,
2907        path: &hir::Path<'_>,
2908        hir_id: HirId,
2909    ) -> Const<'tcx> {
2910        let tcx = self.tcx();
2911        let span = path.span;
2912        let ct = match path.res {
2913            Res::Def(DefKind::ConstParam, def_id) => {
2914                {
    match (&opt_self_ty, &None) {
        (left_val, right_val) => {
            if !(*left_val == *right_val) {
                let kind = ::core::panicking::AssertKind::Eq;
                ::core::panicking::assert_failed(kind, &*left_val,
                    &*right_val, ::core::option::Option::None);
            }
        }
    }
};assert_eq!(opt_self_ty, None);
2915                let _ = self.prohibit_generic_args(
2916                    path.segments.iter(),
2917                    GenericsArgsErrExtend::Param(def_id),
2918                );
2919                self.lower_const_param(def_id, hir_id)
2920            }
2921            Res::Def(DefKind::Const, did) => {
2922                let kind = ty::AliasConstKind::Free { def_id: did };
2923                if let Err(guar) = self.check_const_item_in_type_system(kind, span) {
2924                    return Const::new_error(self.tcx(), guar);
2925                }
2926
2927                {
    match (&opt_self_ty, &None) {
        (left_val, right_val) => {
            if !(*left_val == *right_val) {
                let kind = ::core::panicking::AssertKind::Eq;
                ::core::panicking::assert_failed(kind, &*left_val,
                    &*right_val, ::core::option::Option::None);
            }
        }
    }
};assert_eq!(opt_self_ty, None);
2928                let [leading_segments @ .., segment] = path.segments else { ::rustc_span::macros::bug_impl(None, format_args!("impossible case reached"),
    Location::caller())bug!() };
2929                let _ = self
2930                    .prohibit_generic_args(leading_segments.iter(), GenericsArgsErrExtend::None);
2931                let args = self.lower_generic_args_of_path_segment(span, did, segment);
2932                let alias = ty::AliasConst::new(tcx, kind, args);
2933                ty::Const::new_alias(tcx, ty::IsRigid::No, alias)
2934            }
2935            Res::Def(kind @ DefKind::Ctor(ctor_of, CtorKind::Const), did) => {
2936                {
    match (&opt_self_ty, &None) {
        (left_val, right_val) => {
            if !(*left_val == *right_val) {
                let kind = ::core::panicking::AssertKind::Eq;
                ::core::panicking::assert_failed(kind, &*left_val,
                    &*right_val, ::core::option::Option::None);
            }
        }
    }
};assert_eq!(opt_self_ty, None);
2937                let generic_segments =
2938                    self.probe_generic_path_segments(path.segments, opt_self_ty, kind, did, span);
2939                let indices: FxHashSet<_> =
2940                    generic_segments.iter().map(|GenericPathSegment(_, index)| index).collect();
2941                let _ = self.prohibit_generic_args(
2942                    path.segments.iter().enumerate().filter_map(|(index, seg)| {
2943                        if !indices.contains(&index) { Some(seg) } else { None }
2944                    }),
2945                    GenericsArgsErrExtend::DefVariant(&path.segments),
2946                );
2947
2948                let parent_did = tcx.parent(did);
2949                let generics_did = match ctor_of {
2950                    CtorOf::Variant => tcx.parent(parent_did),
2951                    CtorOf::Struct => parent_did,
2952                };
2953                let args = self.lower_generic_args_of_path_segment(
2954                    span,
2955                    generics_did,
2956                    &path.segments[generic_segments[0].1],
2957                );
2958                self.construct_const_ctor_value(did, ctor_of, args)
2959            }
2960            Res::Def(DefKind::Ctor(ctor_of, CtorKind::Fn), did) => {
2961                {
    match (&opt_self_ty, &None) {
        (left_val, right_val) => {
            if !(*left_val == *right_val) {
                let kind = ::core::panicking::AssertKind::Eq;
                ::core::panicking::assert_failed(kind, &*left_val,
                    &*right_val, ::core::option::Option::None);
            }
        }
    }
};assert_eq!(opt_self_ty, None);
2962                let generic_segments = self.probe_generic_path_segments(
2963                    path.segments,
2964                    opt_self_ty,
2965                    DefKind::Ctor(ctor_of, CtorKind::Const),
2966                    did,
2967                    span,
2968                );
2969                let indices: FxHashSet<_> =
2970                    generic_segments.iter().map(|GenericPathSegment(_, index)| index).collect();
2971                let _ = self.prohibit_generic_args(
2972                    path.segments.iter().enumerate().filter_map(|(index, seg)| {
2973                        if !indices.contains(&index) { Some(seg) } else { None }
2974                    }),
2975                    GenericsArgsErrExtend::DefVariant(&path.segments),
2976                );
2977
2978                let parent_did = tcx.parent(did);
2979                let generics_did = if let DefKind::Ctor(CtorOf::Variant, _) = tcx.def_kind(did) {
2980                    tcx.parent(parent_did)
2981                } else {
2982                    parent_did
2983                };
2984                let args = self.lower_generic_args_of_path_segment(
2985                    span,
2986                    generics_did,
2987                    &path.segments[generic_segments[0].1],
2988                );
2989
2990                ty::Const::zero_sized(tcx, tcx.type_of(did).instantiate(tcx, args).skip_norm_wip())
2991            }
2992            Res::Def(DefKind::AssocConst, did) => {
2993                let trait_segment = if let [modules @ .., trait_, _item] = path.segments {
2994                    let _ = self.prohibit_generic_args(modules.iter(), GenericsArgsErrExtend::None);
2995                    Some(trait_)
2996                } else {
2997                    None
2998                };
2999                self.lower_resolved_assoc_const_path(
3000                    span,
3001                    opt_self_ty,
3002                    did,
3003                    trait_segment,
3004                    path.segments.last().unwrap(),
3005                )
3006                .unwrap_or_else(|guar| Const::new_error(tcx, guar))
3007            }
3008            Res::Def(DefKind::Static { .. }, _) => {
3009                let guar = self
3010                    .dcx()
3011                    .span_err(path.span, "static items cannot be used as const arguments");
3012                return Const::new_error(tcx, guar);
3013            }
3014            // FIXME(const_generics): create real consts to allow fn items as const paths.
3015            // Lowering these to recovered `FnDef` consts currently interacts poorly with WF
3016            // checking: WF of a `FnDef` walks the function signature, so a signature that mentions
3017            // the same function item as a const arg can recurse until it overflows/segfaults.
3018            Res::Def(DefKind::Fn | DefKind::AssocFn, _) => {
3019                let guar = self
3020                    .dcx()
3021                    .struct_span_err(span, "function items cannot be used as const args")
3022                    .emit_err();
3023                Const::new_error(tcx, guar)
3024            }
3025            // Exhaustive match to be clear about what exactly we're considering to be
3026            // an invalid Res for a const path.
3027            res @ (Res::Def(
3028                DefKind::Mod
3029                | DefKind::Enum
3030                | DefKind::Variant
3031                | DefKind::Struct
3032                | DefKind::OpaqueTy
3033                | DefKind::TyAlias
3034                | DefKind::TraitAlias
3035                | DefKind::AssocTy
3036                | DefKind::Union
3037                | DefKind::Trait
3038                | DefKind::ForeignTy
3039                | DefKind::TyParam
3040                | DefKind::Macro(_)
3041                | DefKind::LifetimeParam
3042                | DefKind::Use
3043                | DefKind::ForeignMod
3044                | DefKind::AnonConst
3045                | DefKind::Field
3046                | DefKind::Impl { .. }
3047                | DefKind::Closure
3048                | DefKind::ExternCrate
3049                | DefKind::GlobalAsm
3050                | DefKind::SyntheticCoroutineBody
3051                | DefKind::TestBinderConstraints,
3052                _,
3053            )
3054            | Res::PrimTy(_)
3055            | Res::SelfTyParam { .. }
3056            | Res::SelfTyAlias { .. }
3057            | Res::SelfCtor(_)
3058            | Res::Local(_)
3059            | Res::ToolMod
3060            | Res::OpenMod(..)
3061            | Res::NonMacroAttr(_)
3062            | Res::Err) => Const::new_error_with_message(
3063                tcx,
3064                span,
3065                ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("invalid Res {0:?} for const path",
                res))
    })format!("invalid Res {res:?} for const path"),
3066            ),
3067        };
3068        self.check_param_uses_if_mcg(ct, span, false)
3069    }
3070
3071    /// Literals are eagerly converted to a constant, everything else becomes `ConstKind::Alias`.
3072    {}
#[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("lower_const_arg_anon",
                                    "rustc_hir_analysis::hir_ty_lowering",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(3072u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("anon")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("anon");
                                                        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(&anon)
                                                            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: Const<'tcx> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let tcx = self.tcx();
            let expr = &tcx.hir_body(anon.body).value;
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3077",
                                    "rustc_hir_analysis::hir_ty_lowering",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(3077u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("expr")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("expr");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&expr)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            let ty =
                tcx.type_of(anon.def_id).instantiate_identity().skip_norm_wip();
            match self.try_lower_anon_const_lit(ty, expr) {
                Some(v) => v,
                None =>
                    ty::Const::new_alias(tcx, ty::IsRigid::No,
                        ty::AliasConst::new(tcx,
                            ty::AliasConstKind::Anon {
                                def_id: anon.def_id.to_def_id(),
                            },
                            ty::GenericArgs::identity_for_item(tcx,
                                anon.def_id.to_def_id()))),
            }
        }
    }
}#[instrument(skip(self), level = "debug")]
3073    fn lower_const_arg_anon(&self, anon: &AnonConst) -> Const<'tcx> {
3074        let tcx = self.tcx();
3075
3076        let expr = &tcx.hir_body(anon.body).value;
3077        debug!(?expr);
3078
3079        // FIXME(generic_const_parameter_types): We should use the proper generic args
3080        // here. It's only used as a hint for literals so doesn't matter too much to use the right
3081        // generic arguments, just weaker type inference.
3082        let ty = tcx.type_of(anon.def_id).instantiate_identity().skip_norm_wip();
3083
3084        match self.try_lower_anon_const_lit(ty, expr) {
3085            Some(v) => v,
3086            None => ty::Const::new_alias(
3087                tcx,
3088                ty::IsRigid::No,
3089                ty::AliasConst::new(
3090                    tcx,
3091                    ty::AliasConstKind::Anon { def_id: anon.def_id.to_def_id() },
3092                    ty::GenericArgs::identity_for_item(tcx, anon.def_id.to_def_id()),
3093                ),
3094            ),
3095        }
3096    }
3097
3098    {}
#[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("lower_const_arg_literal",
                                    "rustc_hir_analysis::hir_ty_lowering",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(3098u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("kind")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("kind");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("neg")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("neg");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("ty")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("ty");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("span")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("span");
                                                        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(&kind)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&neg as
                                                            &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ty)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
                                                            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: Const<'tcx> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let tcx = self.tcx();
            let ty = if !ty.has_infer() { Some(ty) } else { None };
            if let LitKind::Err(guar) = *kind {
                return ty::Const::new_error(tcx, guar);
            }
            let input = LitToConstInput { lit: *kind, ty, neg };
            match tcx.at(span).lit_to_const(input) {
                Some(value) =>
                    ty::Const::new_value(tcx, value.valtree, value.ty),
                None => {
                    let e =
                        tcx.dcx().span_err(span,
                            "type annotations needed for the literal");
                    ty::Const::new_error(tcx, e)
                }
            }
        }
    }
}#[instrument(skip(self), level = "debug")]
3099    fn lower_const_arg_literal(
3100        &self,
3101        kind: &LitKind,
3102        neg: bool,
3103        ty: Ty<'tcx>,
3104        span: Span,
3105    ) -> Const<'tcx> {
3106        let tcx = self.tcx();
3107
3108        let ty = if !ty.has_infer() { Some(ty) } else { None };
3109
3110        if let LitKind::Err(guar) = *kind {
3111            return ty::Const::new_error(tcx, guar);
3112        }
3113        let input = LitToConstInput { lit: *kind, ty, neg };
3114        match tcx.at(span).lit_to_const(input) {
3115            Some(value) => ty::Const::new_value(tcx, value.valtree, value.ty),
3116            None => {
3117                let e = tcx.dcx().span_err(span, "type annotations needed for the literal");
3118                ty::Const::new_error(tcx, e)
3119            }
3120        }
3121    }
3122
3123    {}
#[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("try_lower_anon_const_lit",
                                    "rustc_hir_analysis::hir_ty_lowering",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(3123u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("ty")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("ty");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("expr")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("expr");
                                                        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(&ty)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&expr)
                                                            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: Option<Const<'tcx>> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let tcx = self.tcx();
            let expr =
                match &expr.kind {
                    hir::ExprKind::Block(block, _) if
                        block.stmts.is_empty() && block.expr.is_some() => {
                        block.expr.as_ref().unwrap()
                    }
                    _ => expr,
                };
            let lit_input =
                match expr.kind {
                    hir::ExprKind::Lit(lit) => {
                        Some(LitToConstInput {
                                lit: lit.node,
                                ty: Some(ty),
                                neg: false,
                            })
                    }
                    hir::ExprKind::Unary(hir::UnOp::Neg, expr) =>
                        match expr.kind {
                            hir::ExprKind::Lit(lit) => {
                                Some(LitToConstInput {
                                        lit: lit.node,
                                        ty: Some(ty),
                                        neg: true,
                                    })
                            }
                            _ => None,
                        },
                    _ => None,
                };
            lit_input.and_then(|l|
                    {
                        if const_lit_matches_ty(tcx, &l.lit, ty, l.neg) {
                            tcx.at(expr.span).lit_to_const(l).map(|value|
                                    ty::Const::new_value(tcx, value.valtree, value.ty))
                        } else { None }
                    })
        }
    }
}#[instrument(skip(self), level = "debug")]
3124    fn try_lower_anon_const_lit(
3125        &self,
3126        ty: Ty<'tcx>,
3127        expr: &'tcx hir::Expr<'tcx>,
3128    ) -> Option<Const<'tcx>> {
3129        let tcx = self.tcx();
3130
3131        // Unwrap a block, so that e.g. `{ 1 }` is recognised as a literal. This makes the
3132        // performance optimisation of directly lowering anon consts occur more often.
3133        let expr = match &expr.kind {
3134            hir::ExprKind::Block(block, _) if block.stmts.is_empty() && block.expr.is_some() => {
3135                block.expr.as_ref().unwrap()
3136            }
3137            _ => expr,
3138        };
3139
3140        let lit_input = match expr.kind {
3141            hir::ExprKind::Lit(lit) => {
3142                Some(LitToConstInput { lit: lit.node, ty: Some(ty), neg: false })
3143            }
3144            hir::ExprKind::Unary(hir::UnOp::Neg, expr) => match expr.kind {
3145                hir::ExprKind::Lit(lit) => {
3146                    Some(LitToConstInput { lit: lit.node, ty: Some(ty), neg: true })
3147                }
3148                _ => None,
3149            },
3150            _ => None,
3151        };
3152
3153        lit_input.and_then(|l| {
3154            if const_lit_matches_ty(tcx, &l.lit, ty, l.neg) {
3155                tcx.at(expr.span)
3156                    .lit_to_const(l)
3157                    .map(|value| ty::Const::new_value(tcx, value.valtree, value.ty))
3158            } else {
3159                None
3160            }
3161        })
3162    }
3163
3164    /// `alias_const` is a const item used in the type system. Checks if that's OK.
3165    fn check_const_item_in_type_system(
3166        &self,
3167        alias_const: ty::AliasConstKind<'tcx>,
3168        span: Span,
3169    ) -> Result<(), ErrorGuaranteed> {
3170        let tcx = self.tcx();
3171        if tcx.features().gca_const_items() || alias_const.is_direct_const(tcx) {
3172            Ok(())
3173        } else {
3174            let mut err = self
3175                .dcx()
3176                .struct_span_err(span, "use of `const` in the type system not marked as direct");
3177            let hir_node = match alias_const {
3178                ty::AliasConstKind::Projection { def_id }
3179                | ty::AliasConstKind::InherentSelf { def_id }
3180                | ty::AliasConstKind::InherentImpl { def_id }
3181                | ty::AliasConstKind::Free { def_id }
3182                | ty::AliasConstKind::Anon { def_id } => {
3183                    def_id.as_local().map(|id| tcx.hir_node_by_def_id(id))
3184                }
3185            };
3186            if let Some(hir_node) = hir_node {
3187                if let Some(body_id) = hir_node.body_id() {
3188                    let body_span = tcx.hir_body(body_id).value.span;
3189
3190                    err.multipart_suggestion(
3191                        "add gca!() to the right-hand side of the constant",
3192                        ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [(body_span.shrink_to_lo(), String::from("core::gca!(")),
                (body_span.shrink_to_hi(), String::from(")"))]))vec![
3193                            (body_span.shrink_to_lo(), String::from("core::gca!(")),
3194                            (body_span.shrink_to_hi(), String::from(")")),
3195                        ],
3196                        Applicability::MaybeIncorrect,
3197                    );
3198                } else if let ty::AliasConstKind::Projection { .. } = alias_const {
3199                    let node = hir_node.expect_trait_item();
3200                    let sp = node.span.shrink_to_lo();
3201                    err.span_suggestion_verbose(
3202                        sp,
3203                        "add `#[rustc_always_gca]` to the constant",
3204                        "#[rustc_always_gca] ",
3205                        Applicability::MaybeIncorrect,
3206                    );
3207                }
3208            } else {
3209                err.note("only consts with a `gca!` right-hand side may be used in types");
3210            }
3211            Err(err.emit_err())
3212        }
3213    }
3214
3215    fn lower_delegation_ty(&self, infer: hir::InferDelegation<'_>) -> Ty<'tcx> {
3216        match infer {
3217            hir::InferDelegation::DefId(def_id) => {
3218                self.tcx().type_of(def_id).instantiate_identity().skip_norm_wip()
3219            }
3220            rustc_hir::InferDelegation::Sig(_, idx) => {
3221                let delegation_sig = self.tcx().inherit_sig_for_delegation_item(self.item_def_id());
3222
3223                match idx {
3224                    hir::InferDelegationSig::Input(idx) => delegation_sig[idx],
3225                    hir::InferDelegationSig::Output { .. } => *delegation_sig.last().unwrap(),
3226                }
3227            }
3228        }
3229    }
3230
3231    /// Lower a type from the HIR to our internal notion of a type.
3232    {}
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("lower_ty",
                                "rustc_hir_analysis::hir_ty_lowering",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                ::tracing_core::__macro_support::Option::Some(3232u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("hir_ty")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("hir_ty");
                                                    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(&hir_ty)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[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: Ty<'tcx> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        let tcx = self.tcx();
                        let result_ty =
                            match &hir_ty.kind {
                                hir::TyKind::InferDelegation(infer) =>
                                    self.lower_delegation_ty(*infer),
                                hir::TyKind::Slice(ty) =>
                                    Ty::new_slice(tcx, self.lower_ty(ty)),
                                hir::TyKind::Ptr(ty, mutbl) =>
                                    Ty::new_ptr(tcx, self.lower_ty(ty), *mutbl),
                                hir::TyKind::Ref(region, ty, mutbl) => {
                                    let r =
                                        self.lower_lifetime(region, RegionInferReason::Reference);
                                    {
                                        use ::tracing::__macro_support::Callsite as _;
                                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                            {
                                                static META: ::tracing::Metadata<'static> =
                                                    {
                                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3242",
                                                            "rustc_hir_analysis::hir_ty_lowering",
                                                            ::tracing::Level::DEBUG,
                                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                                            ::tracing_core::__macro_support::Option::Some(3242u32),
                                                            ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                                            ::tracing_core::field::FieldSet::new(&[{
                                                                                const NAME:
                                                                                    ::tracing::__macro_support::FieldName<{
                                                                                        ::tracing::__macro_support::FieldName::len("r")
                                                                                    }> =
                                                                                    ::tracing::__macro_support::FieldName::new("r");
                                                                                NAME.as_str()
                                                                            }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                            ::tracing::metadata::Kind::EVENT)
                                                    };
                                                ::tracing::callsite::DefaultCallsite::new(&META)
                                            };
                                        let enabled =
                                            ::tracing::Level::DEBUG <=
                                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                                    ::tracing::Level::DEBUG <=
                                                        ::tracing::level_filters::LevelFilter::current() &&
                                                {
                                                    let interest = __CALLSITE.interest();
                                                    !interest.is_never() &&
                                                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                            interest)
                                                };
                                        if enabled {
                                            (|value_set: ::tracing::field::ValueSet|
                                                        {
                                                            let meta = __CALLSITE.metadata();
                                                            ::tracing::Event::dispatch(meta, &value_set);
                                                            ;
                                                        })({
                                                    #[allow(unused_imports)]
                                                    use ::tracing::field::{debug, display, Value};
                                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&r)
                                                                                as &dyn ::tracing::field::Value))])
                                                });
                                        } else { ; }
                                    };
                                    let t = self.lower_ty(ty);
                                    Ty::new_ref(tcx, r, t, *mutbl)
                                }
                                hir::TyKind::Never => tcx.types.never,
                                hir::TyKind::Tup(fields) => {
                                    Ty::new_tup_from_iter(tcx,
                                        fields.iter().map(|t| self.lower_ty(t)))
                                }
                                hir::TyKind::FnPtr(bf) => {
                                    check_c_variadic_abi(tcx, bf.decl, bf.abi, hir_ty.span);
                                    Ty::new_fn_ptr(tcx,
                                        self.lower_fn_ty(hir_ty.hir_id, bf.safety, bf.abi, bf.decl,
                                            None, Some(hir_ty)))
                                }
                                hir::TyKind::UnsafeBinder(binder) =>
                                    Ty::new_unsafe_binder(tcx,
                                        ty::Binder::bind_with_vars(self.lower_ty(binder.inner_ty),
                                            tcx.late_bound_vars(hir_ty.hir_id))),
                                hir::TyKind::TraitObject(bounds, tagged_ptr) => {
                                    let lifetime = tagged_ptr.pointer();
                                    let syntax = tagged_ptr.tag();
                                    self.lower_trait_object_ty(hir_ty.span, hir_ty.hir_id,
                                        bounds, lifetime, syntax)
                                }
                                hir::TyKind::Path(hir::QPath::Resolved(_, path)) if
                                    path.segments.last().and_then(|segment|
                                                segment.args).is_some_and(|args|
                                            {

                                                #[allow(non_exhaustive_omitted_patterns)]
                                                match args.parenthesized {
                                                    hir::GenericArgsParentheses::ReturnTypeNotation => true,
                                                    _ => false,
                                                }
                                            }) => {
                                    let guar =
                                        self.dcx().emit_err(BadReturnTypeNotation {
                                                span: hir_ty.span,
                                                suggestion: None,
                                            });
                                    Ty::new_error(tcx, guar)
                                }
                                hir::TyKind::Path(hir::QPath::Resolved(maybe_qself, path))
                                    => {
                                    {
                                        use ::tracing::__macro_support::Callsite as _;
                                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                            {
                                                static META: ::tracing::Metadata<'static> =
                                                    {
                                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3284",
                                                            "rustc_hir_analysis::hir_ty_lowering",
                                                            ::tracing::Level::DEBUG,
                                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                                            ::tracing_core::__macro_support::Option::Some(3284u32),
                                                            ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                                            ::tracing_core::field::FieldSet::new(&[{
                                                                                const NAME:
                                                                                    ::tracing::__macro_support::FieldName<{
                                                                                        ::tracing::__macro_support::FieldName::len("maybe_qself")
                                                                                    }> =
                                                                                    ::tracing::__macro_support::FieldName::new("maybe_qself");
                                                                                NAME.as_str()
                                                                            },
                                                                            {
                                                                                const NAME:
                                                                                    ::tracing::__macro_support::FieldName<{
                                                                                        ::tracing::__macro_support::FieldName::len("path")
                                                                                    }> =
                                                                                    ::tracing::__macro_support::FieldName::new("path");
                                                                                NAME.as_str()
                                                                            }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                            ::tracing::metadata::Kind::EVENT)
                                                    };
                                                ::tracing::callsite::DefaultCallsite::new(&META)
                                            };
                                        let enabled =
                                            ::tracing::Level::DEBUG <=
                                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                                    ::tracing::Level::DEBUG <=
                                                        ::tracing::level_filters::LevelFilter::current() &&
                                                {
                                                    let interest = __CALLSITE.interest();
                                                    !interest.is_never() &&
                                                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                            interest)
                                                };
                                        if enabled {
                                            (|value_set: ::tracing::field::ValueSet|
                                                        {
                                                            let meta = __CALLSITE.metadata();
                                                            ::tracing::Event::dispatch(meta, &value_set);
                                                            ;
                                                        })({
                                                    #[allow(unused_imports)]
                                                    use ::tracing::field::{debug, display, Value};
                                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&maybe_qself)
                                                                                as &dyn ::tracing::field::Value)),
                                                                    (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&path)
                                                                                as &dyn ::tracing::field::Value))])
                                                });
                                        } else { ; }
                                    };
                                    let opt_self_ty =
                                        maybe_qself.as_ref().map(|qself| self.lower_ty(qself));
                                    self.lower_resolved_ty_path(opt_self_ty, path,
                                        hir_ty.hir_id, PermitVariants::No)
                                }
                                &hir::TyKind::OpaqueDef(opaque_ty) => {
                                    let in_trait =
                                        match opaque_ty.origin {
                                            hir::OpaqueTyOrigin::FnReturn {
                                                parent, in_trait_or_impl: Some(hir::RpitContext::Trait), ..
                                                } | hir::OpaqueTyOrigin::AsyncFn {
                                                parent, in_trait_or_impl: Some(hir::RpitContext::Trait), ..
                                                } => Some(parent),
                                            hir::OpaqueTyOrigin::FnReturn {
                                                in_trait_or_impl: None | Some(hir::RpitContext::TraitImpl),
                                                .. } | hir::OpaqueTyOrigin::AsyncFn {
                                                in_trait_or_impl: None | Some(hir::RpitContext::TraitImpl),
                                                .. } | hir::OpaqueTyOrigin::TyAlias { .. } => None,
                                        };
                                    self.lower_opaque_ty(opaque_ty.def_id, in_trait)
                                }
                                hir::TyKind::TraitAscription(hir_bounds) => {
                                    let self_ty = self.ty_infer(None, hir_ty.span);
                                    let mut bounds = Vec::new();
                                    self.lower_bounds(self_ty, hir_bounds.iter(), &mut bounds,
                                        ty::List::empty(), PredicateFilter::All,
                                        OverlappingAsssocItemConstraints::Allowed);
                                    self.add_implicit_bounds(&mut bounds, self_ty, hir_bounds,
                                        ImpliedBoundsContext::AssociatedTypeOrImplTrait,
                                        hir_ty.span, IncludeSizedImplicitBounds::Yes);
                                    self.register_trait_ascription_bounds(bounds, hir_ty.hir_id,
                                        hir_ty.span);
                                    self_ty
                                }
                                hir::TyKind::Path(hir::QPath::TypeRelative(hir_self_ty,
                                    segment)) if
                                    segment.args.is_some_and(|args|
                                            {

                                                #[allow(non_exhaustive_omitted_patterns)]
                                                match args.parenthesized {
                                                    hir::GenericArgsParentheses::ReturnTypeNotation => true,
                                                    _ => false,
                                                }
                                            }) => {
                                    let guar =
                                        if let hir::Node::LetStmt(stmt) =
                                                                tcx.parent_hir_node(hir_ty.hir_id) && let None = stmt.init
                                                        &&
                                                        let hir::TyKind::Path(hir::QPath::Resolved(_, self_ty_path))
                                                            = hir_self_ty.kind &&
                                                    let Res::Def(DefKind::Enum | DefKind::Struct |
                                                        DefKind::Union, def_id) = self_ty_path.res &&
                                                let Some(_) =
                                                    tcx.inherent_impls(def_id).iter().flat_map(|imp|
                                                                    {
                                                                        tcx.associated_items(*imp).filter_by_name_unhygienic(segment.ident.name)
                                                                    }).filter(|assoc|
                                                                {

                                                                    #[allow(non_exhaustive_omitted_patterns)]
                                                                    match assoc.kind {
                                                                        ty::AssocKind::Fn { has_self: false, .. } => true,
                                                                        _ => false,
                                                                    }
                                                                }).next() {
                                            let mut err =
                                                tcx.dcx().struct_span_err(hir_ty.span,
                                                    "expected type, found associated function call");
                                            if let Some(between) =
                                                    eq_ctxt_suggestion_span(stmt.pat.span, hir_ty.span) {
                                                err.span_suggestion_verbose(between,
                                                    "use `=` if you meant to assign", " = ",
                                                    Applicability::MaybeIncorrect);
                                            }
                                            self.dcx().try_steal_replace_and_emit_err(hir_ty.span,
                                                StashKey::ReturnTypeNotation, err)
                                        } else if let hir::Node::LetStmt(stmt) =
                                                                tcx.parent_hir_node(hir_ty.hir_id) && let None = stmt.init
                                                        &&
                                                        let hir::TyKind::Path(hir::QPath::Resolved(_, self_ty_path))
                                                            = hir_self_ty.kind && let Res::PrimTy(_) = self_ty_path.res
                                                &&
                                                self.dcx().has_stashed_diagnostic(hir_ty.span,
                                                    StashKey::ReturnTypeNotation) {
                                            let mut err =
                                                tcx.dcx().struct_span_err(hir_ty.span,
                                                    "expected type, found associated function call");
                                            if let Some(between) =
                                                    eq_ctxt_suggestion_span(stmt.pat.span, hir_ty.span) {
                                                err.span_suggestion_verbose(between,
                                                    "use `=` if you meant to assign", " = ",
                                                    Applicability::MaybeIncorrect);
                                            }
                                            self.dcx().try_steal_replace_and_emit_err(hir_ty.span,
                                                StashKey::ReturnTypeNotation, err)
                                        } else {
                                            let suggestion =
                                                if self.dcx().has_stashed_diagnostic(hir_ty.span,
                                                        StashKey::ReturnTypeNotation) {
                                                    Some(segment.ident.span.shrink_to_hi().with_hi(hir_ty.span.hi()))
                                                } else { None };
                                            let err =
                                                self.dcx().create_err(BadReturnTypeNotation {
                                                        span: hir_ty.span,
                                                        suggestion,
                                                    });
                                            self.dcx().try_steal_replace_and_emit_err(hir_ty.span,
                                                StashKey::ReturnTypeNotation, err)
                                        };
                                    Ty::new_error(tcx, guar)
                                }
                                hir::TyKind::Path(hir::QPath::TypeRelative(hir_self_ty,
                                    segment)) => {
                                    {
                                        use ::tracing::__macro_support::Callsite as _;
                                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                            {
                                                static META: ::tracing::Metadata<'static> =
                                                    {
                                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3435",
                                                            "rustc_hir_analysis::hir_ty_lowering",
                                                            ::tracing::Level::DEBUG,
                                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                                            ::tracing_core::__macro_support::Option::Some(3435u32),
                                                            ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                                            ::tracing_core::field::FieldSet::new(&[{
                                                                                const NAME:
                                                                                    ::tracing::__macro_support::FieldName<{
                                                                                        ::tracing::__macro_support::FieldName::len("hir_self_ty")
                                                                                    }> =
                                                                                    ::tracing::__macro_support::FieldName::new("hir_self_ty");
                                                                                NAME.as_str()
                                                                            },
                                                                            {
                                                                                const NAME:
                                                                                    ::tracing::__macro_support::FieldName<{
                                                                                        ::tracing::__macro_support::FieldName::len("segment")
                                                                                    }> =
                                                                                    ::tracing::__macro_support::FieldName::new("segment");
                                                                                NAME.as_str()
                                                                            }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                            ::tracing::metadata::Kind::EVENT)
                                                    };
                                                ::tracing::callsite::DefaultCallsite::new(&META)
                                            };
                                        let enabled =
                                            ::tracing::Level::DEBUG <=
                                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                                    ::tracing::Level::DEBUG <=
                                                        ::tracing::level_filters::LevelFilter::current() &&
                                                {
                                                    let interest = __CALLSITE.interest();
                                                    !interest.is_never() &&
                                                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                            interest)
                                                };
                                        if enabled {
                                            (|value_set: ::tracing::field::ValueSet|
                                                        {
                                                            let meta = __CALLSITE.metadata();
                                                            ::tracing::Event::dispatch(meta, &value_set);
                                                            ;
                                                        })({
                                                    #[allow(unused_imports)]
                                                    use ::tracing::field::{debug, display, Value};
                                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_self_ty)
                                                                                as &dyn ::tracing::field::Value)),
                                                                    (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&segment)
                                                                                as &dyn ::tracing::field::Value))])
                                                });
                                        } else { ; }
                                    };
                                    let self_ty = self.lower_ty(hir_self_ty);
                                    self.lower_type_relative_ty_path(self_ty, hir_self_ty,
                                                segment, hir_ty.hir_id, hir_ty.span,
                                                PermitVariants::No).map(|(ty, _, _)|
                                                ty).unwrap_or_else(|guar| Ty::new_error(tcx, guar))
                                }
                                hir::TyKind::Array(ty, length) => {
                                    let length = self.lower_const_arg(length, tcx.types.usize);
                                    Ty::new_array_with_const_len(tcx, self.lower_ty(ty), length)
                                }
                                hir::TyKind::Infer(()) => {
                                    self.ty_infer(None, hir_ty.span)
                                }
                                hir::TyKind::Pat(ty, pat) => {
                                    let ty_span = ty.span;
                                    let ty = self.lower_ty(ty);
                                    let pat_ty =
                                        match self.lower_pat_ty_pat(ty, ty_span, pat) {
                                            Ok(kind) => Ty::new_pat(tcx, ty, tcx.mk_pat(kind)),
                                            Err(guar) => Ty::new_error(tcx, guar),
                                        };
                                    self.record_ty(pat.hir_id, ty, pat.span);
                                    pat_ty
                                }
                                hir::TyKind::FieldOf(ty, hir::TyFieldPath { variant, field
                                    }) =>
                                    self.lower_field_of(self.lower_ty(ty), self.mod_id(),
                                        ty.span, hir_ty.hir_id, *variant, *field),
                                hir::TyKind::View(ty, fields) => {
                                    self.lower_view(self.lower_ty(ty), fields, hir_ty.span)
                                }
                                hir::TyKind::Err(guar) => Ty::new_error(tcx, *guar),
                            };
                        self.record_ty(hir_ty.hir_id, result_ty, hir_ty.span);
                        result_ty
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3232",
                        "rustc_hir_analysis::hir_ty_lowering",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(3232u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
3233    pub fn lower_ty(&self, hir_ty: &hir::Ty<'_>) -> Ty<'tcx> {
3234        let tcx = self.tcx();
3235
3236        let result_ty = match &hir_ty.kind {
3237            hir::TyKind::InferDelegation(infer) => self.lower_delegation_ty(*infer),
3238            hir::TyKind::Slice(ty) => Ty::new_slice(tcx, self.lower_ty(ty)),
3239            hir::TyKind::Ptr(ty, mutbl) => Ty::new_ptr(tcx, self.lower_ty(ty), *mutbl),
3240            hir::TyKind::Ref(region, ty, mutbl) => {
3241                let r = self.lower_lifetime(region, RegionInferReason::Reference);
3242                debug!(?r);
3243                let t = self.lower_ty(ty);
3244                Ty::new_ref(tcx, r, t, *mutbl)
3245            }
3246            hir::TyKind::Never => tcx.types.never,
3247            hir::TyKind::Tup(fields) => {
3248                Ty::new_tup_from_iter(tcx, fields.iter().map(|t| self.lower_ty(t)))
3249            }
3250            hir::TyKind::FnPtr(bf) => {
3251                check_c_variadic_abi(tcx, bf.decl, bf.abi, hir_ty.span);
3252
3253                Ty::new_fn_ptr(
3254                    tcx,
3255                    self.lower_fn_ty(hir_ty.hir_id, bf.safety, bf.abi, bf.decl, None, Some(hir_ty)),
3256                )
3257            }
3258            hir::TyKind::UnsafeBinder(binder) => Ty::new_unsafe_binder(
3259                tcx,
3260                ty::Binder::bind_with_vars(
3261                    self.lower_ty(binder.inner_ty),
3262                    tcx.late_bound_vars(hir_ty.hir_id),
3263                ),
3264            ),
3265            hir::TyKind::TraitObject(bounds, tagged_ptr) => {
3266                let lifetime = tagged_ptr.pointer();
3267                let syntax = tagged_ptr.tag();
3268                self.lower_trait_object_ty(hir_ty.span, hir_ty.hir_id, bounds, lifetime, syntax)
3269            }
3270            // If we encounter a fully qualified path with RTN generics, then it must have
3271            // *not* gone through `lower_ty_maybe_return_type_notation`, and therefore
3272            // it's certainly in an illegal position.
3273            hir::TyKind::Path(hir::QPath::Resolved(_, path))
3274                if path.segments.last().and_then(|segment| segment.args).is_some_and(|args| {
3275                    matches!(args.parenthesized, hir::GenericArgsParentheses::ReturnTypeNotation)
3276                }) =>
3277            {
3278                let guar = self
3279                    .dcx()
3280                    .emit_err(BadReturnTypeNotation { span: hir_ty.span, suggestion: None });
3281                Ty::new_error(tcx, guar)
3282            }
3283            hir::TyKind::Path(hir::QPath::Resolved(maybe_qself, path)) => {
3284                debug!(?maybe_qself, ?path);
3285                let opt_self_ty = maybe_qself.as_ref().map(|qself| self.lower_ty(qself));
3286                self.lower_resolved_ty_path(opt_self_ty, path, hir_ty.hir_id, PermitVariants::No)
3287            }
3288            &hir::TyKind::OpaqueDef(opaque_ty) => {
3289                // If this is an RPITIT and we are using the new RPITIT lowering scheme, we
3290                // generate the def_id of an associated type for the trait and return as
3291                // type a projection.
3292                let in_trait = match opaque_ty.origin {
3293                    hir::OpaqueTyOrigin::FnReturn {
3294                        parent,
3295                        in_trait_or_impl: Some(hir::RpitContext::Trait),
3296                        ..
3297                    }
3298                    | hir::OpaqueTyOrigin::AsyncFn {
3299                        parent,
3300                        in_trait_or_impl: Some(hir::RpitContext::Trait),
3301                        ..
3302                    } => Some(parent),
3303                    hir::OpaqueTyOrigin::FnReturn {
3304                        in_trait_or_impl: None | Some(hir::RpitContext::TraitImpl),
3305                        ..
3306                    }
3307                    | hir::OpaqueTyOrigin::AsyncFn {
3308                        in_trait_or_impl: None | Some(hir::RpitContext::TraitImpl),
3309                        ..
3310                    }
3311                    | hir::OpaqueTyOrigin::TyAlias { .. } => None,
3312                };
3313
3314                self.lower_opaque_ty(opaque_ty.def_id, in_trait)
3315            }
3316            hir::TyKind::TraitAscription(hir_bounds) => {
3317                // Impl trait in bindings lower as an infer var with additional
3318                // set of type bounds.
3319                let self_ty = self.ty_infer(None, hir_ty.span);
3320                let mut bounds = Vec::new();
3321                self.lower_bounds(
3322                    self_ty,
3323                    hir_bounds.iter(),
3324                    &mut bounds,
3325                    ty::List::empty(),
3326                    PredicateFilter::All,
3327                    OverlappingAsssocItemConstraints::Allowed,
3328                );
3329                self.add_implicit_bounds(
3330                    &mut bounds,
3331                    self_ty,
3332                    hir_bounds,
3333                    ImpliedBoundsContext::AssociatedTypeOrImplTrait,
3334                    hir_ty.span,
3335                    IncludeSizedImplicitBounds::Yes,
3336                );
3337                self.register_trait_ascription_bounds(bounds, hir_ty.hir_id, hir_ty.span);
3338                self_ty
3339            }
3340            // If we encounter a type relative path with RTN generics, then it must have
3341            // *not* gone through `lower_ty_maybe_return_type_notation`, and therefore
3342            // it's certainly in an illegal position.
3343            hir::TyKind::Path(hir::QPath::TypeRelative(hir_self_ty, segment))
3344                if segment.args.is_some_and(|args| {
3345                    matches!(args.parenthesized, hir::GenericArgsParentheses::ReturnTypeNotation)
3346                }) =>
3347            {
3348                let guar = if let hir::Node::LetStmt(stmt) = tcx.parent_hir_node(hir_ty.hir_id)
3349                    && let None = stmt.init
3350                    && let hir::TyKind::Path(hir::QPath::Resolved(_, self_ty_path)) =
3351                        hir_self_ty.kind
3352                    && let Res::Def(DefKind::Enum | DefKind::Struct | DefKind::Union, def_id) =
3353                        self_ty_path.res
3354                    && let Some(_) = tcx
3355                        .inherent_impls(def_id)
3356                        .iter()
3357                        .flat_map(|imp| {
3358                            tcx.associated_items(*imp).filter_by_name_unhygienic(segment.ident.name)
3359                        })
3360                        .filter(|assoc| {
3361                            matches!(assoc.kind, ty::AssocKind::Fn { has_self: false, .. })
3362                        })
3363                        .next()
3364                {
3365                    // `let x: S::new(valid_in_ty_ctxt);` -> `let x = S::new(valid_in_ty_ctxt);`
3366                    let mut err = tcx.dcx().struct_span_err(
3367                        hir_ty.span,
3368                        "expected type, found associated function call",
3369                    );
3370                    if let Some(between) = eq_ctxt_suggestion_span(stmt.pat.span, hir_ty.span) {
3371                        err.span_suggestion_verbose(
3372                            between,
3373                            "use `=` if you meant to assign",
3374                            " = ",
3375                            Applicability::MaybeIncorrect,
3376                        );
3377                    }
3378                    self.dcx().try_steal_replace_and_emit_err(
3379                        hir_ty.span,
3380                        StashKey::ReturnTypeNotation,
3381                        err,
3382                    )
3383                } else if let hir::Node::LetStmt(stmt) = tcx.parent_hir_node(hir_ty.hir_id)
3384                    && let None = stmt.init
3385                    && let hir::TyKind::Path(hir::QPath::Resolved(_, self_ty_path)) =
3386                        hir_self_ty.kind
3387                    && let Res::PrimTy(_) = self_ty_path.res
3388                    && self.dcx().has_stashed_diagnostic(hir_ty.span, StashKey::ReturnTypeNotation)
3389                {
3390                    // `let x: i32::something(valid_in_ty_ctxt);` -> `let x = i32::something(valid_in_ty_ctxt);`
3391                    // FIXME: Check that `something` is a valid function in `i32`.
3392                    let mut err = tcx.dcx().struct_span_err(
3393                        hir_ty.span,
3394                        "expected type, found associated function call",
3395                    );
3396                    if let Some(between) = eq_ctxt_suggestion_span(stmt.pat.span, hir_ty.span) {
3397                        err.span_suggestion_verbose(
3398                            between,
3399                            "use `=` if you meant to assign",
3400                            " = ",
3401                            Applicability::MaybeIncorrect,
3402                        );
3403                    }
3404                    self.dcx().try_steal_replace_and_emit_err(
3405                        hir_ty.span,
3406                        StashKey::ReturnTypeNotation,
3407                        err,
3408                    )
3409                } else {
3410                    let suggestion = if self
3411                        .dcx()
3412                        .has_stashed_diagnostic(hir_ty.span, StashKey::ReturnTypeNotation)
3413                    {
3414                        // We already created a diagnostic complaining that `foo(bar)` is wrong and
3415                        // should have been `foo(..)`. Instead, emit only the current error and
3416                        // include that prior suggestion. Changes are that the problems go further,
3417                        // but keep the suggestion just in case. Either way, we want a single error
3418                        // instead of two.
3419                        Some(segment.ident.span.shrink_to_hi().with_hi(hir_ty.span.hi()))
3420                    } else {
3421                        None
3422                    };
3423                    let err = self
3424                        .dcx()
3425                        .create_err(BadReturnTypeNotation { span: hir_ty.span, suggestion });
3426                    self.dcx().try_steal_replace_and_emit_err(
3427                        hir_ty.span,
3428                        StashKey::ReturnTypeNotation,
3429                        err,
3430                    )
3431                };
3432                Ty::new_error(tcx, guar)
3433            }
3434            hir::TyKind::Path(hir::QPath::TypeRelative(hir_self_ty, segment)) => {
3435                debug!(?hir_self_ty, ?segment);
3436                let self_ty = self.lower_ty(hir_self_ty);
3437                self.lower_type_relative_ty_path(
3438                    self_ty,
3439                    hir_self_ty,
3440                    segment,
3441                    hir_ty.hir_id,
3442                    hir_ty.span,
3443                    PermitVariants::No,
3444                )
3445                .map(|(ty, _, _)| ty)
3446                .unwrap_or_else(|guar| Ty::new_error(tcx, guar))
3447            }
3448            hir::TyKind::Array(ty, length) => {
3449                let length = self.lower_const_arg(length, tcx.types.usize);
3450                Ty::new_array_with_const_len(tcx, self.lower_ty(ty), length)
3451            }
3452            hir::TyKind::Infer(()) => {
3453                // Infer also appears as the type of arguments or return
3454                // values in an ExprKind::Closure, or as
3455                // the type of local variables. Both of these cases are
3456                // handled specially and will not descend into this routine.
3457                self.ty_infer(None, hir_ty.span)
3458            }
3459            hir::TyKind::Pat(ty, pat) => {
3460                let ty_span = ty.span;
3461                let ty = self.lower_ty(ty);
3462                let pat_ty = match self.lower_pat_ty_pat(ty, ty_span, pat) {
3463                    Ok(kind) => Ty::new_pat(tcx, ty, tcx.mk_pat(kind)),
3464                    Err(guar) => Ty::new_error(tcx, guar),
3465                };
3466                self.record_ty(pat.hir_id, ty, pat.span);
3467                pat_ty
3468            }
3469            hir::TyKind::FieldOf(ty, hir::TyFieldPath { variant, field }) => self.lower_field_of(
3470                self.lower_ty(ty),
3471                self.mod_id(),
3472                ty.span,
3473                hir_ty.hir_id,
3474                *variant,
3475                *field,
3476            ),
3477            hir::TyKind::View(ty, fields) => {
3478                self.lower_view(self.lower_ty(ty), fields, hir_ty.span)
3479            }
3480
3481            hir::TyKind::Err(guar) => Ty::new_error(tcx, *guar),
3482        };
3483
3484        self.record_ty(hir_ty.hir_id, result_ty, hir_ty.span);
3485        result_ty
3486    }
3487
3488    fn lower_pat_ty_pat(
3489        &self,
3490        ty: Ty<'tcx>,
3491        ty_span: Span,
3492        pat: &hir::TyPat<'_>,
3493    ) -> Result<ty::PatternKind<'tcx>, ErrorGuaranteed> {
3494        let tcx = self.tcx();
3495        match pat.kind {
3496            hir::TyPatKind::Range(start, end) => {
3497                match ty.kind() {
3498                    // Keep this list of types in sync with the list of types that
3499                    // the `RangePattern` trait is implemented for.
3500                    ty::Int(_) | ty::Uint(_) | ty::Char => {
3501                        let start = self.lower_const_arg(start, ty);
3502                        let end = self.lower_const_arg(end, ty);
3503                        Ok(ty::PatternKind::Range { start, end })
3504                    }
3505                    _ => Err(self
3506                        .dcx()
3507                        .span_delayed_bug(ty_span, "invalid base type for range pattern")),
3508                }
3509            }
3510            hir::TyPatKind::NotNull => Ok(ty::PatternKind::NotNull),
3511            hir::TyPatKind::Or(patterns) => {
3512                self.tcx()
3513                    .mk_patterns_from_iter(patterns.iter().map(|pat| {
3514                        self.lower_pat_ty_pat(ty, ty_span, pat).map(|pat| tcx.mk_pat(pat))
3515                    }))
3516                    .map(ty::PatternKind::Or)
3517            }
3518            hir::TyPatKind::Err(e) => Err(e),
3519        }
3520    }
3521
3522    fn lower_field_of(
3523        &self,
3524        ty: Ty<'tcx>,
3525        mod_id: LocalModId,
3526        ty_span: Span,
3527        hir_id: HirId,
3528        variant: Option<Ident>,
3529        field: Ident,
3530    ) -> Ty<'tcx> {
3531        let dcx = self.dcx();
3532        let tcx = self.tcx();
3533        match ty.kind() {
3534            ty::Adt(def, _) => {
3535                let base_did = def.did();
3536                let kind_name = tcx.def_descr(base_did);
3537                let (variant_idx, variant) = if def.is_enum() {
3538                    let Some(variant) = variant else {
3539                        let err = dcx
3540                            .create_err(NoVariantNamed { span: field.span, ident: field, ty })
3541                            .with_span_help(
3542                                field.span.shrink_to_lo(),
3543                                "you might be missing a variant here: `Variant.`",
3544                            )
3545                            .emit_err();
3546                        return Ty::new_error(tcx, err);
3547                    };
3548
3549                    if let Some(res) = def
3550                        .variants()
3551                        .iter_enumerated()
3552                        .find(|(_, f)| f.ident(tcx).normalize_to_macros_2_0() == variant)
3553                    {
3554                        res
3555                    } else {
3556                        let err =
3557                            dcx.emit_err(NoVariantNamed { span: variant.span, ident: variant, ty });
3558                        return Ty::new_error(tcx, err);
3559                    }
3560                } else {
3561                    if let Some(variant) = variant {
3562                        let adt_path = tcx.def_path_str(base_did);
3563                        {
    dcx.struct_span_err(variant.span,
            ::alloc::__export::must_use({
                    ::alloc::fmt::format(format_args!("{0} `{1}` does not have any variants",
                            kind_name, adt_path))
                })).with_code(E0609)
}struct_span_code_err!(
3564                            dcx,
3565                            variant.span,
3566                            E0609,
3567                            "{kind_name} `{adt_path}` does not have any variants",
3568                        )
3569                        .with_span_label(variant.span, "variant unknown")
3570                        .emit();
3571                    }
3572                    (FIRST_VARIANT, def.non_enum_variant())
3573                };
3574                let (ident, def_scope) = tcx.adjust_ident_and_get_scope(field, def.did(), mod_id);
3575                if let Some((field_idx, field)) = variant
3576                    .fields
3577                    .iter_enumerated()
3578                    .find(|(_, f)| f.ident(tcx).normalize_to_macros_2_0() == ident)
3579                {
3580                    if field.vis.is_accessible_from(def_scope, tcx) {
3581                        tcx.check_stability(field.did, Some(hir_id), ident.span, None);
3582                    } else {
3583                        let adt_path = tcx.def_path_str(base_did);
3584                        {
    dcx.struct_span_err(ident.span,
            ::alloc::__export::must_use({
                    ::alloc::fmt::format(format_args!("field `{0}` of {1} `{2}` is private",
                            ident, kind_name, adt_path))
                })).with_code(E0616)
}struct_span_code_err!(
3585                            dcx,
3586                            ident.span,
3587                            E0616,
3588                            "field `{ident}` of {kind_name} `{adt_path}` is private",
3589                        )
3590                        .with_span_label(ident.span, "private field")
3591                        .emit();
3592                    }
3593                    Ty::new_field_representing_type(tcx, ty, variant_idx, field_idx)
3594                } else {
3595                    let err = dcx.emit_err(NoFieldOnType { span: ident.span, field: ident, ty });
3596                    Ty::new_error(tcx, err)
3597                }
3598            }
3599            ty::Tuple(tys) => {
3600                let index = match field.as_str().parse::<usize>() {
3601                    Ok(idx) => idx,
3602                    Err(_) => {
3603                        let err = dcx.emit_err(NoFieldOnType { span: field.span, field, ty });
3604                        return Ty::new_error(tcx, err);
3605                    }
3606                };
3607                if field.name != sym::integer(index) {
3608                    ::rustc_span::macros::bug_impl(None,
    format_args!("we parsed above, but now not equal?"), Location::caller());bug!("we parsed above, but now not equal?");
3609                }
3610                if tys.get(index).is_some() {
3611                    Ty::new_field_representing_type(tcx, ty, FIRST_VARIANT, index.into())
3612                } else {
3613                    let err = dcx.emit_err(NoFieldOnType { span: field.span, field, ty });
3614                    Ty::new_error(tcx, err)
3615                }
3616            }
3617            // FIXME(FRTs): support type aliases
3618            /*
3619            ty::Alias(AliasTyKind::Free, ty) => {
3620                return self.lower_field_of(
3621                    ty,
3622                    item_def_id,
3623                    ty_span,
3624                    hir_id,
3625                    variant,
3626                    field,
3627                );
3628            }*/
3629            ty::Alias(..) => Ty::new_error(
3630                tcx,
3631                dcx.span_err(ty_span, ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("could not resolve fields of `{0}`",
                ty))
    })format!("could not resolve fields of `{ty}`")),
3632            ),
3633            ty::Error(err) => Ty::new_error(tcx, *err),
3634            ty::Bool
3635            | ty::Char
3636            | ty::Int(_)
3637            | ty::Uint(_)
3638            | ty::Float(_)
3639            | ty::Foreign(_)
3640            | ty::Str
3641            | ty::RawPtr(_, _)
3642            | ty::Ref(_, _, _)
3643            | ty::FnDef(_, _)
3644            | ty::FnPtr(_, _)
3645            | ty::UnsafeBinder(_)
3646            | ty::Dynamic(_, _)
3647            | ty::Closure(_, _)
3648            | ty::CoroutineClosure(_, _)
3649            | ty::Coroutine(_, _)
3650            | ty::CoroutineWitness(_, _)
3651            | ty::Never
3652            | ty::Param(_)
3653            | ty::Bound(_, _)
3654            | ty::Placeholder(_)
3655            | ty::Slice(..) => Ty::new_error(
3656                tcx,
3657                dcx.span_err(ty_span, ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("type `{0}` doesn\'t have fields",
                ty))
    })format!("type `{ty}` doesn't have fields")),
3658            ),
3659            ty::Infer(_) => Ty::new_error(
3660                tcx,
3661                dcx.span_err(ty_span, ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("cannot use `{0}` in this position",
                ty))
    })format!("cannot use `{ty}` in this position")),
3662            ),
3663            // FIXME(FRTs): support these types?
3664            ty::Array(..) | ty::Pat(..) => Ty::new_error(
3665                tcx,
3666                dcx.span_err(ty_span, ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("type `{0}` is not yet supported in `field_of!`",
                ty))
    })format!("type `{ty}` is not yet supported in `field_of!`")),
3667            ),
3668        }
3669    }
3670
3671    /// Lower an opaque type (i.e., an existential impl-Trait type) from the HIR.
3672    {}
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("lower_opaque_ty",
                                "rustc_hir_analysis::hir_ty_lowering",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                ::tracing_core::__macro_support::Option::Some(3672u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("def_id")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("def_id");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("in_trait")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("in_trait");
                                                    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(&def_id)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&in_trait)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[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: Ty<'tcx> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        let tcx = self.tcx();
                        let lifetimes = tcx.opaque_captured_lifetimes(def_id);
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3677",
                                                "rustc_hir_analysis::hir_ty_lowering",
                                                ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                                ::tracing_core::__macro_support::Option::Some(3677u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("lifetimes")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("lifetimes");
                                                                    NAME.as_str()
                                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                ::tracing::metadata::Kind::EVENT)
                                        };
                                    ::tracing::callsite::DefaultCallsite::new(&META)
                                };
                            let enabled =
                                ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                        ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::LevelFilter::current() &&
                                    {
                                        let interest = __CALLSITE.interest();
                                        !interest.is_never() &&
                                            ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                interest)
                                    };
                            if enabled {
                                (|value_set: ::tracing::field::ValueSet|
                                            {
                                                let meta = __CALLSITE.metadata();
                                                ::tracing::Event::dispatch(meta, &value_set);
                                                ;
                                            })({
                                        #[allow(unused_imports)]
                                        use ::tracing::field::{debug, display, Value};
                                        __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&lifetimes)
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        let def_id =
                            if let Some(parent_def_id) = in_trait {
                                *tcx.associated_types_for_impl_traits_in_associated_fn(parent_def_id.to_def_id()).iter().find(|rpitit|
                                                match tcx.opt_rpitit_info(**rpitit) {
                                                    Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. })
                                                        => {
                                                        opaque_def_id.expect_local() == def_id
                                                    }
                                                    _ => ::core::panicking::unreachable_default_msg(),
                                                }).unwrap()
                            } else { def_id.to_def_id() };
                        let generics = tcx.generics_of(def_id);
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3697",
                                                "rustc_hir_analysis::hir_ty_lowering",
                                                ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                                ::tracing_core::__macro_support::Option::Some(3697u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("generics")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("generics");
                                                                    NAME.as_str()
                                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                ::tracing::metadata::Kind::EVENT)
                                        };
                                    ::tracing::callsite::DefaultCallsite::new(&META)
                                };
                            let enabled =
                                ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                        ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::LevelFilter::current() &&
                                    {
                                        let interest = __CALLSITE.interest();
                                        !interest.is_never() &&
                                            ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                interest)
                                    };
                            if enabled {
                                (|value_set: ::tracing::field::ValueSet|
                                            {
                                                let meta = __CALLSITE.metadata();
                                                ::tracing::Event::dispatch(meta, &value_set);
                                                ;
                                            })({
                                        #[allow(unused_imports)]
                                        use ::tracing::field::{debug, display, Value};
                                        __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&generics)
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        let offset = generics.count() - lifetimes.len();
                        let args =
                            ty::GenericArgs::for_item(tcx, def_id,
                                |param, _|
                                    {
                                        if let Some(i) = (param.index as usize).checked_sub(offset)
                                            {
                                            let (lifetime, _) = lifetimes[i];
                                            self.lower_resolved_lifetime(lifetime).into()
                                        } else { tcx.mk_param_from_def(param) }
                                    });
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3713",
                                                "rustc_hir_analysis::hir_ty_lowering",
                                                ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                                ::tracing_core::__macro_support::Option::Some(3713u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    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::EVENT)
                                        };
                                    ::tracing::callsite::DefaultCallsite::new(&META)
                                };
                            let enabled =
                                ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                        ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::LevelFilter::current() &&
                                    {
                                        let interest = __CALLSITE.interest();
                                        !interest.is_never() &&
                                            ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                interest)
                                    };
                            if enabled {
                                (|value_set: ::tracing::field::ValueSet|
                                            {
                                                let meta = __CALLSITE.metadata();
                                                ::tracing::Event::dispatch(meta, &value_set);
                                                ;
                                            })({
                                        #[allow(unused_imports)]
                                        use ::tracing::field::{debug, display, Value};
                                        __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        if in_trait.is_some() {
                            Ty::new_projection_from_args(tcx, ty::IsRigid::No, def_id,
                                args)
                        } else {
                            Ty::new_opaque(tcx, ty::IsRigid::No, def_id, args)
                        }
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3672",
                        "rustc_hir_analysis::hir_ty_lowering",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(3672u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
3673    fn lower_opaque_ty(&self, def_id: LocalDefId, in_trait: Option<LocalDefId>) -> Ty<'tcx> {
3674        let tcx = self.tcx();
3675
3676        let lifetimes = tcx.opaque_captured_lifetimes(def_id);
3677        debug!(?lifetimes);
3678
3679        // If this is an RPITIT and we are using the new RPITIT lowering scheme,
3680        // do a linear search to map this to the synthetic associated type that
3681        // it will be lowered to.
3682        let def_id = if let Some(parent_def_id) = in_trait {
3683            *tcx.associated_types_for_impl_traits_in_associated_fn(parent_def_id.to_def_id())
3684                .iter()
3685                .find(|rpitit| match tcx.opt_rpitit_info(**rpitit) {
3686                    Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => {
3687                        opaque_def_id.expect_local() == def_id
3688                    }
3689                    _ => unreachable!(),
3690                })
3691                .unwrap()
3692        } else {
3693            def_id.to_def_id()
3694        };
3695
3696        let generics = tcx.generics_of(def_id);
3697        debug!(?generics);
3698
3699        // We use `generics.count() - lifetimes.len()` here instead of `generics.parent_count`
3700        // since return-position impl trait in trait squashes all of the generics from its source fn
3701        // into its own generics, so the opaque's "own" params isn't always just lifetimes.
3702        let offset = generics.count() - lifetimes.len();
3703
3704        let args = ty::GenericArgs::for_item(tcx, def_id, |param, _| {
3705            if let Some(i) = (param.index as usize).checked_sub(offset) {
3706                let (lifetime, _) = lifetimes[i];
3707                // FIXME(mgca): should we be calling self.check_params_use_if_mcg here too?
3708                self.lower_resolved_lifetime(lifetime).into()
3709            } else {
3710                tcx.mk_param_from_def(param)
3711            }
3712        });
3713        debug!(?args);
3714
3715        if in_trait.is_some() {
3716            Ty::new_projection_from_args(tcx, ty::IsRigid::No, def_id, args)
3717        } else {
3718            Ty::new_opaque(tcx, ty::IsRigid::No, def_id, args)
3719        }
3720    }
3721
3722    /// Lower a function type from the HIR to our internal notion of a function signature.
3723    {}
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("lower_fn_ty",
                                "rustc_hir_analysis::hir_ty_lowering",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                ::tracing_core::__macro_support::Option::Some(3723u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                ::tracing_core::field::FieldSet::new(&[],
                                    ::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,
                    &{ meta.fields().value_set_all(&[]) })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[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: ty::PolyFnSig<'tcx> =
                            loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        let tcx = self.tcx();
                        let bound_vars = tcx.late_bound_vars(hir_id);
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3735",
                                                "rustc_hir_analysis::hir_ty_lowering",
                                                ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                                ::tracing_core::__macro_support::Option::Some(3735u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("bound_vars")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("bound_vars");
                                                                    NAME.as_str()
                                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                ::tracing::metadata::Kind::EVENT)
                                        };
                                    ::tracing::callsite::DefaultCallsite::new(&META)
                                };
                            let enabled =
                                ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                        ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::LevelFilter::current() &&
                                    {
                                        let interest = __CALLSITE.interest();
                                        !interest.is_never() &&
                                            ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                interest)
                                    };
                            if enabled {
                                (|value_set: ::tracing::field::ValueSet|
                                            {
                                                let meta = __CALLSITE.metadata();
                                                ::tracing::Event::dispatch(meta, &value_set);
                                                ;
                                            })({
                                        #[allow(unused_imports)]
                                        use ::tracing::field::{debug, display, Value};
                                        __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&bound_vars)
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        let (input_tys, output_ty) =
                            self.lower_fn_sig(decl, generics, hir_id, hir_ty);
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3739",
                                                "rustc_hir_analysis::hir_ty_lowering",
                                                ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                                ::tracing_core::__macro_support::Option::Some(3739u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("output_ty")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("output_ty");
                                                                    NAME.as_str()
                                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                ::tracing::metadata::Kind::EVENT)
                                        };
                                    ::tracing::callsite::DefaultCallsite::new(&META)
                                };
                            let enabled =
                                ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                        ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::LevelFilter::current() &&
                                    {
                                        let interest = __CALLSITE.interest();
                                        !interest.is_never() &&
                                            ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                interest)
                                    };
                            if enabled {
                                (|value_set: ::tracing::field::ValueSet|
                                            {
                                                let meta = __CALLSITE.metadata();
                                                ::tracing::Event::dispatch(meta, &value_set);
                                                ;
                                            })({
                                        #[allow(unused_imports)]
                                        use ::tracing::field::{debug, display, Value};
                                        __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&output_ty)
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3741",
                                                "rustc_hir_analysis::hir_ty_lowering",
                                                ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                                ::tracing_core::__macro_support::Option::Some(3741u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("abi")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("abi");
                                                                    NAME.as_str()
                                                                },
                                                                {
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("safety")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("safety");
                                                                    NAME.as_str()
                                                                },
                                                                {
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("decl.fn_decl_kind")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("decl.fn_decl_kind");
                                                                    NAME.as_str()
                                                                },
                                                                {
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("input_tys_len")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("input_tys_len");
                                                                    NAME.as_str()
                                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                ::tracing::metadata::Kind::EVENT)
                                        };
                                    ::tracing::callsite::DefaultCallsite::new(&META)
                                };
                            let enabled =
                                ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                        ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::LevelFilter::current() &&
                                    {
                                        let interest = __CALLSITE.interest();
                                        !interest.is_never() &&
                                            ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                interest)
                                    };
                            if enabled {
                                (|value_set: ::tracing::field::ValueSet|
                                            {
                                                let meta = __CALLSITE.metadata();
                                                ::tracing::Event::dispatch(meta, &value_set);
                                                ;
                                            })({
                                        #[allow(unused_imports)]
                                        use ::tracing::field::{debug, display, Value};
                                        __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&abi)
                                                                    as &dyn ::tracing::field::Value)),
                                                        (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&safety)
                                                                    as &dyn ::tracing::field::Value)),
                                                        (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&decl.fn_decl_kind)
                                                                    as &dyn ::tracing::field::Value)),
                                                        (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&input_tys.len())
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        let fn_sig_kind =
                            FnSigKind::default().set_abi(abi).set_safety(safety).set_c_variadic(decl.fn_decl_kind.c_variadic()).set_splatted(decl.splatted(),
                                    input_tys.len()).unwrap();
                        let fn_ty =
                            tcx.mk_fn_sig(input_tys, output_ty, fn_sig_kind);
                        let fn_ptr_ty =
                            ty::Binder::bind_with_vars(fn_ty, bound_vars);
                        if let Some(hir::Ty {
                                kind: hir::TyKind::FnPtr(fn_ptr_ty), span, .. }) = hir_ty {
                            check_abi(tcx, hir_id, *span, fn_ptr_ty.abi);
                        }
                        cmse::validate_cmse_abi(self.tcx(), self.dcx(), hir_id, abi,
                            fn_ptr_ty);
                        if !fn_ptr_ty.references_error() {
                            let inputs = fn_ptr_ty.inputs();
                            let late_bound_in_args =
                                tcx.collect_constrained_late_bound_regions(inputs.map_bound(|i|
                                            i.to_owned()));
                            let output = fn_ptr_ty.output();
                            let late_bound_in_ret =
                                tcx.collect_referenced_late_bound_regions(output);
                            self.validate_late_bound_regions(late_bound_in_args,
                                late_bound_in_ret,
                                |br_name|
                                    {
                                        {
                                            self.dcx().struct_span_err(decl.output.span(),
                                                    ::alloc::__export::must_use({
                                                            ::alloc::fmt::format(format_args!("return type references {0}, which is not constrained by the fn input types",
                                                                    br_name))
                                                        })).with_code(E0581)
                                        }
                                    });
                        }
                        fn_ptr_ty
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3723",
                        "rustc_hir_analysis::hir_ty_lowering",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(3723u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip(self, hir_id, safety, abi, decl, generics, hir_ty), ret)]
3724    pub fn lower_fn_ty(
3725        &self,
3726        hir_id: HirId,
3727        safety: hir::Safety,
3728        abi: rustc_abi::ExternAbi,
3729        decl: &hir::FnDecl<'_>,
3730        generics: Option<&hir::Generics<'_>>,
3731        hir_ty: Option<&hir::Ty<'_>>,
3732    ) -> ty::PolyFnSig<'tcx> {
3733        let tcx = self.tcx();
3734        let bound_vars = tcx.late_bound_vars(hir_id);
3735        debug!(?bound_vars);
3736
3737        let (input_tys, output_ty) = self.lower_fn_sig(decl, generics, hir_id, hir_ty);
3738
3739        debug!(?output_ty);
3740
3741        debug!(?abi, ?safety, ?decl.fn_decl_kind, input_tys_len = ?input_tys.len());
3742        let fn_sig_kind = FnSigKind::default()
3743            .set_abi(abi)
3744            .set_safety(safety)
3745            .set_c_variadic(decl.fn_decl_kind.c_variadic())
3746            .set_splatted(decl.splatted(), input_tys.len())
3747            .unwrap();
3748        let fn_ty = tcx.mk_fn_sig(input_tys, output_ty, fn_sig_kind);
3749        let fn_ptr_ty = ty::Binder::bind_with_vars(fn_ty, bound_vars);
3750
3751        if let Some(hir::Ty { kind: hir::TyKind::FnPtr(fn_ptr_ty), span, .. }) = hir_ty {
3752            check_abi(tcx, hir_id, *span, fn_ptr_ty.abi);
3753        }
3754
3755        // reject function types that violate cmse ABI requirements
3756        cmse::validate_cmse_abi(self.tcx(), self.dcx(), hir_id, abi, fn_ptr_ty);
3757
3758        if !fn_ptr_ty.references_error() {
3759            // Find any late-bound regions declared in return type that do
3760            // not appear in the arguments. These are not well-formed.
3761            //
3762            // Example:
3763            //     for<'a> fn() -> &'a str <-- 'a is bad
3764            //     for<'a> fn(&'a String) -> &'a str <-- 'a is ok
3765            let inputs = fn_ptr_ty.inputs();
3766            let late_bound_in_args =
3767                tcx.collect_constrained_late_bound_regions(inputs.map_bound(|i| i.to_owned()));
3768            let output = fn_ptr_ty.output();
3769            let late_bound_in_ret = tcx.collect_referenced_late_bound_regions(output);
3770
3771            self.validate_late_bound_regions(late_bound_in_args, late_bound_in_ret, |br_name| {
3772                struct_span_code_err!(
3773                    self.dcx(),
3774                    decl.output.span(),
3775                    E0581,
3776                    "return type references {}, which is not constrained by the fn input types",
3777                    br_name
3778                )
3779            });
3780        }
3781
3782        fn_ptr_ty
3783    }
3784
3785    /// Given a fn_hir_id for a impl function, suggest the type that is found on the
3786    /// corresponding function in the trait that the impl implements, if it exists.
3787    /// If arg_idx is Some, then it corresponds to an input type index, otherwise it
3788    /// corresponds to the return type.
3789    pub(super) fn suggest_trait_fn_ty_for_impl_fn_infer(
3790        &self,
3791        fn_hir_id: HirId,
3792        arg_idx: Option<usize>,
3793    ) -> Option<Ty<'tcx>> {
3794        let tcx = self.tcx();
3795        let hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), ident, .. }) =
3796            tcx.hir_node(fn_hir_id)
3797        else {
3798            return None;
3799        };
3800        let i = tcx.parent_hir_node(fn_hir_id).expect_item().expect_impl();
3801
3802        let trait_ref = self.lower_impl_trait_ref(&i.of_trait?.trait_ref, self.lower_ty(i.self_ty));
3803
3804        let assoc = tcx.associated_items(trait_ref.def_id).find_by_ident_and_kind(
3805            tcx,
3806            *ident,
3807            ty::AssocTag::Fn,
3808            trait_ref.def_id,
3809        )?;
3810
3811        let fn_sig = tcx
3812            .fn_sig(assoc.def_id)
3813            .instantiate(
3814                tcx,
3815                trait_ref
3816                    .args
3817                    .extend_to(tcx, assoc.def_id, |param, _| tcx.mk_param_from_def(param)),
3818            )
3819            .skip_norm_wip();
3820        let fn_sig = tcx.liberate_late_bound_regions(fn_hir_id.expect_owner().to_def_id(), fn_sig);
3821
3822        Some(if let Some(arg_idx) = arg_idx {
3823            *fn_sig.inputs().get(arg_idx)?
3824        } else {
3825            fn_sig.output()
3826        })
3827    }
3828
3829    {}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::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("validate_late_bound_regions",
                                    "rustc_hir_analysis::hir_ty_lowering",
                                    ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(3829u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("constrained_regions")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("constrained_regions");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("referenced_regions")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("referenced_regions");
                                                        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::TRACE <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::TRACE <=
                                    ::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(&constrained_regions)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&referenced_regions)
                                                            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;
        }
        {
            for br in referenced_regions.difference(&constrained_regions) {
                let br_name =
                    if let Some(name) = br.get_name(self.tcx()) {
                        ::alloc::__export::must_use({
                                ::alloc::fmt::format(format_args!("lifetime `{0}`", name))
                            })
                    } else { "an anonymous lifetime".to_string() };
                let mut err = generate_err(&br_name);
                if !br.is_named(self.tcx()) {
                    err.note("lifetimes appearing in an associated or opaque type are not considered constrained");
                    err.note("consider introducing a named lifetime parameter");
                }
                err.emit();
            }
        }
    }
}#[instrument(level = "trace", skip(self, generate_err))]
3830    fn validate_late_bound_regions<'cx>(
3831        &'cx self,
3832        constrained_regions: FxIndexSet<ty::BoundRegionKind<'tcx>>,
3833        referenced_regions: FxIndexSet<ty::BoundRegionKind<'tcx>>,
3834        generate_err: impl Fn(&str) -> Diag<'cx>,
3835    ) {
3836        for br in referenced_regions.difference(&constrained_regions) {
3837            let br_name = if let Some(name) = br.get_name(self.tcx()) {
3838                format!("lifetime `{name}`")
3839            } else {
3840                "an anonymous lifetime".to_string()
3841            };
3842
3843            let mut err = generate_err(&br_name);
3844
3845            if !br.is_named(self.tcx()) {
3846                // The only way for an anonymous lifetime to wind up
3847                // in the return type but **also** be unconstrained is
3848                // if it only appears in "associated types" in the
3849                // input. See #47511 and #62200 for examples. In this case,
3850                // though we can easily give a hint that ought to be
3851                // relevant.
3852                err.note(
3853                    "lifetimes appearing in an associated or opaque type are not considered constrained",
3854                );
3855                err.note("consider introducing a named lifetime parameter");
3856            }
3857
3858            err.emit();
3859        }
3860    }
3861
3862    fn construct_const_ctor_value(
3863        &self,
3864        ctor_def_id: DefId,
3865        ctor_of: CtorOf,
3866        args: ty::GenericArgs<'tcx>,
3867    ) -> Const<'tcx> {
3868        let tcx = self.tcx();
3869        let parent_did = tcx.parent(ctor_def_id);
3870
3871        let adt_def = tcx.adt_def(match ctor_of {
3872            CtorOf::Variant => tcx.parent(parent_did),
3873            CtorOf::Struct => parent_did,
3874        });
3875
3876        let variant_idx = adt_def.variant_index_with_id(parent_did);
3877
3878        let valtree = if adt_def.is_enum() {
3879            let discr = ty::ValTree::from_scalar_int(tcx, variant_idx.as_u32().into());
3880            ty::ValTree::from_branches(tcx, [ty::Const::new_value(tcx, discr, tcx.types.u32)])
3881        } else {
3882            ty::ValTree::zst(tcx)
3883        };
3884
3885        let adt_ty = Ty::new_adt(tcx, adt_def, args);
3886        ty::Const::new_value(tcx, valtree, adt_ty)
3887    }
3888
3889    fn lower_view(&self, inner_ty: Ty<'tcx>, fields: &[Ident], ty_span: Span) -> Ty<'tcx> {
3890        // Step 1: check that every field is unique, and keep a list of field that we know are
3891        // unique.
3892        let mut viewed_fields = Vec::<Ident>::with_capacity(fields.len());
3893
3894        for f in fields {
3895            let f = f.normalize_to_macros_2_0();
3896            // PERF: this is quadratic, but ~fine since the amount of fields is very low.
3897            if let Some(previous_field_span) =
3898                viewed_fields.iter().find_map(|f_| (*f_ == f).then_some(f_.span))
3899            {
3900                self.dcx().emit_err(diagnostics::ViewedFieldIsAlreadyPartOfTheView {
3901                    name: f.name,
3902                    span: f.span,
3903                    previous_field_span,
3904                });
3905                continue;
3906            }
3907            viewed_fields.push(f);
3908        }
3909
3910        // Step 2: check that the viewed type is a struct.
3911        let variant = match inner_ty.kind() {
3912            ty::Adt(def, _) if def.is_struct() => def.non_enum_variant(),
3913
3914            ty::Adt(def, _) => {
3915                let guar = self.dcx().emit_err(diagnostics::OnlyStructsCanBeViewedAdt {
3916                    ty: inner_ty,
3917                    span: ty_span,
3918                    article: def.article(),
3919                    kind: def.descr(),
3920                });
3921                return Ty::new_error(self.tcx(), guar);
3922            }
3923
3924            _ => {
3925                let guar = self.dcx().emit_err(diagnostics::OnlyStructsCanBeViewedNonAdt {
3926                    ty: inner_ty,
3927                    span: ty_span,
3928                });
3929                return Ty::new_error(self.tcx(), guar);
3930            }
3931        };
3932
3933        // Step 3: check that every viewed field exists.
3934        let mut viewed_indices = Vec::with_capacity(viewed_fields.len());
3935        let mut error = None;
3936        for field in viewed_fields {
3937            let Some((_, field)) = variant
3938                .fields
3939                .iter_enumerated()
3940                .find(|(_, f)| f.ident(self.tcx()).normalize_to_macros_2_0() == field)
3941            else {
3942                let err =
3943                    self.dcx().emit_err(NoFieldOnType { span: field.span, field, ty: inner_ty });
3944                error = Some(err);
3945                continue;
3946            };
3947
3948            viewed_indices.push(field);
3949        }
3950        if let Some(guar) = error {
3951            return Ty::new_error(self.tcx(), guar);
3952        }
3953
3954        // FIXME(scrabsha): actually lower view types.
3955        inner_ty
3956    }
3957}