Skip to main content

rustc_trait_selection/traits/
normalize.rs

1//! Deeply normalize types using the old trait solver.
2
3use rustc_errors::msg;
4use rustc_infer::infer::at::At;
5use rustc_infer::infer::{InferCtxt, InferOk};
6use rustc_infer::traits::{
7    FromSolverError, Normalized, Obligation, PredicateObligations, TraitEngine, TraitErrors,
8};
9use rustc_macros::extension;
10use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
11use rustc_middle::ty::{
12    self, AliasTerm, PredicateProxy, Term, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable,
13    TypeVisitable, TypeVisitableExt, TypingMode, Unnormalized,
14};
15use rustc_span::span_bug;
16use thin_vec::ThinVec;
17use tracing::{debug, instrument};
18
19use super::{BoundVarReplacer, PlaceholderReplacer, SelectionContext, project};
20use crate::error_reporting::InferCtxtErrorExt;
21use crate::error_reporting::traits::OverflowCause;
22use crate::solve::NextSolverError;
23
24pub trait NormalizeExt<'tcx> {
    #[doc = " Normalize a value using the `AssocTypeNormalizer`."]
    #[doc = ""]
    #[doc =
    " This normalization should be used when the type contains inference variables or the"]
    #[doc = " projection may be fallible."]
    fn normalize<T: TypeFoldable<TyCtxt<'tcx>>>(&self,
    value: Unnormalized<'tcx, T>)
    -> InferOk<'tcx, T>;
    #[doc =
    " Deeply normalizes `value`, replacing all aliases which can by normalized in"]
    #[doc =
    " the current environment. In the new solver this errors in case normalization"]
    #[doc = " fails or is ambiguous."]
    #[doc = ""]
    #[doc =
    " In the old solver this simply uses `normalizes` and adds the nested obligations"]
    #[doc =
    " to the `fulfill_cx`. This is necessary as we otherwise end up recomputing the"]
    #[doc =
    " same goals in both a temporary and the shared context which negatively impacts"]
    #[doc = " performance as these don\'t share caching."]
    #[doc = ""]
    #[doc =
    " FIXME(-Znext-solver=no): For performance reasons, we currently reuse an existing"]
    #[doc =
    " fulfillment context in the old solver. Once we have removed the old solver, we"]
    #[doc = " can remove the `fulfill_cx` parameter on this function."]
    fn deeply_normalize<T,
    E>(self, value: Unnormalized<'tcx, T>,
    fulfill_cx: &mut dyn TraitEngine<'tcx, E>)
    -> Result<T, ThinVec<E>>
    where
    T: TypeFoldable<TyCtxt<'tcx>>,
    E: FromSolverError<'tcx, NextSolverError<'tcx>>;
}
impl<'tcx> NormalizeExt<'tcx> for At<'_, 'tcx> {
    #[doc = " Normalize a value using the `AssocTypeNormalizer`."]
    #[doc = ""]
    #[doc =
    " This normalization should be used when the type contains inference variables or the"]
    #[doc = " projection may be fallible."]
    fn normalize<T: TypeFoldable<TyCtxt<'tcx>>>(&self,
        value: Unnormalized<'tcx, T>) -> InferOk<'tcx, T> {
        if self.infcx.next_trait_solver() {
            let Normalized { value, obligations } =
                crate::solve::normalize(*self, value);
            InferOk { value, obligations }
        } else {
            let mut selcx = SelectionContext::new(self.infcx);
            let Normalized { value, obligations } =
                normalize_with_depth(&mut selcx, self.param_env,
                    self.cause.clone(), 0, value);
            InferOk { value, obligations }
        }
    }
    #[doc =
    " Deeply normalizes `value`, replacing all aliases which can by normalized in"]
    #[doc =
    " the current environment. In the new solver this errors in case normalization"]
    #[doc = " fails or is ambiguous."]
    #[doc = ""]
    #[doc =
    " In the old solver this simply uses `normalizes` and adds the nested obligations"]
    #[doc =
    " to the `fulfill_cx`. This is necessary as we otherwise end up recomputing the"]
    #[doc =
    " same goals in both a temporary and the shared context which negatively impacts"]
    #[doc = " performance as these don\'t share caching."]
    #[doc = ""]
    #[doc =
    " FIXME(-Znext-solver=no): For performance reasons, we currently reuse an existing"]
    #[doc =
    " fulfillment context in the old solver. Once we have removed the old solver, we"]
    #[doc = " can remove the `fulfill_cx` parameter on this function."]
    fn deeply_normalize<T,
        E>(self, value: Unnormalized<'tcx, T>,
        fulfill_cx: &mut dyn TraitEngine<'tcx, E>) -> Result<T, ThinVec<E>>
        where T: TypeFoldable<TyCtxt<'tcx>>,
        E: FromSolverError<'tcx, NextSolverError<'tcx>> {
        if self.infcx.next_trait_solver() {
            crate::solve::deeply_normalize(self, value)
        } else {
            if fulfill_cx.has_pending_obligations() {
                let pending_obligations = fulfill_cx.pending_obligations();
                ::rustc_span::macros::bug_impl(Some(pending_obligations[0].cause.span),
                    format_args!("deeply_normalize should not be called with pending obligations: {0:#?}",
                        pending_obligations), Location::caller());
            }
            let value =
                self.normalize(value).into_value_registering_obligations(self.infcx,
                    &mut *fulfill_cx);
            let errors =
                fulfill_cx.evaluate_obligations_error_on_ambiguity(self.infcx);
            let value = self.infcx.deeply_resolve_ignoring_regions(value);
            match errors {
                TraitErrors::NoErrors => Ok(value),
                TraitErrors::HasErrors(errors) => {
                    let _ = fulfill_cx.collect_remaining_errors(self.infcx);
                    Err(errors)
                }
            }
        }
    }
}#[extension(pub trait NormalizeExt<'tcx>)]
25impl<'tcx> At<'_, 'tcx> {
26    /// Normalize a value using the `AssocTypeNormalizer`.
27    ///
28    /// This normalization should be used when the type contains inference variables or the
29    /// projection may be fallible.
30    fn normalize<T: TypeFoldable<TyCtxt<'tcx>>>(
31        &self,
32        value: Unnormalized<'tcx, T>,
33    ) -> InferOk<'tcx, T> {
34        if self.infcx.next_trait_solver() {
35            let Normalized { value, obligations } = crate::solve::normalize(*self, value);
36            InferOk { value, obligations }
37        } else {
38            let mut selcx = SelectionContext::new(self.infcx);
39            let Normalized { value, obligations } =
40                normalize_with_depth(&mut selcx, self.param_env, self.cause.clone(), 0, value);
41            InferOk { value, obligations }
42        }
43    }
44
45    /// Deeply normalizes `value`, replacing all aliases which can by normalized in
46    /// the current environment. In the new solver this errors in case normalization
47    /// fails or is ambiguous.
48    ///
49    /// In the old solver this simply uses `normalizes` and adds the nested obligations
50    /// to the `fulfill_cx`. This is necessary as we otherwise end up recomputing the
51    /// same goals in both a temporary and the shared context which negatively impacts
52    /// performance as these don't share caching.
53    ///
54    /// FIXME(-Znext-solver=no): For performance reasons, we currently reuse an existing
55    /// fulfillment context in the old solver. Once we have removed the old solver, we
56    /// can remove the `fulfill_cx` parameter on this function.
57    fn deeply_normalize<T, E>(
58        self,
59        value: Unnormalized<'tcx, T>,
60        fulfill_cx: &mut dyn TraitEngine<'tcx, E>,
61    ) -> Result<T, ThinVec<E>>
62    where
63        T: TypeFoldable<TyCtxt<'tcx>>,
64        E: FromSolverError<'tcx, NextSolverError<'tcx>>,
65    {
66        if self.infcx.next_trait_solver() {
67            crate::solve::deeply_normalize(self, value)
68        } else {
69            if fulfill_cx.has_pending_obligations() {
70                let pending_obligations = fulfill_cx.pending_obligations();
71                span_bug!(
72                    pending_obligations[0].cause.span,
73                    "deeply_normalize should not be called with pending obligations: \
74                    {pending_obligations:#?}"
75                );
76            }
77            let value = self
78                .normalize(value)
79                .into_value_registering_obligations(self.infcx, &mut *fulfill_cx);
80            let errors = fulfill_cx.evaluate_obligations_error_on_ambiguity(self.infcx);
81            let value = self.infcx.deeply_resolve_ignoring_regions(value);
82            match errors {
83                TraitErrors::NoErrors => Ok(value),
84                TraitErrors::HasErrors(errors) => {
85                    // Drop pending obligations, since deep normalization may happen
86                    // in a loop and we don't want to trigger the assertion on the next
87                    // iteration due to pending ambiguous obligations we've left over.
88                    let _ = fulfill_cx.collect_remaining_errors(self.infcx);
89                    Err(errors)
90                }
91            }
92        }
93    }
94}
95
96/// As `normalize`, but with a custom depth.
97pub(crate) fn normalize_with_depth<'a, 'b, 'tcx, T>(
98    selcx: &'a mut SelectionContext<'b, 'tcx>,
99    param_env: ty::ParamEnv<'tcx>,
100    cause: ObligationCause<'tcx>,
101    depth: usize,
102    value: Unnormalized<'tcx, T>,
103) -> Normalized<'tcx, T>
104where
105    T: TypeFoldable<TyCtxt<'tcx>>,
106{
107    let mut obligations = PredicateObligations::new();
108    let value = normalize_with_depth_to(selcx, param_env, cause, depth, value, &mut obligations);
109    Normalized { value, obligations }
110}
111
112{}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::INFO <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
                ::tracing::Level::INFO <=
                    ::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("normalize_with_depth_to",
                                    "rustc_trait_selection::traits::normalize",
                                    ::tracing::Level::INFO,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_trait_selection/src/traits/normalize.rs"),
                                    ::tracing_core::__macro_support::Option::Some(112u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::normalize"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("depth")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("depth");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("value")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("value");
                                                        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::INFO <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::INFO <=
                                    ::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(&depth
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&value)
                                                            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: T = 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/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_trait_selection/src/traits/normalize.rs:124",
                                    "rustc_trait_selection::traits::normalize",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_trait_selection/src/traits/normalize.rs"),
                                    ::tracing_core::__macro_support::Option::Some(124u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::normalize"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("obligations.len")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("obligations.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(&obligations.len()
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            let mut normalizer =
                AssocTypeNormalizer::new(selcx, param_env, cause, depth,
                    obligations);
            let result =
                AssocTypeNormalizer::fold(&mut normalizer,
                    value.skip_normalization());
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_trait_selection/src/traits/normalize.rs:127",
                                    "rustc_trait_selection::traits::normalize",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_trait_selection/src/traits/normalize.rs"),
                                    ::tracing_core::__macro_support::Option::Some(127u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::normalize"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("result")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("result");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("obligations.len")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("obligations.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(&result)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&normalizer.obligations.len()
                                                        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/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_trait_selection/src/traits/normalize.rs:128",
                                    "rustc_trait_selection::traits::normalize",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_trait_selection/src/traits/normalize.rs"),
                                    ::tracing_core::__macro_support::Option::Some(128u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::normalize"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("normalizer.obligations")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("normalizer.obligations");
                                                        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(&normalizer.obligations)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            result
        }
    }
}#[instrument(level = "info", skip(selcx, param_env, cause, obligations))]
113pub(crate) fn normalize_with_depth_to<'a, 'b, 'tcx, T>(
114    selcx: &'a mut SelectionContext<'b, 'tcx>,
115    param_env: ty::ParamEnv<'tcx>,
116    cause: ObligationCause<'tcx>,
117    depth: usize,
118    value: Unnormalized<'tcx, T>,
119    obligations: &mut PredicateObligations<'tcx>,
120) -> T
121where
122    T: TypeFoldable<TyCtxt<'tcx>>,
123{
124    debug!(obligations.len = obligations.len());
125    let mut normalizer = AssocTypeNormalizer::new(selcx, param_env, cause, depth, obligations);
126    let result = AssocTypeNormalizer::fold(&mut normalizer, value.skip_normalization());
127    debug!(?result, obligations.len = normalizer.obligations.len());
128    debug!(?normalizer.obligations,);
129    result
130}
131
132pub(super) fn needs_normalization<'tcx, T: TypeVisitable<TyCtxt<'tcx>>>(
133    infcx: &InferCtxt<'tcx>,
134    value: &T,
135) -> bool {
136    let mut flags = ty::TypeFlags::HAS_ALIAS;
137
138    // Opaques are treated as rigid outside of `TypingMode::PostAnalysis`,
139    // so we can ignore those.
140    match infcx.typing_mode_raw().assert_not_erased() {
141        // FIXME(#132279): We likely want to reveal opaques during post borrowck analysis
142        TypingMode::Typeck { .. }
143        | TypingMode::PostTypeckUntilBorrowck { .. }
144        | TypingMode::PostBorrowck { .. } => flags.remove(ty::TypeFlags::HAS_TY_OPAQUE),
145        TypingMode::Reflection | TypingMode::PostAnalysis | TypingMode::Codegen => {}
146        TypingMode::Coherence => {
147            {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("old solver coherence")));
}unreachable!("old solver coherence")
148        }
149    }
150
151    value.has_type_flags(flags)
152}
153
154struct AssocTypeNormalizer<'a, 'b, 'tcx> {
155    selcx: &'a mut SelectionContext<'b, 'tcx>,
156    param_env: ty::ParamEnv<'tcx>,
157    cause: ObligationCause<'tcx>,
158    obligations: &'a mut PredicateObligations<'tcx>,
159    depth: usize,
160    universes: Vec<Option<ty::UniverseIndex>>,
161}
162
163impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
164    fn new(
165        selcx: &'a mut SelectionContext<'b, 'tcx>,
166        param_env: ty::ParamEnv<'tcx>,
167        cause: ObligationCause<'tcx>,
168        depth: usize,
169        obligations: &'a mut PredicateObligations<'tcx>,
170    ) -> AssocTypeNormalizer<'a, 'b, 'tcx> {
171        if true {
    if !!selcx.infcx.next_trait_solver() {
        ::core::panicking::panic("assertion failed: !selcx.infcx.next_trait_solver()")
    };
};debug_assert!(!selcx.infcx.next_trait_solver());
172        AssocTypeNormalizer { selcx, param_env, cause, obligations, depth, universes: ::alloc::vec::Vec::new()vec![] }
173    }
174
175    fn fold<T: TypeFoldable<TyCtxt<'tcx>>>(&mut self, value: T) -> T {
176        let value = self.selcx.infcx.deeply_resolve_ignoring_regions(value);
177        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_trait_selection/src/traits/normalize.rs:177",
                        "rustc_trait_selection::traits::normalize",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_trait_selection/src/traits/normalize.rs"),
                        ::tracing_core::__macro_support::Option::Some(177u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::normalize"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("value")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("value");
                                            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(&value)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?value);
