Skip to main content

rustc_borrowck/type_check/
relate_tys.rs

1use rustc_data_structures::fx::FxHashMap;
2use rustc_errors::ErrorGuaranteed;
3use rustc_hir::def_id::DefId;
4use rustc_infer::infer::relate::{PredicateEmittingRelation, Relate, RelateResult, TypeRelation};
5use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin};
6use rustc_infer::traits::Obligation;
7use rustc_infer::traits::solve::Goal;
8use rustc_middle::mir::ConstraintCategory;
9use rustc_middle::traits::ObligationCause;
10use rustc_middle::traits::query::NoSolution;
11use rustc_middle::ty::relate::combine::{combine_ty_args, super_combine_consts, super_combine_tys};
12use rustc_middle::ty::relate::relate_args_invariantly;
13use rustc_middle::ty::{self, FnMutDelegate, Ty, TyCtxt, TypeVisitableExt};
14use rustc_span::{Span, Symbol, bug, span_bug, sym};
15use tracing::{debug, instrument};
16
17use crate::constraints::OutlivesConstraint;
18use crate::diagnostics::UniverseInfo;
19use crate::renumber::RegionCtxt;
20use crate::type_check::{InstantiateOpaqueType, Locations, TypeChecker};
21
22impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
23    /// Adds sufficient constraints to ensure that `a R b` where `R` depends on `v`:
24    ///
25    /// - "Covariant" `a <: b`
26    /// - "Invariant" `a == b`
27    /// - "Contravariant" `a :> b`
28    ///
29    /// N.B., the type `a` is permitted to have unresolved inference
30    /// variables, but not the type `b`.
31    {}
#[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("relate_types",
                                    "rustc_borrowck::type_check::relate_tys",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
                                    ::tracing_core::__macro_support::Option::Some(31u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("a")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("a");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("v")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("v");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("b")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("b");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("locations")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("locations");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("category")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("category");
                                                        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(&a)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&v)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&b)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&locations)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&category)
                                                            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: Result<(), NoSolution> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            NllTypeRelating::new(self, locations, category,
                        UniverseInfo::relate(a, b), v).relate(a, b)?;
            Ok(())
        }
    }
}#[instrument(skip(self), level = "debug")]
32    pub(super) fn relate_types(
33        &mut self,
34        a: Ty<'tcx>,
35        v: ty::Variance,
36        b: Ty<'tcx>,
37        locations: Locations,
38        category: ConstraintCategory<'tcx>,
39    ) -> Result<(), NoSolution> {
40        NllTypeRelating::new(self, locations, category, UniverseInfo::relate(a, b), v)
41            .relate(a, b)?;
42        Ok(())
43    }
44
45    /// Add sufficient constraints to ensure `a == b`. See also [Self::relate_types].
46    pub(super) fn eq_args(
47        &mut self,
48        a: ty::GenericArgs<'tcx>,
49        b: ty::GenericArgs<'tcx>,
50        locations: Locations,
51        category: ConstraintCategory<'tcx>,
52    ) -> Result<(), NoSolution> {
53        NllTypeRelating::new(self, locations, category, UniverseInfo::other(), ty::Invariant)
54            .relate(a, b)?;
55        Ok(())
56    }
57}
58
59struct NllTypeRelating<'a, 'b, 'tcx> {
60    type_checker: &'a mut TypeChecker<'b, 'tcx>,
61
62    /// Where (and why) is this relation taking place?
63    locations: Locations,
64
65    /// What category do we assign the resulting `'a: 'b` relationships?
66    category: ConstraintCategory<'tcx>,
67
68    /// Information so that error reporting knows what types we are relating
69    /// when reporting a bound region error.
70    universe_info: UniverseInfo<'tcx>,
71
72    /// How are we relating `a` and `b`?
73    ///
74    /// - Covariant means `a <: b`.
75    /// - Contravariant means `b <: a`.
76    /// - Invariant means `a == b`.
77    /// - Bivariant means that it doesn't matter.
78    ambient_variance: ty::Variance,
79
80    ambient_variance_info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
81}
82
83impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
84    fn new(
85        type_checker: &'a mut TypeChecker<'b, 'tcx>,
86        locations: Locations,
87        category: ConstraintCategory<'tcx>,
88        universe_info: UniverseInfo<'tcx>,
89        ambient_variance: ty::Variance,
90    ) -> Self {
91        Self {
92            type_checker,
93            locations,
94            category,
95            universe_info,
96            ambient_variance,
97            ambient_variance_info: ty::VarianceDiagInfo::default(),
98        }
99    }
100
101    fn ambient_covariance(&self) -> bool {
102        match self.ambient_variance {
103            ty::Covariant | ty::Invariant => true,
104            ty::Contravariant | ty::Bivariant => false,
105        }
106    }
107
108    fn ambient_contravariance(&self) -> bool {
109        match self.ambient_variance {
110            ty::Contravariant | ty::Invariant => true,
111            ty::Covariant | ty::Bivariant => false,
112        }
113    }
114
115    fn relate_opaques(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, ()> {
116        let infcx = self.type_checker.infcx;
117        if true {
    if !!infcx.next_trait_solver() {
        ::core::panicking::panic("assertion failed: !infcx.next_trait_solver()")
    };
};debug_assert!(!infcx.next_trait_solver());
118        // `handle_opaque_type` cannot handle subtyping, so to support subtyping
119        // we instead eagerly generalize here. This is a bit of a mess but will go
120        // away once we're using the new solver.
121        //
122        // Given `opaque rel B`, we create a new infer var `ty_vid` constrain it
123        // by using `ty_vid rel B` and then finally and end by equating `ty_vid` to
124        // the opaque.
125        let mut enable_subtyping = |ty, opaque_is_expected| {
126            // We create the fresh inference variable in the highest universe.
127            // In theory we could limit it to the highest universe in the args of
128            // the opaque but that isn't really worth the effort.
129            //
130            // We'll make sure that the opaque type can actually name everything
131            // in its hidden type later on.
132            let ty_vid = infcx.next_ty_vid(self.span());
133            let variance = if opaque_is_expected {
134                self.ambient_variance
135            } else {
136                self.ambient_variance.xform(ty::Contravariant)
137            };
138
139            self.type_checker.infcx.instantiate_ty_var(
140                self,
141                opaque_is_expected,
142                ty_vid,
143                variance,
144                ty,
145            )?;
146            let new_var =
147                infcx.deeply_resolve_ignoring_regions(Ty::new_infer(infcx.tcx, ty::TyVar(ty_vid)));
148
149            // Any regions in this new type must be live everywhere, so we mark them as such.
150            // (It may be that it only needs to be live where the opaque type itself is - which
151            // includes defining use sites, but we'll be conservative and mark all points as live).
152            // This is needed for Polonius, which doesn't propagate constraints
153            // through dead regions. See issue #160669.
154            //
155            // We only do this in the root universe. Inside a binder these regions live in a higher
156            // universe and their values contain placeholders; marking them live at every point
157            // leaks those placeholders, turning the higher-ranked check into an error which then
158            // suppresses the deferred opaque type diagnostics.
159            if infcx.universe() == ty::UniverseIndex::ROOT {
160                let tcx = infcx.tcx;
161                let liveness = &mut self.type_checker.constraints.liveness_constraints;
162                ty::fold_regions(tcx, new_var, |r, _| {
163                    if let ty::ReVar(vid) = r.kind() {
164                        liveness.add_all_points(vid);
165                    }
166                    r
167                });
168            }
169
170            Ok(new_var)
171        };
172
173        let (a, b) = match (a.kind(), b.kind()) {
174            (&ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }), _) => {
175                (a, enable_subtyping(b, true)?)
176            }
177            (_, &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. })) => {
178                (enable_subtyping(a, false)?, b)
179            }
180            _ => {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("expected at least one opaque type in `relate_opaques`, got {0} and {1}.",
                a, b)));
}unreachable!(
181                "expected at least one opaque type in `relate_opaques`, got {a} and {b}."
182            ),
183        };
184        self.register_goals(infcx.handle_opaque_type(a, b, self.span(), self.param_env())?);
185        Ok(())
186    }
187
188    fn enter_forall<T, U>(
189        &mut self,
190        binder: ty::Binder<'tcx, T>,
191        f: impl FnOnce(&mut Self, T) -> U,
192    ) -> U
193    where
194        T: ty::TypeFoldable<TyCtxt<'tcx>> + Copy,
195    {
196        let value = if let Some(inner) = binder.no_bound_vars() {
197            inner
198        } else {
199            let infcx = self.type_checker.infcx;
200            let mut lazy_universe = None;
201            let delegate = FnMutDelegate {
202                regions: &mut |br: ty::BoundRegion<'tcx>| {
203                    // The first time this closure is called, create a
204                    // new universe for the placeholders we will make
205                    // from here out.
206                    let universe = lazy_universe.unwrap_or_else(|| {
207                        let universe = self.create_next_universe();
208                        lazy_universe = Some(universe);
209                        universe
210                    });
211
212                    let placeholder = ty::PlaceholderRegion::new(universe, br);
213                    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs:213",
                        "rustc_borrowck::type_check::relate_tys",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
                        ::tracing_core::__macro_support::Option::Some(213u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("placeholder")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("placeholder");
                                            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(&placeholder)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?placeholder);
214                    let placeholder_reg = self.next_placeholder_region(placeholder);
215                    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs:215",
                        "rustc_borrowck::type_check::relate_tys",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
                        ::tracing_core::__macro_support::Option::Some(215u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("placeholder_reg")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("placeholder_reg");
                                            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(&placeholder_reg)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?placeholder_reg);
216
217                    placeholder_reg
218                },
219                types: &mut |_bound_ty: ty::BoundTy<'tcx>| {
220                    {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("we only replace regions in nll_relate, not types")));
}unreachable!("we only replace regions in nll_relate, not types")
221                },
222                consts: &mut |_bound_const: ty::BoundConst<'tcx>| {
223                    {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("we only replace regions in nll_relate, not consts")));
}unreachable!("we only replace regions in nll_relate, not consts")
224                },
225            };
226
227            infcx.tcx.replace_bound_vars_uncached(binder, delegate)
228        };
229
230        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs:230",
                        "rustc_borrowck::type_check::relate_tys",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
                        ::tracing_core::__macro_support::Option::Some(230u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
                        ::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);
