Skip to main content

rustc_middle/ty/
normalize_erasing_regions.rs

1//! Methods for normalizing when you don't care about regions (and
2//! aren't doing type inference). If either of those things don't
3//! apply to you, use `infcx.normalize(...)`.
4//!
5//! The methods in this file use a `TypeFolder` to recursively process
6//! contents, invoking the underlying
7//! `normalize_generic_arg_after_erasing_regions` query for each type
8//! or constant found within. (This underlying query is what is cached.)
9
10use rustc_macros::{StableHash, TyDecodable, TyEncodable};
11use tracing::{debug, instrument};
12
13use crate::traits::query::NoSolution;
14use crate::ty::{
15    self, EarlyBinder, FallibleTypeFolder, GenericArgsRef, Ty, TyCtxt, TypeFoldable, TypeFolder,
16    TypeVisitableExt, Unnormalized,
17};
18
19#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for NormalizationError<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            NormalizationError::Type(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Type",
                    &__self_0),
            NormalizationError::Const(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Const",
                    &__self_0),
        }
    }
}Debug, #[automatically_derived]
impl<'tcx> ::core::marker::Copy for NormalizationError<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for NormalizationError<'tcx> {
    #[inline]
    fn clone(&self) -> NormalizationError<'tcx> {
        let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
        let _: ::core::clone::AssertParamIsClone<ty::Const<'tcx>>;
        *self
    }
}Clone, const _: () =
    {
        impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
            NormalizationError<'tcx> {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                ::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
                match *self {
                    NormalizationError::Type(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    NormalizationError::Const(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash, const _: () =
    {
        impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
            ::rustc_serialize::Encodable<__E> for NormalizationError<'tcx> {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        NormalizationError::Type(ref __binding_0) => { 0usize }
                        NormalizationError::Const(ref __binding_0) => { 1usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    NormalizationError::Type(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    NormalizationError::Const(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };TyEncodable, const _: () =
    {
        impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
            ::rustc_serialize::Decodable<__D> for NormalizationError<'tcx> {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => {
                        NormalizationError::Type(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    1usize => {
                        NormalizationError::Const(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `NormalizationError`, expected 0..2, actual {0}",
                                n));
                    }
                }
            }
        }
    };TyDecodable)]
20pub enum NormalizationError<'tcx> {
21    Type(Ty<'tcx>),
22    Const(ty::Const<'tcx>),
23}
24
25impl<'tcx> NormalizationError<'tcx> {
26    pub fn get_type_for_failure(&self) -> String {
27        match self {
28            NormalizationError::Type(t) => ::alloc::__export::must_use({ ::alloc::fmt::format(format_args!("{0}", t)) })format!("{t}"),
29            NormalizationError::Const(c) => ::alloc::__export::must_use({ ::alloc::fmt::format(format_args!("{0}", c)) })format!("{c}"),
30        }
31    }
32}
33
34impl<'tcx> TyCtxt<'tcx> {
35    /// Erase the regions in `value` and then fully normalize all the
36    /// types found within. The result will also have regions erased.
37    ///
38    /// This should only be used outside of type inference. For example,
39    /// it assumes that normalization will succeed.
40    x;#[tracing::instrument(level = "debug", skip(self, typing_env), ret)]
41    pub fn normalize_erasing_regions<T>(
42        self,
43        typing_env: ty::TypingEnv<'tcx>,
44        value: Unnormalized<'tcx, T>,
45    ) -> T
46    where
47        T: TypeFoldable<TyCtxt<'tcx>>,
48    {
49        let value = value.skip_normalization();
50        debug!(
51            "normalize_erasing_regions::<{}>(value={:?}, typing_env={:?})",
52            std::any::type_name::<T>(),
53            value,
54            typing_env,
55        );
56
57        // Erase first before we do the real query -- this keeps the
58        // cache from being too polluted.
59        let value = self.erase_and_anonymize_regions(value);
60        debug!(?value);
61
62        if !value.has_aliases() {
63            value
64        } else {
65            value.fold_with(&mut NormalizeAfterErasingRegionsFolder { tcx: self, typing_env })
66        }
67    }
68
69    pub fn assert_fully_normalized(
70        self,
71        typing_env: ty::TypingEnv<'tcx>,
72        value: impl TypeFoldable<TyCtxt<'tcx>> + Eq,
73    ) {
74        let value = self.erase_and_anonymize_regions(value);
75        if value.has_aliases() {
76            match (&value.clone(),
        &value.fold_with(&mut NormalizeAfterErasingRegionsFolder {
                        tcx: self,
                        typing_env,
                    })) {
    (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!(
77                value.clone(),
78                value.fold_with(&mut NormalizeAfterErasingRegionsFolder { tcx: self, typing_env })
79            )
80        }
81    }
82
83    pub fn debug_assert_fully_normalized(
84        self,
85        typing_env: ty::TypingEnv<'tcx>,
86        value: impl TypeFoldable<TyCtxt<'tcx>> + Eq,
87    ) {
88        if truecfg!(debug_assertions) {
89            self.assert_fully_normalized(typing_env, value);
90        }
91    }
92
93    /// Tries to erase the regions in `value` and then fully normalize all the
94    /// types found within. The result will also have regions erased.
95    ///
96    /// Contrary to `normalize_erasing_regions` this function does not assume that normalization
97    /// succeeds.
98    pub fn try_normalize_erasing_regions<T>(
99        self,
100        typing_env: ty::TypingEnv<'tcx>,
101        value: Unnormalized<'tcx, T>,
102    ) -> Result<T, NormalizationError<'tcx>>
103    where
104        T: TypeFoldable<TyCtxt<'tcx>>,
105    {
106        let value = value.skip_normalization();
107        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/ty/normalize_erasing_regions.rs:107",
                        "rustc_middle::ty::normalize_erasing_regions",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/ty/normalize_erasing_regions.rs"),
                        ::tracing_core::__macro_support::Option::Some(107u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_middle::ty::normalize_erasing_regions"),
                        ::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};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("try_normalize_erasing_regions::<{0}>(value={1:?}, typing_env={2:?})",
                                                    std::any::type_name::<T>(), value, typing_env) as
                                            &dyn Value))])
            });
    } else { ; }
};debug!(
108            "try_normalize_erasing_regions::<{}>(value={:?}, typing_env={:?})",
109            std::any::type_name::<T>(),
110            value,
111            typing_env,
112        );
113
114        // Erase first before we do the real query -- this keeps the
115        // cache from being too polluted.
116        let value = self.erase_and_anonymize_regions(value);
117        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/ty/normalize_erasing_regions.rs:117",
                        "rustc_middle::ty::normalize_erasing_regions",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/ty/normalize_erasing_regions.rs"),
                        ::tracing_core::__macro_support::Option::Some(117u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_middle::ty::normalize_erasing_regions"),
                        ::tracing_core::field::FieldSet::new(&["value"],
                            ::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};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&value) as
                                            &dyn Value))])
            });
    } else { ; }
};debug!(?value);
118
119        if !value.has_aliases() {
120            Ok(value)
121        } else {
122            let mut folder = TryNormalizeAfterErasingRegionsFolder::new(self, typing_env);
123            value.try_fold_with(&mut folder)
124        }
125    }
126
127    /// If you have a `Binder<'tcx, T>`, you can do this to strip out the
128    /// late-bound regions and then normalize the result, yielding up
129    /// a `T` (with regions erased). This is appropriate when the
130    /// binder is being instantiated at the call site.
131    ///
132    /// N.B., currently, higher-ranked type bounds inhibit
133    /// normalization. Therefore, each time we erase them in
134    /// codegen, we need to normalize the contents.
135    // FIXME(@lcnr): This method should not be necessary, we now normalize
136    // inside of binders. We should be able to only use
137    // `tcx.instantiate_bound_regions_with_erased`.
138    #[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("normalize_erasing_late_bound_regions",
                                    "rustc_middle::ty::normalize_erasing_regions",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/ty/normalize_erasing_regions.rs"),
                                    ::tracing_core::__macro_support::Option::Some(138u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_middle::ty::normalize_erasing_regions"),
                                    ::tracing_core::field::FieldSet::new(&["value"],
                                        ::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};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&value)
                                                            as &dyn 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;
        }
        {
            let value = self.instantiate_bound_regions_with_erased(value);
            self.normalize_erasing_regions(typing_env,
                Unnormalized::new_wip(value))
        }
    }
}#[tracing::instrument(level = "debug", skip(self, typing_env))]
139    pub fn normalize_erasing_late_bound_regions<T>(
140        self,
141        typing_env: ty::TypingEnv<'tcx>,
142        value: ty::Binder<'tcx, T>,
143    ) -> T
144    where
145        T: TypeFoldable<TyCtxt<'tcx>>,
146    {
147        let value = self.instantiate_bound_regions_with_erased(value);
148        self.normalize_erasing_regions(typing_env, Unnormalized::new_wip(value))
149    }
150
151    /// Monomorphizes a type from the AST by first applying the
152    /// in-scope instantiations and then normalizing any associated
153    /// types.
154    /// Panics if normalization fails. In case normalization might fail
155    /// use `try_instantiate_and_normalize_erasing_regions` instead.
156    #[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("instantiate_and_normalize_erasing_regions",
                                    "rustc_middle::ty::normalize_erasing_regions",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/ty/normalize_erasing_regions.rs"),
                                    ::tracing_core::__macro_support::Option::Some(156u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_middle::ty::normalize_erasing_regions"),
                                    ::tracing_core::field::FieldSet::new(&["param_args",
                                                    "typing_env", "value"],
                                        ::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};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&param_args)
                                                            as &dyn Value)),
                                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&typing_env)
                                                            as &dyn Value)),
                                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&value)
                                                            as &dyn 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;
        }
        {
            let instantiated = value.instantiate(self, param_args);
            self.normalize_erasing_regions(typing_env, instantiated)
        }
    }
}#[instrument(level = "debug", skip(self))]
157    pub fn instantiate_and_normalize_erasing_regions<T>(
158        self,
159        param_args: GenericArgsRef<'tcx>,
160        typing_env: ty::TypingEnv<'tcx>,
161        value: EarlyBinder<'tcx, T>,
162    ) -> T
163    where
164        T: TypeFoldable<TyCtxt<'tcx>>,
165    {
166        let instantiated = value.instantiate(self, param_args);
167        self.normalize_erasing_regions(typing_env, instantiated)
168    }
169
170    /// Monomorphizes a type from the AST by first applying the
171    /// in-scope instantiations and then trying to normalize any associated
172    /// types. Contrary to `instantiate_and_normalize_erasing_regions` this does
173    /// not assume that normalization succeeds.
174    #[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_instantiate_and_normalize_erasing_regions",
                                    "rustc_middle::ty::normalize_erasing_regions",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/ty/normalize_erasing_regions.rs"),
                                    ::tracing_core::__macro_support::Option::Some(174u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_middle::ty::normalize_erasing_regions"),
                                    ::tracing_core::field::FieldSet::new(&["param_args",
                                                    "typing_env", "value"],
                                        ::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};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&param_args)
                                                            as &dyn Value)),
                                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&typing_env)
                                                            as &dyn Value)),
                                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&value)
                                                            as &dyn 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:
                    Result<T, NormalizationError<'tcx>> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let instantiated = value.instantiate(self, param_args);
            self.try_normalize_erasing_regions(typing_env, instantiated)
        }
    }
}#[instrument(level = "debug", skip(self))]
175    pub fn try_instantiate_and_normalize_erasing_regions<T>(
176        self,
177        param_args: GenericArgsRef<'tcx>,
178        typing_env: ty::TypingEnv<'tcx>,
179        value: EarlyBinder<'tcx, T>,
180    ) -> Result<T, NormalizationError<'tcx>>
181    where
182        T: TypeFoldable<TyCtxt<'tcx>>,
183    {
184        let instantiated = value.instantiate(self, param_args);
185        self.try_normalize_erasing_regions(typing_env, instantiated)
186    }
187}
188
189struct NormalizeAfterErasingRegionsFolder<'tcx> {
190    tcx: TyCtxt<'tcx>,
191    typing_env: ty::TypingEnv<'tcx>,
192}
193
194impl<'tcx> NormalizeAfterErasingRegionsFolder<'tcx> {
195    fn normalize_generic_arg_after_erasing_regions(
196        &self,
197        arg: ty::GenericArg<'tcx>,
198    ) -> ty::GenericArg<'tcx> {
199        let arg = self.typing_env.as_query_input(arg);
200        self.tcx.try_normalize_generic_arg_after_erasing_regions(arg).unwrap_or_else(|_| {
201            crate::util::bug::bug_fmt(format_args!("Failed to normalize {0:?} in typing_env={1:?}, maybe try to call `try_normalize_erasing_regions` instead",
        arg.value, self.typing_env))bug!(
202                "Failed to normalize {:?} in typing_env={:?}, \
203                maybe try to call `try_normalize_erasing_regions` instead",
204                arg.value,
205                self.typing_env,
206            )
207        })
208    }
209}
210
211impl<'tcx> TypeFolder<TyCtxt<'tcx>> for NormalizeAfterErasingRegionsFolder<'tcx> {
212    fn cx(&self) -> TyCtxt<'tcx> {
213        self.tcx
214    }
215
216    fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
217        self.normalize_generic_arg_after_erasing_regions(ty.into()).expect_ty()
218    }
219
220    fn fold_const(&mut self, c: ty::Const<'tcx>) -> ty::Const<'tcx> {
221        self.normalize_generic_arg_after_erasing_regions(c.into()).expect_const()
222    }
223}
224
225struct TryNormalizeAfterErasingRegionsFolder<'tcx> {
226    tcx: TyCtxt<'tcx>,
227    typing_env: ty::TypingEnv<'tcx>,
228}
229
230impl<'tcx> TryNormalizeAfterErasingRegionsFolder<'tcx> {
231    fn new(tcx: TyCtxt<'tcx>, typing_env: ty::TypingEnv<'tcx>) -> Self {
232        TryNormalizeAfterErasingRegionsFolder { tcx, typing_env }
233    }
234
235    #[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_normalize_generic_arg_after_erasing_regions",
                                    "rustc_middle::ty::normalize_erasing_regions",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/ty/normalize_erasing_regions.rs"),
                                    ::tracing_core::__macro_support::Option::Some(235u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_middle::ty::normalize_erasing_regions"),
                                    ::tracing_core::field::FieldSet::new(&["arg"],
                                        ::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};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&arg)
                                                            as &dyn 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:
                    Result<ty::GenericArg<'tcx>, NoSolution> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let input = self.typing_env.as_query_input(arg);
            self.tcx.try_normalize_generic_arg_after_erasing_regions(input)
        }
    }
}#[instrument(skip(self), level = "debug")]
236    fn try_normalize_generic_arg_after_erasing_regions(
237        &self,
238        arg: ty::GenericArg<'tcx>,
239    ) -> Result<ty::GenericArg<'tcx>, NoSolution> {
240        let input = self.typing_env.as_query_input(arg);
241        self.tcx.try_normalize_generic_arg_after_erasing_regions(input)
242    }
243}
244
245impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for TryNormalizeAfterErasingRegionsFolder<'tcx> {
246    type Error = NormalizationError<'tcx>;
247
248    fn cx(&self) -> TyCtxt<'tcx> {
249        self.tcx
250    }
251
252    fn try_fold_ty(&mut self, ty: Ty<'tcx>) -> Result<Ty<'tcx>, Self::Error> {
253        match self.try_normalize_generic_arg_after_erasing_regions(ty.into()) {
254            Ok(t) => Ok(t.expect_ty()),
255            Err(_) => Err(NormalizationError::Type(ty)),
256        }
257    }
258
259    fn try_fold_const(&mut self, c: ty::Const<'tcx>) -> Result<ty::Const<'tcx>, Self::Error> {
260        match self.try_normalize_generic_arg_after_erasing_regions(c.into()) {
261            Ok(t) => Ok(t.expect_const()),
262            Err(_) => Err(NormalizationError::Const(c)),
263        }
264    }
265}