178
179        if !!value.has_escaping_bound_vars() {
    {
        ::core::panicking::panic_fmt(format_args!("Normalizing {0:?} without wrapping in a `Binder`",
                value));
    }
};assert!(
180            !value.has_escaping_bound_vars(),
181            "Normalizing {value:?} without wrapping in a `Binder`"
182        );
183
184        if !needs_normalization(self.selcx.infcx, &value) { value } else { value.fold_with(self) }
185    }
186
187    // FIXME(mgca): While this supports constants, it is only used for types by default right now
188    {}
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("normalize_trait_projection",
                                "rustc_trait_selection::traits::normalize",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_trait_selection/src/traits/normalize.rs"),
                                ::tracing_core::__macro_support::Option::Some(188u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::normalize"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("proj")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("proj");
                                                    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(&proj)
                                                        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: Term<'tcx> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        if !proj.has_escaping_bound_vars() {
                            let proj = proj.fold_with(self);
                            project::normalize_projection_term(self.selcx,
                                self.param_env, proj, self.cause.clone(), self.depth,
                                self.obligations)
                        } else {
                            let infcx = self.selcx.infcx;
                            let (proj, mapped_regions, mapped_types, mapped_consts) =
                                BoundVarReplacer::replace_bound_vars(infcx,
                                    &mut self.universes, proj);
                            let proj = proj.fold_with(self);
                            let normalized_term =
                                project::opt_normalize_projection_term(self.selcx,
                                                self.param_env, proj, self.cause.clone(), self.depth,
                                                self.obligations).ok().flatten().unwrap_or_else(||
                                        proj.to_term(infcx.tcx, ty::IsRigid::No));
                            PlaceholderReplacer::replace_placeholders(infcx,
                                mapped_regions, mapped_types, mapped_consts,
                                &self.universes, normalized_term)
                        }
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_trait_selection/src/traits/normalize.rs:188",
                        "rustc_trait_selection::traits::normalize",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_trait_selection/src/traits/normalize.rs"),
                        ::tracing_core::__macro_support::Option::Some(188u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::normalize"),
                        ::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)]