231        f(self, value)
232    }
233
234    {}
#[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_binder_with_existentials",
                                    "rustc_borrowck::type_check::relate_tys",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
                                    ::tracing_core::__macro_support::Option::Some(234u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("binder")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("binder");
                                                        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(&binder)
                                                            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;
        }
        {
            if let Some(inner) = binder.no_bound_vars() { return inner; }
            let infcx = self.type_checker.infcx;
            let mut reg_map = FxHashMap::default();
            let delegate =
                FnMutDelegate {
                    regions: &mut |br: ty::BoundRegion<'tcx>|
                            {
                                if let Some(ex_reg_var) = reg_map.get(&br) {
                                    *ex_reg_var
                                } else {
                                    let ex_reg_var =
                                        self.next_existential_region_var(br.kind.get_name(infcx.infcx.tcx));
                                    {
                                        use ::tracing::__macro_support::Callsite as _;
                                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                            {
                                                static META: ::tracing::Metadata<'static> =
                                                    {
                                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs:252",
                                                            "rustc_borrowck::type_check::relate_tys",
                                                            ::tracing::Level::DEBUG,
                                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
                                                            ::tracing_core::__macro_support::Option::Some(252u32),
                                                            ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
                                                            ::tracing_core::field::FieldSet::new(&[{
                                                                                const NAME:
                                                                                    ::tracing::__macro_support::FieldName<{
                                                                                        ::tracing::__macro_support::FieldName::len("ex_reg_var")
                                                                                    }> =
                                                                                    ::tracing::__macro_support::FieldName::new("ex_reg_var");
                                                                                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(&ex_reg_var)
                                                                                as &dyn ::tracing::field::Value))])
                                                });
                                        } else { ; }
                                    };
                                    reg_map.insert(br, ex_reg_var);
                                    ex_reg_var
                                }
                            },
                    types: &mut |_bound_ty: ty::BoundTy<'tcx>|
                            {
                                {
                                    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
                                            format_args!("we only replace regions in nll_relate, not types")));
                                }
                            },
                    consts: &mut |_bound_const: ty::BoundConst<'tcx>|
                            {
                                {
                                    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
                                            format_args!("we only replace regions in nll_relate, not consts")));
                                }
                            },
                };
            let replaced =
                infcx.tcx.replace_bound_vars_uncached(binder, delegate);
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs:267",
                                    "rustc_borrowck::type_check::relate_tys",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
                                    ::tracing_core::__macro_support::Option::Some(267u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("replaced")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("replaced");
                                                        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(&replaced)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            replaced
        }
    }
}#[instrument(skip(self), level = "debug")]
235    fn instantiate_binder_with_existentials<T>(&mut self, binder: ty::Binder<'tcx, T>) -> T
236    where
237        T: ty::TypeFoldable<TyCtxt<'tcx>> + Copy,
238    {
239        if let Some(inner) = binder.no_bound_vars() {
240            return inner;
241        }
242
243        let infcx = self.type_checker.infcx;
244        let mut reg_map = FxHashMap::default();
245        let delegate = FnMutDelegate {
246            regions: &mut |br: ty::BoundRegion<'tcx>| {
247                if let Some(ex_reg_var) = reg_map.get(&br) {
248                    *ex_reg_var
249                } else {
250                    let ex_reg_var =
251                        self.next_existential_region_var(br.kind.get_name(infcx.infcx.tcx));
252                    debug!(?ex_reg_var);
253                    reg_map.insert(br, ex_reg_var);
254
255                    ex_reg_var
256                }
257            },
258            types: &mut |_bound_ty: ty::BoundTy<'tcx>| {
259                unreachable!("we only replace regions in nll_relate, not types")
260            },
261            consts: &mut |_bound_const: ty::BoundConst<'tcx>| {
262                unreachable!("we only replace regions in nll_relate, not consts")
263            },
264        };
265
266        let replaced = infcx.tcx.replace_bound_vars_uncached(binder, delegate);
267        debug!(?replaced);
268
269        replaced
270    }
271
272    fn create_next_universe(&mut self) -> ty::UniverseIndex {
273        let universe = self.type_checker.infcx.create_next_universe();
274        self.type_checker.constraints.universe_causes.insert(universe, self.universe_info.clone());
275        universe
276    }
277
278    {}
#[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("next_existential_region_var",
                                    "rustc_borrowck::type_check::relate_tys",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
                                    ::tracing_core::__macro_support::Option::Some(278u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("name")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("name");
                                                        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(&name)
                                                            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::Region<'tcx> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let origin = NllRegionVariableOrigin::Existential { name };
            self.type_checker.infcx.next_nll_region_var(origin,
                || RegionCtxt::Existential(name))
        }
    }
}#[instrument(skip(self), level = "debug")]
279    fn next_existential_region_var(&mut self, name: Option<Symbol>) -> ty::Region<'tcx> {
280        let origin = NllRegionVariableOrigin::Existential { name };
281        self.type_checker.infcx.next_nll_region_var(origin, || RegionCtxt::Existential(name))
282    }
283
284    {}
#[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("next_placeholder_region",
                                    "rustc_borrowck::type_check::relate_tys",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
                                    ::tracing_core::__macro_support::Option::Some(284u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("placeholder")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("placeholder");
                                                        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(&placeholder)
                                                            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::Region<'tcx> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let reg =
                self.type_checker.constraints.placeholder_region(self.type_checker.infcx,
                    placeholder);
            let reg_info =
                match placeholder.bound.kind {
                    ty::BoundRegionKind::Anon => sym::anon,
                    ty::BoundRegionKind::Named(def_id) =>
                        self.type_checker.tcx().item_name(def_id),
                    ty::BoundRegionKind::ClosureEnv => sym::env,
                    ty::BoundRegionKind::NamedForPrinting(_) =>
                        ::rustc_span::macros::bug_impl(None,
                            format_args!("only used for pretty printing"),
                            Location::caller()),
                };
            if true {
                let mut var_to_origin =
                    self.type_checker.infcx.reg_var_to_origin.borrow_mut();
                let new = RegionCtxt::Placeholder(reg_info);
                let prev = var_to_origin.insert(reg.as_var(), new);
                if let Some(prev) = prev {
                    {
                        match (&new, &prev) {
                            (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);
                                }
                            }
                        }
                    };
                }
            }
            reg
        }
    }
}#[instrument(skip(self), level = "debug")]
285    fn next_placeholder_region(
286        &mut self,
287        placeholder: ty::PlaceholderRegion<'tcx>,
288    ) -> ty::Region<'tcx> {
289        let reg =
290            self.type_checker.constraints.placeholder_region(self.type_checker.infcx, placeholder);
291
292        let reg_info = match placeholder.bound.kind {
293            ty::BoundRegionKind::Anon => sym::anon,
294            ty::BoundRegionKind::Named(def_id) => self.type_checker.tcx().item_name(def_id),
295            ty::BoundRegionKind::ClosureEnv => sym::env,
296            ty::BoundRegionKind::NamedForPrinting(_) => bug!("only used for pretty printing"),
297        };
298
299        if cfg!(debug_assertions) {
300            let mut var_to_origin = self.type_checker.infcx.reg_var_to_origin.borrow_mut();
301            let new = RegionCtxt::Placeholder(reg_info);
302            let prev = var_to_origin.insert(reg.as_var(), new);
303            if let Some(prev) = prev {
304                assert_eq!(new, prev);
305            }
306        }
307
308        reg
309    }
310
311    fn push_outlives(
312        &mut self,
313        sup: ty::Region<'tcx>,
314        sub: ty::Region<'tcx>,
315        info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
316    ) {
317        let sub = self.type_checker.universal_regions.to_region_vid(sub);
318        let sup = self.type_checker.universal_regions.to_region_vid(sup);
319        self.type_checker.constraints.outlives_constraints.push(OutlivesConstraint {
320            sup,
321            sub,
322            locations: self.locations,
323            span: self.locations.span(self.type_checker.body),
324            category: self.category,
325            variance_info: info,
326            from_closure: false,
327        });
328    }
329}
330
331impl<'b, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'b, 'tcx> {
332    fn cx(&self) -> TyCtxt<'tcx> {
333        self.type_checker.infcx.tcx
334    }
335
336    fn relate_ty_args(
337        &mut self,
338        a_ty: Ty<'tcx>,
339        b_ty: Ty<'tcx>,
340        def_id: DefId,
341        a_args: ty::GenericArgs<'tcx>,
342        b_args: ty::GenericArgs<'tcx>,
343        _: impl FnOnce(ty::GenericArgs<'tcx>) -> Ty<'tcx>,
344    ) -> RelateResult<'tcx, Ty<'tcx>> {
345        if self.ambient_variance == ty::Invariant {
346            // Avoid fetching the variance if we are in an invariant context,
347            // slightly improves perf.
348            relate_args_invariantly(self, a_args, b_args)?;
349            Ok(a_ty)
350        } else {
351            let variances = self.cx().variances_of(def_id);
352            combine_ty_args(
353                &self.type_checker.infcx.infcx,
354                self,
355                a_ty,
356                b_ty,
357                variances,
358                a_args,
359                b_args,
360                |_| a_ty,
361            )
362        }
363    }
364
365    {}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
            ::tracing::Level::TRACE <=
                ::tracing::level_filters::LevelFilter::current() || { false }
    {
    __tracing_attr_span =
        {
            use ::tracing::__macro_support::Callsite as _;
            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                {
                    static META: ::tracing::Metadata<'static> =
                        {
                            ::tracing_core::metadata::Metadata::new("relate_with_variance",
                                "rustc_borrowck::type_check::relate_tys",
                                ::tracing::Level::TRACE,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
                                ::tracing_core::__macro_support::Option::Some(365u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("variance")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("variance");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("a")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("a");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("b")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("b");
                                                    NAME.as_str()
                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                ::tracing::metadata::Kind::SPAN)
                        };
                    ::tracing::callsite::DefaultCallsite::new(&META)
                };
            let mut interest = ::tracing::subscriber::Interest::never();
            if ::tracing::Level::TRACE <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::TRACE <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        { interest = __CALLSITE.interest(); !interest.is_never() }
                    &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest) {
                let meta = __CALLSITE.metadata();
                ::tracing::Span::new(meta,
                    &{
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&variance)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&a)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&b)
                                                        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: RelateResult<'tcx, T> =
                            loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        let old_ambient_variance = self.ambient_variance;
                        self.ambient_variance =
                            self.ambient_variance.xform(variance);
                        self.ambient_variance_info =
                            self.ambient_variance_info.xform(info);
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs:377",
                                                "rustc_borrowck::type_check::relate_tys",
                                                ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
                                                ::tracing_core::__macro_support::Option::Some(377u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("self.ambient_variance")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("self.ambient_variance");
                                                                    NAME.as_str()
                                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                ::tracing::metadata::Kind::EVENT)
                                        };
                                    ::tracing::callsite::DefaultCallsite::new(&META)
                                };
                            let enabled =
                                ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                        ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::LevelFilter::current() &&
                                    {
                                        let interest = __CALLSITE.interest();
                                        !interest.is_never() &&
                                            ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                interest)
                                    };
                            if enabled {
                                (|value_set: ::tracing::field::ValueSet|
                                            {
                                                let meta = __CALLSITE.metadata();
                                                ::tracing::Event::dispatch(meta, &value_set);
                                                ;
                                            })({
                                        #[allow(unused_imports)]
                                        use ::tracing::field::{debug, display, Value};
                                        __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self.ambient_variance)
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        let r =
                            if self.ambient_variance == ty::Bivariant {
                                Ok(a)
                            } else { self.relate(a, b) };
                        self.ambient_variance = old_ambient_variance;
                        r
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs:365",
                        "rustc_borrowck::type_check::relate_tys",
                        ::tracing::Level::TRACE,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
                        ::tracing_core::__macro_support::Option::Some(365u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
                        ::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::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::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(skip(self, info), level = "trace", ret)]
366    fn relate_with_variance<T: Relate<TyCtxt<'tcx>>>(
367        &mut self,
368        variance: ty::Variance,
369        info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
370        a: T,
371        b: T,
372    ) -> RelateResult<'tcx, T> {
373        let old_ambient_variance = self.ambient_variance;
374        self.ambient_variance = self.ambient_variance.xform(variance);
375        self.ambient_variance_info = self.ambient_variance_info.xform(info);
376
377        debug!(?self.ambient_variance);
378        // In a bivariant context this always succeeds.
379        let r = if self.ambient_variance == ty::Bivariant { Ok(a) } else { self.relate(a, b) };
380
381        self.ambient_variance = old_ambient_variance;
382
383        r
384    }
385
386    {}
#[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("tys",
                                    "rustc_borrowck::type_check::relate_tys",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
                                    ::tracing_core::__macro_support::Option::Some(386u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("a")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("a");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("b")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("b");
                                                        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(&a)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&b)
                                                            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: RelateResult<'tcx, Ty<'tcx>> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            let infcx = self.type_checker.infcx;
            let a = infcx.shallow_resolve(a);
            if !!b.has_non_region_infer() {
                {
                    ::core::panicking::panic_fmt(format_args!("unexpected inference var {0:?}",
                            b));
                }
            };
            if a == b { return Ok(a); }
            match (a.kind(), b.kind()) {
                (_, &ty::Infer(ty::TyVar(_))) => {
                    ::rustc_span::macros::bug_impl(Some(self.span()),
                        format_args!("should not be relating type variables on the right in MIR typeck"),
                        Location::caller());
                }
                (&ty::Alias(ty::IsRigid::No, _), _) |
                    (_, &ty::Alias(ty::IsRigid::No, _)) if
                    infcx.next_trait_solver() => {
                    ::rustc_span::macros::bug_impl(Some(self.span()),
                        format_args!("it should not be possible to encounter unnormalized aliases in borrowck"),
                        Location::caller());
                }
                (&ty::Infer(ty::TyVar(a_vid)), _) => {
                    infcx.instantiate_ty_var(self, true, a_vid,
                            self.ambient_variance, b)?
                }
                (&ty::Alias(_, ty::AliasTy {
                    kind: ty::Opaque { def_id: a_def_id }, .. }),
                    &ty::Alias(_, ty::AliasTy {
                    kind: ty::Opaque { def_id: b_def_id }, .. })) if
                    a_def_id == b_def_id || infcx.next_trait_solver() => {
                    super_combine_tys(&infcx.infcx, self, a,
                                    b).map(|_|
                                    ()).or_else(|err|
                                {
                                    if !!self.type_checker.infcx.next_trait_solver() {
                                        ::core::panicking::panic("assertion failed: !self.type_checker.infcx.next_trait_solver()")
                                    };
                                    self.cx().dcx().span_delayed_bug(self.span(),
                                        "failure to relate an opaque to itself should result in an error later on");
                                    if a_def_id.is_local() {
                                        self.relate_opaques(a, b)
                                    } else { Err(err) }
                                })?;
                }
                (&ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, ..
                    }), _) |
                    (_,
                    &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, ..
                    })) if
                    def_id.is_local() &&
                        !self.type_checker.infcx.next_trait_solver() => {
                    self.relate_opaques(a, b)?;
                }
                _ => {
                    {
                        use ::tracing::__macro_support::Callsite as _;
                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                            {
                                static META: ::tracing::Metadata<'static> =
                                    {
                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs:446",
                                            "rustc_borrowck::type_check::relate_tys",
                                            ::tracing::Level::DEBUG,
                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
                                            ::tracing_core::__macro_support::Option::Some(446u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
                                            ::tracing_core::field::FieldSet::new(&[{
                                                                const NAME:
                                                                    ::tracing::__macro_support::FieldName<{
                                                                        ::tracing::__macro_support::FieldName::len("a")
                                                                    }> =
                                                                    ::tracing::__macro_support::FieldName::new("a");
                                                                NAME.as_str()
                                                            },
                                                            {
                                                                const NAME:
                                                                    ::tracing::__macro_support::FieldName<{
                                                                        ::tracing::__macro_support::FieldName::len("b")
                                                                    }> =
                                                                    ::tracing::__macro_support::FieldName::new("b");
                                                                NAME.as_str()
                                                            },
                                                            {
                                                                const NAME:
                                                                    ::tracing::__macro_support::FieldName<{
                                                                        ::tracing::__macro_support::FieldName::len("self.ambient_variance")
                                                                    }> =
                                                                    ::tracing::__macro_support::FieldName::new("self.ambient_variance");
                                                                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(&a)
                                                                as &dyn ::tracing::field::Value)),
                                                    (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&b)
                                                                as &dyn ::tracing::field::Value)),
                                                    (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self.ambient_variance)
                                                                as &dyn ::tracing::field::Value))])
                                });
                        } else { ; }
                    };
                    super_combine_tys(&self.type_checker.infcx.infcx, self, a,
                            b)?;
                }
            }
            Ok(a)
        }
    }
}#[instrument(skip(self), level = "debug")]
387    fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
388        let infcx = self.type_checker.infcx;
389
390        let a = infcx.shallow_resolve(a);
391        assert!(!b.has_non_region_infer(), "unexpected inference var {:?}", b);
392
393        if a == b {
394            return Ok(a);
395        }
396
397        match (a.kind(), b.kind()) {
398            (_, &ty::Infer(ty::TyVar(_))) => {
399                span_bug!(
400                    self.span(),
401                    "should not be relating type variables on the right in MIR typeck"
402                );
403            }
404
405            (&ty::Alias(ty::IsRigid::No, _), _) | (_, &ty::Alias(ty::IsRigid::No, _))
406                if infcx.next_trait_solver() =>
407            {
408                // NOTE(khyperia): If this turns out to be possible, either the caller should
409                // normalize the alias, or we should normalize the alias here. See the PR that
410                // introduced this comment for how to do so, which normalizes aliases in other
411                // relations.
412                span_bug!(
413                    self.span(),
414                    "it should not be possible to encounter unnormalized aliases in borrowck"
415                );
416            }
417
418            (&ty::Infer(ty::TyVar(a_vid)), _) => {
419                infcx.instantiate_ty_var(self, true, a_vid, self.ambient_variance, b)?
420            }
421
422            (
423                &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id: a_def_id }, .. }),
424                &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id: b_def_id }, .. }),
425            ) if a_def_id == b_def_id || infcx.next_trait_solver() => {
426                super_combine_tys(&infcx.infcx, self, a, b).map(|_| ()).or_else(|err| {
427                    // This behavior is only there for the old solver, the new solver
428                    // shouldn't ever fail. Instead, it unconditionally emits an
429                    // alias-relate goal.
430                    assert!(!self.type_checker.infcx.next_trait_solver());
431                    self.cx().dcx().span_delayed_bug(
432                        self.span(),
433                        "failure to relate an opaque to itself should result in an error later on",
434                    );
435                    if a_def_id.is_local() { self.relate_opaques(a, b) } else { Err(err) }
436                })?;
437            }
438            (&ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }), _)
439            | (_, &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }))
440                if def_id.is_local() && !self.type_checker.infcx.next_trait_solver() =>
441            {
442                self.relate_opaques(a, b)?;
443            }
444
445            _ => {
446                debug!(?a, ?b, ?self.ambient_variance);
447
448                // Will also handle unification of `IntVar` and `FloatVar`.
449                super_combine_tys(&self.type_checker.infcx.infcx, self, a, b)?;
450            }
451        }
452
453        Ok(a)
454    }
455
456    {}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("regions",
                                    "rustc_borrowck::type_check::relate_tys",
                                    ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
                                    ::tracing_core::__macro_support::Option::Some(456u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("a")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("a");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("b")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("b");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&a)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&b)
                                                            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:
                    RelateResult<'tcx, ty::Region<'tcx>> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs:462",
                                    "rustc_borrowck::type_check::relate_tys",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
                                    ::tracing_core::__macro_support::Option::Some(462u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("self.ambient_variance")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("self.ambient_variance");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self.ambient_variance)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            if self.ambient_covariance() {
                self.push_outlives(a, b, self.ambient_variance_info);
            }
            if self.ambient_contravariance() {
                self.push_outlives(b, a, self.ambient_variance_info);
            }
            Ok(a)
        }
    }
}#[instrument(skip(self), level = "trace")]
457    fn regions(
458        &mut self,
459        a: ty::Region<'tcx>,
460        b: ty::Region<'tcx>,
461    ) -> RelateResult<'tcx, ty::Region<'tcx>> {
462        debug!(?self.ambient_variance);
463
464        if self.ambient_covariance() {
465            // Covariant: &'a u8 <: &'b u8. Hence, `'a: 'b`.
466            self.push_outlives(a, b, self.ambient_variance_info);
467        }
468
469        if self.ambient_contravariance() {
470            // Contravariant: &'b u8 <: &'a u8. Hence, `'b: 'a`.
471            self.push_outlives(b, a, self.ambient_variance_info);
472        }
473
474        Ok(a)
475    }
476
477    fn consts(
478        &mut self,
479        a: ty::Const<'tcx>,
480        b: ty::Const<'tcx>,
481    ) -> RelateResult<'tcx, ty::Const<'tcx>> {
482        let a = self.type_checker.infcx.shallow_resolve_const(a);
483        if !!a.has_non_region_infer() {
    {
        ::core::panicking::panic_fmt(format_args!("unexpected inference var {0:?}",
                a));
    }
};assert!(!a.has_non_region_infer(), "unexpected inference var {:?}", a);
484        if !!b.has_non_region_infer() {
    {
        ::core::panicking::panic_fmt(format_args!("unexpected inference var {0:?}",
                b));
    }
};assert!(!b.has_non_region_infer(), "unexpected inference var {:?}", b);
485
486        super_combine_consts(&self.type_checker.infcx.infcx, self, a, b)
487    }
488
489    {}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("binders",
                                    "rustc_borrowck::type_check::relate_tys",
                                    ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
                                    ::tracing_core::__macro_support::Option::Some(489u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("a")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("a");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("b")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("b");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&a)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&b)
                                                            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:
                    RelateResult<'tcx, ty::Binder<'tcx, 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/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs:517",
                                    "rustc_borrowck::type_check::relate_tys",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/3ef0c22cdb86ac42dc6b8f0f1ec36857daa6f2a1/compiler/rustc_borrowck/src/type_check/relate_tys.rs"),
                                    ::tracing_core::__macro_support::Option::Some(517u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check::relate_tys"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("self.ambient_variance")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("self.ambient_variance");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self.ambient_variance)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            if let (Some(a), Some(b)) = (a.no_bound_vars(), b.no_bound_vars())
                {
                self.relate(a, b)?;
                return Ok(ty::Binder::dummy(a));
            }
            match self.ambient_variance {
                ty::Covariant => {
                    self.enter_forall(b,
                            |this, b|
                                {
                                    let a = this.instantiate_binder_with_existentials(a);
                                    this.relate(a, b)
                                })?;
                }
                ty::Contravariant => {
                    self.enter_forall(a,
                            |this, a|
                                {
                                    let b = this.instantiate_binder_with_existentials(b);
                                    this.relate(a, b)
                                })?;
                }
                ty::Invariant => {
                    self.enter_forall(b,
                            |this, b|
                                {
                                    let a = this.instantiate_binder_with_existentials(a);
                                    this.relate(a, b)
                                })?;
                    self.enter_forall(a,
                            |this, a|
                                {
                                    let b = this.instantiate_binder_with_existentials(b);
                                    this.relate(a, b)
                                })?;
                }
                ty::Bivariant => {}
            }
            Ok(a)
        }
    }
}#[instrument(skip(self), level = "trace")]
490    fn binders<T>(
491        &mut self,
492        a: ty::Binder<'tcx, T>,
493        b: ty::Binder<'tcx, T>,
494    ) -> RelateResult<'tcx, ty::Binder<'tcx, T>>
495    where
496        T: Relate<TyCtxt<'tcx>>,
497    {
498        // We want that
499        //
500        // ```
501        // for<'a> fn(&'a u32) -> &'a u32 <:
502        //   fn(&'b u32) -> &'b u32
503        // ```
504        //
505        // but not
506        //
507        // ```
508        // fn(&'a u32) -> &'a u32 <:
509        //   for<'b> fn(&'b u32) -> &'b u32
510        // ```
511        //
512        // We therefore proceed as follows:
513        //
514        // - Instantiate binders on `b` universally, yielding a universe U1.
515        // - Instantiate binders on `a` existentially in U1.
516
517        debug!(?self.ambient_variance);
518
519        if let (Some(a), Some(b)) = (a.no_bound_vars(), b.no_bound_vars()) {
520            // Fast path for the common case.
521            self.relate(a, b)?;
522            return Ok(ty::Binder::dummy(a));
523        }
524
525        match self.ambient_variance {
526            ty::Covariant => {
527                // Covariance, so we want `for<..> A <: for<..> B` --
528                // therefore we compare any instantiation of A (i.e., A
529                // instantiated with existentials) against every
530                // instantiation of B (i.e., B instantiated with
531                // universals).
532
533                // Note: the order here is important. Create the placeholders first, otherwise
534                // we assign the wrong universe to the existential!
535                self.enter_forall(b, |this, b| {
536                    let a = this.instantiate_binder_with_existentials(a);
537                    this.relate(a, b)
538                })?;
539            }
540
541            ty::Contravariant => {
542                // Contravariance, so we want `for<..> A :> for<..> B` --
543                // therefore we compare every instantiation of A (i.e., A
544                // instantiated with universals) against any
545                // instantiation of B (i.e., B instantiated with
546                // existentials). Opposite of above.
547
548                // Note: the order here is important. Create the placeholders first, otherwise
549                // we assign the wrong universe to the existential!
550                self.enter_forall(a, |this, a| {
551                    let b = this.instantiate_binder_with_existentials(b);
552                    this.relate(a, b)
553                })?;
554            }
555
556            ty::Invariant => {
557                // Invariant, so we want `for<..> A == for<..> B` --
558                // therefore we want `exists<..> A == for<..> B` and
559                // `exists<..> B == for<..> A`.
560                //
561                // See the comment in `fn Equate::binders` for more details.
562
563                // Note: the order here is important. Create the placeholders first, otherwise
564                // we assign the wrong universe to the existential!
565                self.enter_forall(b, |this, b| {
566                    let a = this.instantiate_binder_with_existentials(a);
567                    this.relate(a, b)
568                })?;
569                // Note: the order here is important. Create the placeholders first, otherwise
570                // we assign the wrong universe to the existential!
571                self.enter_forall(a, |this, a| {
572                    let b = this.instantiate_binder_with_existentials(b);
573                    this.relate(a, b)
574                })?;
575            }
576
577            ty::Bivariant => {}
578        }
579
580        Ok(a)
581    }
582}
583
584impl<'b, 'tcx> PredicateEmittingRelation<InferCtxt<'tcx>> for NllTypeRelating<'_, 'b, 'tcx> {
585    fn span(&self) -> Span {
586        self.locations.span(self.type_checker.body)
587    }
588
589    fn param_env(&self) -> ty::ParamEnv<'tcx> {
590        self.type_checker.infcx.param_env
591    }
592
593    fn register_predicates(
594        &mut self,
595        obligations: impl IntoIterator<Item: ty::Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>>>,
596    ) {
597        let tcx = self.cx();
598        let param_env = self.param_env();
599        self.register_goals(
600            obligations.into_iter().map(|to_pred| Goal::new(tcx, param_env, to_pred)),
601        );
602    }
603
604    fn register_goals(
605        &mut self,
606        obligations: impl IntoIterator<Item = Goal<'tcx, ty::Predicate<'tcx>>>,
607    ) {
608        let _: Result<_, ErrorGuaranteed> = self.type_checker.fully_perform_op(
609            self.locations,
610            self.category,
611            InstantiateOpaqueType {
612                obligations: obligations
613                    .into_iter()
614                    .map(|goal| {
615                        Obligation::new(
616                            self.cx(),
617                            ObligationCause::dummy_with_span(self.span()),
618                            goal.param_env,
619                            goal.predicate,
620                        )
621                    })
622                    .collect(),
623                // These fields are filled in during execution of the operation
624                base_universe: None,
625                region_constraints: None,
626            },
627        );
628    }
629}