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