189    fn normalize_trait_projection(&mut self, proj: AliasTerm<'tcx>) -> Term<'tcx> {
190        if !proj.has_escaping_bound_vars() {
191            // When we don't have escaping bound vars we can normalize ambig aliases
192            // to inference variables (done in `normalize_projection_ty`). This would
193            // be wrong if there were escaping bound vars as even if we instantiated
194            // the bound vars with placeholders, we wouldn't be able to map them back
195            // after normalization succeeded.
196            //
197            // Also, as an optimization: when we don't have escaping bound vars, we don't
198            // need to replace them with placeholders (see branch below).
199            let proj = proj.fold_with(self);
200            project::normalize_projection_term(
201                self.selcx,
202                self.param_env,
203                proj,
204                self.cause.clone(),
205                self.depth,
206                self.obligations,
207            )
208        } else {
209            // If there are escaping bound vars, we temporarily replace the
210            // bound vars with placeholders. Note though, that in the case
211            // that we still can't project for whatever reason (e.g. self
212            // type isn't known enough), we *can't* register an obligation
213            // and return an inference variable (since then that obligation
214            // would have bound vars and that's a can of worms). Instead,
215            // we just give up and fall back to pretending like we never tried!
216            //
217            // Note: this isn't necessarily the final approach here; we may
218            // want to figure out how to register obligations with escaping vars
219            // or handle this some other way.
220            let infcx = self.selcx.infcx;
221            let (proj, mapped_regions, mapped_types, mapped_consts) =
222                BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, proj);
223            let proj = proj.fold_with(self);
224            let normalized_term = project::opt_normalize_projection_term(
225                self.selcx,
226                self.param_env,
227                proj,
228                self.cause.clone(),
229                self.depth,
230                self.obligations,
231            )
232            .ok()
233            .flatten()
234            .unwrap_or_else(|| proj.to_term(infcx.tcx, ty::IsRigid::No));
235
236            PlaceholderReplacer::replace_placeholders(
237                infcx,
238                mapped_regions,
239                mapped_types,
240                mapped_consts,
241                &self.universes,
242                normalized_term,
243            )
244        }
245    }
246
247    // FIXME(mgca): While this supports constants, it is only used for types by default right now
248    {}
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("normalize_inherent_projection",
                                "rustc_trait_selection::traits::normalize",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_trait_selection/src/traits/normalize.rs"),
                                ::tracing_core::__macro_support::Option::Some(248u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::normalize"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("inherent")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("inherent");
                                                    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(&inherent)
                                                        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: Term<'tcx> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        if !inherent.has_escaping_bound_vars() {
                            let inherent = inherent.fold_with(self);
                            project::normalize_inherent_projection(self.selcx,
                                self.param_env, inherent, self.cause.clone(), self.depth,
                                self.obligations)
                        } else {
                            let infcx = self.selcx.infcx;
                            let (inherent, mapped_regions, mapped_types,
                                    mapped_consts) =
                                BoundVarReplacer::replace_bound_vars(infcx,
                                    &mut self.universes, inherent);
                            let inherent = inherent.fold_with(self);
                            let inherent =
                                project::normalize_inherent_projection(self.selcx,
                                    self.param_env, inherent, self.cause.clone(), self.depth,
                                    self.obligations);
                            PlaceholderReplacer::replace_placeholders(infcx,
                                mapped_regions, mapped_types, mapped_consts,
                                &self.universes, inherent)
                        }
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_trait_selection/src/traits/normalize.rs:248",
                        "rustc_trait_selection::traits::normalize",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_trait_selection/src/traits/normalize.rs"),
                        ::tracing_core::__macro_support::Option::Some(248u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::normalize"),
                        ::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)]
249    fn normalize_inherent_projection(&mut self, inherent: AliasTerm<'tcx>) -> Term<'tcx> {
250        if !inherent.has_escaping_bound_vars() {
251            // When we don't have escaping bound vars we can normalize ambig aliases
252            // to inference variables (done in `normalize_projection_ty`). This would
253            // be wrong if there were escaping bound vars as even if we instantiated
254            // the bound vars with placeholders, we wouldn't be able to map them back
255            // after normalization succeeded.
256            //
257            // Also, as an optimization: when we don't have escaping bound vars, we don't
258            // need to replace them with placeholders (see branch below).
259
260            let inherent = inherent.fold_with(self);
261            project::normalize_inherent_projection(
262                self.selcx,
263                self.param_env,
264                inherent,
265                self.cause.clone(),
266                self.depth,
267                self.obligations,
268            )
269        } else {
270            let infcx = self.selcx.infcx;
271            let (inherent, mapped_regions, mapped_types, mapped_consts) =
272                BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, inherent);
273            let inherent = inherent.fold_with(self);
274            let inherent = project::normalize_inherent_projection(
275                self.selcx,
276                self.param_env,
277                inherent,
278                self.cause.clone(),
279                self.depth,
280                self.obligations,
281            );
282
283            PlaceholderReplacer::replace_placeholders(
284                infcx,
285                mapped_regions,
286                mapped_types,
287                mapped_consts,
288                &self.universes,
289                inherent,
290            )
291        }
292    }
293
294    // FIXME(mgca): While this supports constants, it is only used for types by default right now
295    {}
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("normalize_free_alias",
                                "rustc_trait_selection::traits::normalize",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_trait_selection/src/traits/normalize.rs"),
                                ::tracing_core::__macro_support::Option::Some(295u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::normalize"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("free")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("free");
                                                    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(&free)
                                                        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: Term<'tcx> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        let recursion_limit = self.cx().recursion_limit();
                        if !recursion_limit.value_within_limit(self.depth) {
                            self.selcx.infcx.err_ctxt().report_overflow_error(OverflowCause::DeeplyNormalize(free),
                                self.cause.span, false,
                                |diag|
                                    {
                                        diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("in case this is a recursive type alias, consider using a struct, enum, or union instead")));
                                    });
                        }
                        let def_id = free.expect_free_def_id();
                        let infcx = self.selcx.infcx;
                        self.obligations.extend(infcx.tcx.clauses_of(def_id).instantiate_own(infcx.tcx,
                                        free.args).map(|(clause, span)|
                                        (clause.skip_norm_wip(),
                                            span)).map(|(mut clause, span)|
                                    {
                                        if free.has_escaping_bound_vars() {
                                            (clause, ..) =
                                                BoundVarReplacer::replace_bound_vars(infcx,
                                                    &mut self.universes, clause);
                                        }
                                        let mut cause = self.cause.clone();
                                        cause.map_code(|code|
                                                ObligationCauseCode::TypeAlias(code, span, def_id));
                                        Obligation::new(infcx.tcx, cause, self.param_env, clause)
                                    }));
                        self.depth += 1;
                        let res: ty::Term<'tcx> =
                            if free.kind.is_type() {
                                infcx.tcx.type_of(def_id).instantiate(infcx.tcx,
                                                free.args).skip_norm_wip().fold_with(self).into()
                            } else {
                                project::const_of_item_or_delayed_bug(infcx.tcx,
                                                    def_id).instantiate(infcx.tcx,
                                                free.args).skip_norm_wip().fold_with(self).into()
                            };
                        if let Some(ct) = res.as_const() {
                            let expected_ty =
                                infcx.tcx.type_of(def_id).instantiate(infcx.tcx,
                                        free.args).skip_norm_wip();
                            self.obligations.push(Obligation::with_depth(infcx.tcx,
                                    self.cause.clone(), self.depth, self.param_env,
                                    ty::ClauseKind::ConstArgHasType(ct, expected_ty)));
                        }
                        self.depth -= 1;
                        res
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_trait_selection/src/traits/normalize.rs:295",
                        "rustc_trait_selection::traits::normalize",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_trait_selection/src/traits/normalize.rs"),
                        ::tracing_core::__macro_support::Option::Some(295u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::normalize"),
                        ::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)]
296    fn normalize_free_alias(&mut self, free: AliasTerm<'tcx>) -> Term<'tcx> {
297        let recursion_limit = self.cx().recursion_limit();
298        if !recursion_limit.value_within_limit(self.depth) {
299            self.selcx.infcx.err_ctxt().report_overflow_error(
300                OverflowCause::DeeplyNormalize(free),
301                self.cause.span,
302                false,
303                |diag| {
304                    diag.note(msg!("in case this is a recursive type alias, consider using a struct, enum, or union instead"));
305                },
306            );
307        }
308
309        let def_id = free.expect_free_def_id();
310
311        // We don't replace bound vars in the generic arguments of the free alias with
312        // placeholders. This doesn't cause any issues as instantiating parameters with
313        // bound variables is special-cased to rewrite the debruijn index to be higher
314        // whenever we fold through a binder.
315        //
316        // However, we do replace any escaping bound vars in the resulting goals with
317        // placeholders as the trait solver does not expect to encounter escaping bound
318        // vars in obligations.
319        //
320        // FIXME(checked_type_alias): Check how much this actually matters for perf before
321        // stabilization. This is a bit weird and generally not how we handle binders in
322        // the compiler so ideally we'd do the same boundvar->placeholder->boundvar dance
323        // that other kinds of normalization do.
324        let infcx = self.selcx.infcx;
325        self.obligations.extend(
326            infcx
327                .tcx
328                .clauses_of(def_id)
329                .instantiate_own(infcx.tcx, free.args)
330                .map(|(clause, span)| (clause.skip_norm_wip(), span))
331                .map(|(mut clause, span)| {
332                    if free.has_escaping_bound_vars() {
333                        (clause, ..) = BoundVarReplacer::replace_bound_vars(
334                            infcx,
335                            &mut self.universes,
336                            clause,
337                        );
338                    }
339                    let mut cause = self.cause.clone();
340                    cause.map_code(|code| ObligationCauseCode::TypeAlias(code, span, def_id));
341                    Obligation::new(infcx.tcx, cause, self.param_env, clause)
342                }),
343        );
344        self.depth += 1;
345        let res: ty::Term<'tcx> = if free.kind.is_type() {
346            infcx
347                .tcx
348                .type_of(def_id)
349                .instantiate(infcx.tcx, free.args)
350                .skip_norm_wip()
351                .fold_with(self)
352                .into()
353        } else {
354            project::const_of_item_or_delayed_bug(infcx.tcx, def_id)
355                .instantiate(infcx.tcx, free.args)
356                .skip_norm_wip()
357                .fold_with(self)
358                .into()
359        };
360        // When normalizing a free const alias, register a `ConstArgHasType`
361        // obligation to ensure the const value's type matches the declared type.
362        if let Some(ct) = res.as_const() {
363            let expected_ty =
364                infcx.tcx.type_of(def_id).instantiate(infcx.tcx, free.args).skip_norm_wip();
365            self.obligations.push(Obligation::with_depth(
366                infcx.tcx,
367                self.cause.clone(),
368                self.depth,
369                self.param_env,
370                ty::ClauseKind::ConstArgHasType(ct, expected_ty),
371            ));
372        }
373        self.depth -= 1;
374        res
375    }
376}
377
378impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx> {
379    fn cx(&self) -> TyCtxt<'tcx> {
380        self.selcx.tcx()
381    }
382
383    fn fold_binder<T: TypeFoldable<TyCtxt<'tcx>>>(
384        &mut self,
385        t: ty::Binder<'tcx, T>,
386    ) -> ty::Binder<'tcx, T> {
387        self.universes.push(None);
388        let t = t.super_fold_with(self);
389        self.universes.pop();
390        t
391    }
392
393    fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
394        // We don't use the rigid marker in old solver.
395        if true {
    if !!ty.has_rigid_aliases() {
        ::core::panicking::panic("assertion failed: !ty.has_rigid_aliases()")
    };
};debug_assert!(!ty.has_rigid_aliases());
396
397        if !needs_normalization(self.selcx.infcx, &ty) {
398            return ty;
399        }
400
401        let ty::Alias(_, data) = *ty.kind() else { return ty.super_fold_with(self) };
402
403        // We try to be a little clever here as a performance optimization in
404        // cases where there are nested projections under binders.
405        // For example:
406        // ```
407        // for<'a> fn(<T as Foo>::One<'a, Box<dyn Bar<'a, Item=<T as Foo>::Two<'a>>>>)
408        // ```
409        // We normalize the args on the projection before the projecting, but
410        // if we're naive, we'll
411        //   replace bound vars on inner, project inner, replace placeholders on inner,
412        //   replace bound vars on outer, project outer, replace placeholders on outer
413        //
414        // However, if we're a bit more clever, we can replace the bound vars
415        // on the entire type before normalizing nested projections, meaning we
416        //   replace bound vars on outer, project inner,
417        //   project outer, replace placeholders on outer
418        //
419        // This is possible because the inner `'a` will already be a placeholder
420        // when we need to normalize the inner projection
421        //
422        // On the other hand, this does add a bit of complexity, since we only
423        // replace bound vars if the current type is a `Projection` and we need
424        // to make sure we don't forget to fold the args regardless.
425
426        match data.kind {
427            ty::Opaque { def_id } => {
428                // Only normalize `impl Trait` outside of type inference, usually in codegen.
429                match self.selcx.typing_mode() {
430                    // FIXME(#132279): We likely want to reveal opaques during post borrowck analysis
431                    TypingMode::Typeck { .. }
432                    | TypingMode::PostTypeckUntilBorrowck { .. }
433                    | TypingMode::PostBorrowck { .. } => ty.super_fold_with(self),
434                    TypingMode::Reflection | TypingMode::PostAnalysis | TypingMode::Codegen => {
435                        let recursion_limit = self.cx().recursion_limit();
436                        if !recursion_limit.value_within_limit(self.depth) {
437                            self.selcx.infcx.err_ctxt().report_overflow_error(
438                                OverflowCause::DeeplyNormalize(data.into()),
439                                self.cause.span,
440                                true,
441                                |_| {},
442                            );
443                        }
444
445                        let args = data.args.fold_with(self);
446                        let generic_ty = self.cx().type_of(def_id);
447                        let concrete_ty = generic_ty.instantiate(self.cx(), args).skip_norm_wip();
448                        self.depth += 1;
449                        let folded_ty = self.fold_ty(concrete_ty);
450                        self.depth -= 1;
451                        folded_ty
452                    }
453                    TypingMode::Coherence => {
454                        {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("old solver coherence")));
}unreachable!("old solver coherence")
455                    }
456                }
457            }
458
459            ty::Projection { .. } => self.normalize_trait_projection(data.into()).expect_type(),
460            ty::Inherent { .. } => self.normalize_inherent_projection(data.into()).expect_type(),
461            ty::Free { .. } => self.normalize_free_alias(data.into()).expect_type(),
462        }
463    }
464
465    {}
#[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("fold_const",
                                    "rustc_trait_selection::traits::normalize",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/b6eeb93c992027a03e1fd120b6652546396b142c/compiler/rustc_trait_selection/src/traits/normalize.rs"),
                                    ::tracing_core::__macro_support::Option::Some(465u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_trait_selection::traits::normalize"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("ct")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("ct");
                                                        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(&ct)
                                                            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::Const<'tcx> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            if true {
                if !!ct.has_rigid_aliases() {
                    ::core::panicking::panic("assertion failed: !ct.has_rigid_aliases()")
                };
            };
            let tcx = self.selcx.tcx();
            if tcx.features().generic_const_exprs() &&
                        !#[allow(non_exhaustive_omitted_patterns)] match ct.kind() {
                                ty::ConstKind::Alias(_, alias_const) if
                                    alias_const.kind.is_direct_const(tcx) => true,
                                _ => false,
                            } || !needs_normalization(self.selcx.infcx, &ct) {
                return ct;
            }
            let alias_const =
                match ct.kind() {
                    ty::ConstKind::Alias(_, alias_const) => alias_const,
                    _ => return ct.super_fold_with(self),
                };
            let ct =
                match alias_const.kind {
                    ty::AliasConstKind::Projection { .. } => {
                        self.normalize_trait_projection(alias_const.into()).expect_const()
                    }
                    ty::AliasConstKind::InherentSelf { .. } |
                        ty::AliasConstKind::InherentImpl { .. } => {
                        self.normalize_inherent_projection(alias_const.into()).expect_const()
                    }
                    ty::AliasConstKind::Free { .. } => {
                        self.normalize_free_alias(alias_const.into()).expect_const()
                    }
                    ty::AliasConstKind::Anon { .. } => {
                        let ct = ct.super_fold_with(self);
                        super::with_replaced_escaping_bound_vars(self.selcx.infcx,
                            &mut self.universes, ct,
                            |ct|
                                super::evaluate_const(self.selcx.infcx, ct, self.param_env))
                    }
                };
            ct.super_fold_with(self)
        }
    }
}#[instrument(skip(self), level = "debug")]
466    fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
467        // We don't use the rigid marker in old solver.
468        debug_assert!(!ct.has_rigid_aliases());
469
470        let tcx = self.selcx.tcx();
471
472        if tcx.features().generic_const_exprs()
473            // Normalize type_const items even with feature `generic_const_exprs`.
474            && !matches!(ct.kind(), ty::ConstKind::Alias(_, alias_const) if alias_const.kind.is_direct_const(tcx))
475            || !needs_normalization(self.selcx.infcx, &ct)
476        {
477            return ct;
478        }
479
480        let alias_const = match ct.kind() {
481            ty::ConstKind::Alias(_, alias_const) => alias_const,
482            _ => return ct.super_fold_with(self),
483        };
484
485        // Note that the Projection/Inherent/Free cases are unreachable on stable,
486        // unless a `gca_min_const_items` feature gate error has already
487        // been emitted earlier in compilation.
488        //
489        // That's because we can only end up with an Alias ty::Const for a const item
490        // if it was marked with `type const`. Using this attribute without the mgca
491        // feature gate causes a parse error.
492        let ct = match alias_const.kind {
493            ty::AliasConstKind::Projection { .. } => {
494                self.normalize_trait_projection(alias_const.into()).expect_const()
495            }
496            ty::AliasConstKind::InherentSelf { .. } | ty::AliasConstKind::InherentImpl { .. } => {
497                self.normalize_inherent_projection(alias_const.into()).expect_const()
498            }
499            ty::AliasConstKind::Free { .. } => {
500                self.normalize_free_alias(alias_const.into()).expect_const()
501            }
502            ty::AliasConstKind::Anon { .. } => {
503                let ct = ct.super_fold_with(self);
504                super::with_replaced_escaping_bound_vars(
505                    self.selcx.infcx,
506                    &mut self.universes,
507                    ct,
508                    |ct| super::evaluate_const(self.selcx.infcx, ct, self.param_env),
509                )
510            }
511        };
512
513        // We re-fold the normalized const as the `ty` field on `ConstKind::Value` may be
514        // unnormalized after const evaluation returns.
515        ct.super_fold_with(self)
516    }
517
518    #[inline]
519    fn fold_predicate<P: PredicateProxy<TyCtxt<'tcx>>>(&mut self, p: P) -> P {
520        if p.allow_normalization() && needs_normalization(self.selcx.infcx, &p) {
521            p.super_fold_with(self)
522        } else {
523            p
524        }
525    }
526}