Skip to main content

rustc_borrowck/type_check/
mod.rs

1//! This pass type-checks the MIR to ensure it is not broken.
2
3use std::rc::Rc;
4use std::{fmt, iter, mem};
5
6use rustc_abi::FieldIdx;
7use rustc_data_structures::frozen::Frozen;
8use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
9use rustc_errors::ErrorGuaranteed;
10use rustc_hir as hir;
11use rustc_hir::attrs::lang_items::LangItem;
12use rustc_hir::def::DefKind;
13use rustc_hir::def_id::LocalDefId;
14use rustc_index::{IndexSlice, IndexVec};
15use rustc_infer::infer::canonical::QueryRegionConstraints;
16use rustc_infer::infer::outlives::env::RegionBoundPairs;
17use rustc_infer::infer::region_constraints::RegionConstraintData;
18use rustc_infer::infer::{
19    BoundRegionConversionTime, InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin,
20};
21use rustc_infer::traits::PredicateObligations;
22use rustc_middle::bug;
23use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor};
24use rustc_middle::mir::*;
25use rustc_middle::traits::query::NoSolution;
26use rustc_middle::ty::adjustment::PointerCoercion;
27use rustc_middle::ty::cast::CastTy;
28use rustc_middle::ty::{
29    self, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, GenericArgsRef, Ty, TyCtxt,
30    TypeVisitableExt, UserArgs, UserTypeAnnotationIndex, fold_regions,
31};
32use rustc_mir_dataflow::move_paths::MoveData;
33use rustc_mir_dataflow::points::DenseLocationMap;
34use rustc_span::def_id::CRATE_DEF_ID;
35use rustc_span::{Span, Spanned, sym};
36use rustc_trait_selection::infer::InferCtxtExt;
37use rustc_trait_selection::traits::query::type_op::custom::scrape_region_constraints;
38use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput};
39use tracing::{debug, instrument, trace};
40
41use crate::borrow_set::BorrowSet;
42use crate::constraints::{OutlivesConstraint, OutlivesConstraintSet};
43use crate::diagnostics::UniverseInfo;
44use crate::polonius::PoloniusContext;
45use crate::polonius::legacy::{PoloniusFacts, PoloniusLocationTable};
46use crate::region_infer::TypeTest;
47use crate::region_infer::values::{LivenessValues, PlaceholderIndex, PlaceholderIndices};
48use crate::session_diagnostics::{MoveUnsized, SimdIntrinsicArgConst};
49use crate::type_check::free_region_relations::{CreateResult, UniversalRegionRelations};
50use crate::universal_regions::{DefiningTy, UniversalRegions};
51use crate::{BorrowCheckRootCtxt, BorrowckInferCtxt, DeferredClosureRequirements, path_utils};
52
53macro_rules! span_mirbug {
54    ($context:expr, $elem:expr, $($message:tt)*) => ({
55        $crate::type_check::mirbug(
56            $context.tcx(),
57            $context.last_span,
58            format!(
59                "broken MIR in {:?} ({:?}): {}",
60                $context.body().source.def_id(),
61                $elem,
62                format_args!($($message)*),
63            ),
64        )
65    })
66}
67
68pub(crate) mod canonical;
69pub(crate) mod constraint_conversion;
70pub(crate) mod free_region_relations;
71mod input_output;
72pub(crate) mod liveness;
73mod relate_tys;
74
75/// Type checks the given `mir` in the context of the inference
76/// context `infcx`. Returns any region constraints that have yet to
77/// be proven. This result includes liveness constraints that
78/// ensure that regions appearing in the types of all local variables
79/// are live at all points where that local variable may later be
80/// used.
81///
82/// This phase of type-check ought to be infallible -- this is because
83/// the original, HIR-based type-check succeeded. So if any errors
84/// occur here, we will get a `bug!` reported.
85///
86/// # Parameters
87///
88/// - `infcx` -- inference context to use
89/// - `body` -- MIR body to type-check
90/// - `promoted` -- map of promoted constants within `body`
91/// - `universal_regions` -- the universal regions from `body`s function signature
92/// - `location_table` -- for datalog polonius, the map between `Location`s and `RichLocation`s
93/// - `borrow_set` -- information about borrows occurring in `body`
94/// - `polonius_facts` -- when using Polonius, this is the generated set of Polonius facts
95/// - `move_data` -- move-data constructed when performing the maybe-init dataflow analysis
96/// - `location_map` -- map between MIR `Location` and `PointIndex`
97pub(crate) fn type_check<'tcx>(
98    root_cx: &BorrowCheckRootCtxt<'_, 'tcx>,
99    infcx: &BorrowckInferCtxt<'tcx>,
100    body: &Body<'tcx>,
101    promoted: &IndexSlice<Promoted, Body<'tcx>>,
102    universal_regions: UniversalRegions<'tcx>,
103    location_table: &PoloniusLocationTable,
104    borrow_set: &BorrowSet<'tcx>,
105    polonius_facts: &mut Option<PoloniusFacts>,
106    move_data: &MoveData<'tcx>,
107    location_map: Rc<DenseLocationMap>,
108) -> MirTypeckResults<'tcx> {
109    let mut constraints = MirTypeckRegionConstraints {
110        placeholder_indices: PlaceholderIndices::default(),
111        placeholder_index_to_region: IndexVec::default(),
112        liveness_constraints: LivenessValues::with_specific_points(Rc::clone(&location_map)),
113        outlives_constraints: OutlivesConstraintSet::default(),
114        type_tests: Vec::default(),
115        universe_causes: FxIndexMap::default(),
116    };
117
118    let CreateResult {
119        universal_region_relations,
120        region_bound_pairs,
121        normalized_inputs_and_output,
122        known_type_outlives_obligations,
123    } = free_region_relations::create(infcx, universal_regions, &mut constraints);
124
125    {
126        // Scope these variables so it's clear they're not used later
127        let pre_obligations = infcx.take_registered_region_obligations();
128        if !pre_obligations.is_empty() {
    {
        ::core::panicking::panic_fmt(format_args!("there should be no incoming region obligations = {0:#?}",
                pre_obligations));
    }
};assert!(
129            pre_obligations.is_empty(),
130            "there should be no incoming region obligations = {pre_obligations:#?}",
131        );
132        let pre_assumptions = infcx.take_registered_region_assumptions();
133        if !pre_assumptions.is_empty() {
    {
        ::core::panicking::panic_fmt(format_args!("there should be no incoming region assumptions = {0:#?}",
                pre_assumptions));
    }
};assert!(
134            pre_assumptions.is_empty(),
135            "there should be no incoming region assumptions = {pre_assumptions:#?}",
136        );
137    }
138
139    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/mod.rs:139",
                        "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(139u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("normalized_inputs_and_output")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("normalized_inputs_and_output");
                                            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(&normalized_inputs_and_output)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?normalized_inputs_and_output);
140
141    let polonius_context = if infcx.tcx.sess.opts.unstable_opts.polonius.is_next_enabled() {
142        Some(PoloniusContext::default())
143    } else {
144        None
145    };
146
147    let mut deferred_closure_requirements = Default::default();
148    let mut typeck = TypeChecker {
149        root_cx,
150        infcx,
151        last_span: body.span,
152        body,
153        promoted,
154        user_type_annotations: &body.user_type_annotations,
155        region_bound_pairs: &region_bound_pairs,
156        known_type_outlives_obligations: &known_type_outlives_obligations,
157        reported_errors: Default::default(),
158        universal_regions: &universal_region_relations.universal_regions,
159        location_table,
160        polonius_facts,
161        borrow_set,
162        constraints: &mut constraints,
163        deferred_closure_requirements: &mut deferred_closure_requirements,
164        polonius_context,
165    };
166
167    typeck.check_user_type_annotations();
168    typeck.visit_body(body);
169    typeck.equate_inputs_and_outputs(&normalized_inputs_and_output);
170    typeck.check_signature_annotation();
171
172    liveness::generate(&mut typeck, &location_map, move_data);
173
174    let polonius_context = typeck.polonius_context;
175
176    if infcx.tcx.assumptions_on_binders() {
177        let mut converter = constraint_conversion::ConstraintConversion::new(
178            typeck.infcx,
179            typeck.universal_regions,
180            typeck.region_bound_pairs,
181            typeck.known_type_outlives_obligations,
182            Locations::All(rustc_span::DUMMY_SP),
183            rustc_span::DUMMY_SP,
184            ConstraintCategory::Boring,
185            typeck.constraints,
186        );
187        typeck.infcx.destructure_solver_region_constraints_for_borrowck(
188            &mut converter,
189            typeck.known_type_outlives_obligations,
190            universal_region_relations.outlives.clone(),
191            infcx.tcx.def_span(infcx.root_def_id),
192        );
193    }
194
195    // In case type check encountered an error region, we suppress unhelpful extra
196    // errors in by clearing out all outlives bounds that we may end up checking.
197    if let Some(guar) = universal_region_relations.universal_regions.encountered_re_error() {
198        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/mod.rs:198",
                        "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(198u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("encountered an error region; removing constraints!")
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("encountered an error region; removing constraints!");
199        constraints.outlives_constraints = Default::default();
200        constraints.type_tests = Default::default();
201        infcx.set_tainted_by_errors(guar);
202    }
203
204    MirTypeckResults {
205        constraints,
206        universal_region_relations,
207        region_bound_pairs,
208        known_type_outlives_obligations,
209        deferred_closure_requirements,
210        polonius_context,
211    }
212}
213
214#[track_caller]
215fn mirbug(tcx: TyCtxt<'_>, span: Span, msg: String) {
216    // We sometimes see MIR failures (notably predicate failures) due to
217    // the fact that we check rvalue sized predicates here. So use `span_delayed_bug`
218    // to avoid reporting bugs in those cases.
219    tcx.dcx().span_delayed_bug(span, msg);
220}
221
222enum FieldAccessError {
223    OutOfRange { field_count: usize },
224}
225
226/// The MIR type checker. Visits the MIR and enforces all the
227/// constraints needed for it to be valid and well-typed. Along the
228/// way, it accrues region constraints -- these can later be used by
229/// NLL region checking.
230struct TypeChecker<'a, 'tcx> {
231    root_cx: &'a BorrowCheckRootCtxt<'a, 'tcx>,
232    infcx: &'a BorrowckInferCtxt<'tcx>,
233    last_span: Span,
234    body: &'a Body<'tcx>,
235    /// The bodies of all promoteds. As promoteds have a completely separate CFG
236    /// recursing into them may corrupt your data structures if you're not careful.
237    promoted: &'a IndexSlice<Promoted, Body<'tcx>>,
238    /// User type annotations are shared between the main MIR and the MIR of
239    /// all of the promoted items.
240    user_type_annotations: &'a CanonicalUserTypeAnnotations<'tcx>,
241    region_bound_pairs: &'a RegionBoundPairs<'tcx>,
242    known_type_outlives_obligations: &'a [ty::PolyTypeOutlivesClause<'tcx>],
243    reported_errors: FxIndexSet<(Ty<'tcx>, Span)>,
244    universal_regions: &'a UniversalRegions<'tcx>,
245    location_table: &'a PoloniusLocationTable,
246    polonius_facts: &'a mut Option<PoloniusFacts>,
247    borrow_set: &'a BorrowSet<'tcx>,
248    constraints: &'a mut MirTypeckRegionConstraints<'tcx>,
249    deferred_closure_requirements: &'a mut DeferredClosureRequirements<'tcx>,
250    /// When using `-Zpolonius=next`, the liveness helper data used to create polonius constraints.
251    polonius_context: Option<PoloniusContext>,
252}
253
254/// Holder struct for passing results from MIR typeck to the rest of the non-lexical regions
255/// inference computation.
256pub(crate) struct MirTypeckResults<'tcx> {
257    pub(crate) constraints: MirTypeckRegionConstraints<'tcx>,
258    pub(crate) universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
259    pub(crate) region_bound_pairs: Frozen<RegionBoundPairs<'tcx>>,
260    pub(crate) known_type_outlives_obligations: Frozen<Vec<ty::PolyTypeOutlivesClause<'tcx>>>,
261    pub(crate) deferred_closure_requirements: DeferredClosureRequirements<'tcx>,
262    pub(crate) polonius_context: Option<PoloniusContext>,
263}
264
265/// A collection of region constraints that must be satisfied for the
266/// program to be considered well-typed.
267#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for MirTypeckRegionConstraints<'tcx> {
    #[inline]
    fn clone(&self) -> MirTypeckRegionConstraints<'tcx> {
        MirTypeckRegionConstraints {
            placeholder_indices: ::core::clone::Clone::clone(&self.placeholder_indices),
            placeholder_index_to_region: ::core::clone::Clone::clone(&self.placeholder_index_to_region),
            liveness_constraints: ::core::clone::Clone::clone(&self.liveness_constraints),
            outlives_constraints: ::core::clone::Clone::clone(&self.outlives_constraints),
            universe_causes: ::core::clone::Clone::clone(&self.universe_causes),
            type_tests: ::core::clone::Clone::clone(&self.type_tests),
        }
    }
}Clone)] // FIXME(#146079)
268pub(crate) struct MirTypeckRegionConstraints<'tcx> {
269    /// Maps from a `ty::Placeholder` to the corresponding
270    /// `PlaceholderIndex` bit that we will use for it.
271    ///
272    /// To keep everything in sync, do not insert this set
273    /// directly. Instead, use the `placeholder_region` helper.
274    pub(crate) placeholder_indices: PlaceholderIndices<'tcx>,
275
276    /// Each time we add a placeholder to `placeholder_indices`, we
277    /// also create a corresponding "representative" region vid for
278    /// that wraps it. This vector tracks those. This way, when we
279    /// convert the same `ty::RePlaceholder(p)` twice, we can map to
280    /// the same underlying `RegionVid`.
281    pub(crate) placeholder_index_to_region: IndexVec<PlaceholderIndex, ty::Region<'tcx>>,
282
283    /// In general, the type-checker is not responsible for enforcing
284    /// liveness constraints; this job falls to the region inferencer,
285    /// which performs a liveness analysis. However, in some limited
286    /// cases, the MIR type-checker creates temporary regions that do
287    /// not otherwise appear in the MIR -- in particular, the
288    /// late-bound regions that it instantiates at call-sites -- and
289    /// hence it must report on their liveness constraints.
290    pub(crate) liveness_constraints: LivenessValues,
291
292    pub(crate) outlives_constraints: OutlivesConstraintSet<'tcx>,
293
294    pub(crate) universe_causes: FxIndexMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
295
296    pub(crate) type_tests: Vec<TypeTest<'tcx>>,
297}
298
299impl<'tcx> MirTypeckRegionConstraints<'tcx> {
300    /// Creates a `Region` for a given `PlaceholderRegion`, or returns the
301    /// region that corresponds to a previously created one.
302    pub(crate) fn placeholder_region(
303        &mut self,
304        infcx: &InferCtxt<'tcx>,
305        placeholder: ty::PlaceholderRegion<'tcx>,
306    ) -> ty::Region<'tcx> {
307        let placeholder_index = self.placeholder_indices.insert(placeholder);
308        match self.placeholder_index_to_region.get(placeholder_index) {
309            Some(&v) => v,
310            None => {
311                let origin = NllRegionVariableOrigin::Placeholder(placeholder);
312                let region = infcx.next_nll_region_var_in_universe(origin, placeholder.universe);
313                self.placeholder_index_to_region.push(region);
314                region
315            }
316        }
317    }
318}
319
320/// The `Locations` type summarizes *where* region constraints are
321/// required to hold. Normally, this is at a particular point which
322/// created the obligation, but for constraints that the user gave, we
323/// want the constraint to hold at all points.
324#[derive(#[automatically_derived]
impl ::core::marker::Copy for Locations { }Copy, #[automatically_derived]
impl ::core::clone::Clone for Locations {
    #[inline]
    fn clone(&self) -> Locations {
        let _: ::core::clone::AssertParamIsClone<Span>;
        let _: ::core::clone::AssertParamIsClone<Location>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for Locations {
    #[inline]
    fn eq(&self, other: &Locations) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (Locations::All(__self_0), Locations::All(__arg1_0)) =>
                    __self_0 == __arg1_0,
                (Locations::Single(__self_0), Locations::Single(__arg1_0)) =>
                    __self_0 == __arg1_0,
                _ => unsafe { ::core::intrinsics::unreachable() }
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Locations {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<Span>;
        let _: ::core::cmp::AssertParamIsEq<Location>;
    }
}Eq, #[automatically_derived]
impl ::core::cmp::PartialOrd for Locations {
    #[inline]
    fn partial_cmp(&self, other: &Locations)
        -> ::core::option::Option<::core::cmp::Ordering> {
        ::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
    }
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for Locations {
    #[inline]
    fn cmp(&self, other: &Locations) -> ::core::cmp::Ordering {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        match ::core::cmp::Ord::cmp(&__self_discr, &__arg1_discr) {
            ::core::cmp::Ordering::Equal =>
                match (self, other) {
                    (Locations::All(__self_0), Locations::All(__arg1_0)) =>
                        ::core::cmp::Ord::cmp(__self_0, __arg1_0),
                    (Locations::Single(__self_0), Locations::Single(__arg1_0))
                        => ::core::cmp::Ord::cmp(__self_0, __arg1_0),
                    _ => unsafe { ::core::intrinsics::unreachable() }
                },
            cmp => cmp,
        }
    }
}Ord, #[automatically_derived]
impl ::core::hash::Hash for Locations {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state);
        match self {
            Locations::All(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            Locations::Single(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
        }
    }
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for Locations {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Locations::All(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "All",
                    &__self_0),
            Locations::Single(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Single",
                    &__self_0),
        }
    }
}Debug)]
325pub enum Locations {
326    /// Indicates that a type constraint should always be true. This
327    /// is particularly important in the new borrowck analysis for
328    /// things like the type of the return slot. Consider this
329    /// example:
330    ///
331    /// ```compile_fail,E0515
332    /// fn foo<'a>(x: &'a u32) -> &'a u32 {
333    ///     let y = 22;
334    ///     return &y; // error
335    /// }
336    /// ```
337    ///
338    /// Here, we wind up with the signature from the return type being
339    /// something like `&'1 u32` where `'1` is a universal region. But
340    /// the type of the return slot `_0` is something like `&'2 u32`
341    /// where `'2` is an existential region variable. The type checker
342    /// requires that `&'2 u32 = &'1 u32` -- but at what point? In the
343    /// older NLL analysis, we required this only at the entry point
344    /// to the function. By the nature of the constraints, this wound
345    /// up propagating to all points reachable from start (because
346    /// `'1` -- as a universal region -- is live everywhere). In the
347    /// newer analysis, though, this doesn't work: `_0` is considered
348    /// dead at the start (it has no usable value) and hence this type
349    /// equality is basically a no-op. Then, later on, when we do `_0
350    /// = &'3 y`, that region `'3` never winds up related to the
351    /// universal region `'1` and hence no error occurs. Therefore, we
352    /// use Locations::All instead, which ensures that the `'1` and
353    /// `'2` are equal everything. We also use this for other
354    /// user-given type annotations; e.g., if the user wrote `let mut
355    /// x: &'static u32 = ...`, we would ensure that all values
356    /// assigned to `x` are of `'static` lifetime.
357    ///
358    /// The span points to the place the constraint arose. For example,
359    /// it points to the type in a user-given type annotation. If
360    /// there's no sensible span then it's DUMMY_SP.
361    All(Span),
362
363    /// An outlives constraint that only has to hold at a single location,
364    /// usually it represents a point where references flow from one spot to
365    /// another (e.g., `x = y`)
366    Single(Location),
367}
368
369impl Locations {
370    pub fn from_location(&self) -> Option<Location> {
371        match self {
372            Locations::All(_) => None,
373            Locations::Single(from_location) => Some(*from_location),
374        }
375    }
376
377    /// Gets a span representing the location.
378    pub fn span(&self, body: &Body<'_>) -> Span {
379        match self {
380            Locations::All(span) => *span,
381            Locations::Single(l) => body.source_info(*l).span,
382        }
383    }
384}
385
386impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
387    fn tcx(&self) -> TyCtxt<'tcx> {
388        self.infcx.tcx
389    }
390
391    fn body(&self) -> &Body<'tcx> {
392        self.body
393    }
394
395    /// Equate the inferred type and the annotated type for user type annotations
396    #[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("check_user_type_annotations",
                                    "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(396u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                    ::tracing_core::field::FieldSet::new(&[],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{ meta.fields().value_set_all(&[]) })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = 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 compiler/rustc_borrowck/src/type_check/mod.rs:398",
                                    "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(398u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("self.user_type_annotations")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("self.user_type_annotations");
                                                        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.user_type_annotations)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            for user_annotation in self.user_type_annotations {
                let CanonicalUserTypeAnnotation {
                        span, ref user_ty, inferred_ty } = *user_annotation;
                let annotation = self.instantiate_canonical(span, user_ty);
                self.ascribe_user_type(inferred_ty, annotation, span);
            }
        }
    }
}#[instrument(skip(self), level = "debug")]
397    fn check_user_type_annotations(&mut self) {
398        debug!(?self.user_type_annotations);
399        for user_annotation in self.user_type_annotations {
400            let CanonicalUserTypeAnnotation { span, ref user_ty, inferred_ty } = *user_annotation;
401            let annotation = self.instantiate_canonical(span, user_ty);
402            self.ascribe_user_type(inferred_ty, annotation, span);
403        }
404    }
405
406    #[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("push_region_constraints",
                                    "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(406u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        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(&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: () = 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 compiler/rustc_borrowck/src/type_check/mod.rs:413",
                                    "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(413u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                    ::tracing_core::field::FieldSet::new(&["message"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("constraints generated: {0:#?}",
                                                                data) as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            constraint_conversion::ConstraintConversion::new(self.infcx,
                    self.universal_regions, self.region_bound_pairs,
                    self.known_type_outlives_obligations, locations,
                    locations.span(self.body), category,
                    self.constraints).convert_all(data);
        }
    }
}#[instrument(skip(self, data), level = "debug")]
407    fn push_region_constraints(
408        &mut self,
409        locations: Locations,
410        category: ConstraintCategory<'tcx>,
411        data: &QueryRegionConstraints<'tcx>,
412    ) {
413        debug!("constraints generated: {:#?}", data);
414
415        constraint_conversion::ConstraintConversion::new(
416            self.infcx,
417            self.universal_regions,
418            self.region_bound_pairs,
419            self.known_type_outlives_obligations,
420            locations,
421            locations.span(self.body),
422            category,
423            self.constraints,
424        )
425        .convert_all(data);
426    }
427
428    /// Try to relate `sub <: sup`
429    fn sub_types(
430        &mut self,
431        sub: Ty<'tcx>,
432        sup: Ty<'tcx>,
433        locations: Locations,
434        category: ConstraintCategory<'tcx>,
435    ) -> Result<(), NoSolution> {
436        // Use this order of parameters because the sup type is usually the
437        // "expected" type in diagnostics.
438        self.relate_types(sup, ty::Contravariant, sub, locations, category)
439    }
440
441    #[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("eq_types",
                                    "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(441u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("expected")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("expected");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("found")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("found");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("locations")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("locations");
                                                        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(&expected)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&found)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&locations)
                                                            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;
        }
        {
            self.relate_types(expected, ty::Invariant, found, locations,
                category)
        }
    }
}#[instrument(skip(self, category), level = "debug")]
442    fn eq_types(
443        &mut self,
444        expected: Ty<'tcx>,
445        found: Ty<'tcx>,
446        locations: Locations,
447        category: ConstraintCategory<'tcx>,
448    ) -> Result<(), NoSolution> {
449        self.relate_types(expected, ty::Invariant, found, locations, category)
450    }
451
452    #[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_type_and_user_type",
                                    "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(452u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                    ::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("user_ty")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("user_ty");
                                                        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(&user_ty)
                                                            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;
        }
        {
            let annotated_type =
                self.user_type_annotations[user_ty.base].inferred_ty;
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/mod.rs:462",
                                    "rustc_borrowck::type_check", ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(462u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("annotated_type")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("annotated_type");
                                                        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(&annotated_type)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            let mut curr_projected_ty = PlaceTy::from_ty(annotated_type);
            let tcx = self.infcx.tcx;
            for proj in &user_ty.projs {
                if !self.infcx.next_trait_solver() &&
                        let ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, ..
                            }) = curr_projected_ty.ty.kind() {
                    return Ok(());
                }
                let projected_ty =
                    curr_projected_ty.projection_ty_core(tcx, proj,
                        |ty, variant_index, field_index, ()|
                            {
                                self.normalize(PlaceTy::field_ty(tcx, ty, variant_index,
                                        field_index), locations)
                            },
                        |_|
                            ::core::panicking::panic("internal error: entered unreachable code"));
                curr_projected_ty = projected_ty;
            }
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/mod.rs:492",
                                    "rustc_borrowck::type_check", ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(492u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("curr_projected_ty")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("curr_projected_ty");
                                                        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(&curr_projected_ty)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            let mut a = a;
            let mut ty = curr_projected_ty.ty;
            if !self.infcx.next_trait_solver() {
                a = self.normalize(ty::Unnormalized::new_wip(a), locations);
                ty = self.normalize(ty::Unnormalized::new_wip(ty), locations);
            }
            self.relate_types(ty, v.xform(ty::Contravariant), a, locations,
                    category)?;
            Ok(())
        }
    }
}#[instrument(skip(self), level = "debug")]
453    fn relate_type_and_user_type(
454        &mut self,
455        a: Ty<'tcx>,
456        v: ty::Variance,
457        user_ty: &UserTypeProjection,
458        locations: Locations,
459        category: ConstraintCategory<'tcx>,
460    ) -> Result<(), NoSolution> {
461        let annotated_type = self.user_type_annotations[user_ty.base].inferred_ty;
462        trace!(?annotated_type);
463        let mut curr_projected_ty = PlaceTy::from_ty(annotated_type);
464
465        let tcx = self.infcx.tcx;
466
467        for proj in &user_ty.projs {
468            // Necessary for non-trivial patterns whose user-type annotation is an opaque type,
469            // e.g. `let (_a,): Tait = whatever`, see #105897
470            if !self.infcx.next_trait_solver()
471                && let ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }) =
472                    curr_projected_ty.ty.kind()
473            {
474                // There is nothing that we can compare here if we go through an opaque type.
475                // We're always in its defining scope as we can otherwise not project through
476                // it, so we're constraining it anyways.
477                return Ok(());
478            }
479            let projected_ty = curr_projected_ty.projection_ty_core(
480                tcx,
481                proj,
482                |ty, variant_index, field_index, ()| {
483                    self.normalize(
484                        PlaceTy::field_ty(tcx, ty, variant_index, field_index),
485                        locations,
486                    )
487                },
488                |_| unreachable!(),
489            );
490            curr_projected_ty = projected_ty;
491        }
492        trace!(?curr_projected_ty);
493
494        // Need to renormalize `a` in the old solver as typecheck may have failed
495        // to normalize higher-ranked aliases if normalization was ambiguous due
496        // to inference.
497        //
498        // We properly normalize higher-ranked aliases during writeback with the
499        // new solver, so this is no longer necessary.
500        let mut a = a;
501        let mut ty = curr_projected_ty.ty;
502        if !self.infcx.next_trait_solver() {
503            a = self.normalize(ty::Unnormalized::new_wip(a), locations);
504            ty = self.normalize(ty::Unnormalized::new_wip(ty), locations);
505        }
506        self.relate_types(ty, v.xform(ty::Contravariant), a, locations, category)?;
507
508        Ok(())
509    }
510
511    fn check_promoted(&mut self, promoted_body: &'a Body<'tcx>, location: Location) {
512        // Determine the constraints from the promoted MIR by running the type
513        // checker on the promoted MIR, then transfer the constraints back to
514        // the main MIR, changing the locations to the provided location.
515
516        let parent_body = mem::replace(&mut self.body, promoted_body);
517
518        // Use new sets of constraints and closure bounds so that we can
519        // modify their locations.
520        let polonius_facts = &mut None;
521        let mut constraints = Default::default();
522        let mut liveness_constraints =
523            LivenessValues::without_specific_points(Rc::new(DenseLocationMap::new(promoted_body)));
524        let mut deferred_closure_requirements = Default::default();
525
526        // Don't try to add borrow_region facts for the promoted MIR as they refer
527        // to the wrong locations.
528        let mut swap_constraints = |this: &mut Self| {
529            mem::swap(this.polonius_facts, polonius_facts);
530            mem::swap(&mut this.constraints.outlives_constraints, &mut constraints);
531            mem::swap(&mut this.constraints.liveness_constraints, &mut liveness_constraints);
532            mem::swap(this.deferred_closure_requirements, &mut deferred_closure_requirements);
533        };
534
535        swap_constraints(self);
536
537        self.visit_body(promoted_body);
538
539        self.body = parent_body;
540
541        // Merge the outlives constraints back in, at the given location.
542        swap_constraints(self);
543        let locations = location.to_locations();
544        for constraint in constraints.outlives().iter() {
545            let mut constraint = *constraint;
546            constraint.locations = locations;
547            if let ConstraintCategory::Return(_)
548            | ConstraintCategory::UseAsConst
549            | ConstraintCategory::UseAsStatic = constraint.category
550            {
551                // "Returning" from a promoted is an assignment to a
552                // temporary from the user's point of view.
553                constraint.category = ConstraintCategory::Boring;
554            }
555            self.constraints.outlives_constraints.push(constraint)
556        }
557
558        // If there are nested bodies in promoteds, we also need to update their
559        // location to something in the actual body, not the promoted.
560        //
561        // We don't update the constraint categories of the resulting constraints
562        // as returns in nested bodies are a proper return, even if that nested body
563        // is in a promoted.
564        for (closure_def_id, args, _locations) in deferred_closure_requirements {
565            self.deferred_closure_requirements.push((closure_def_id, args, locations));
566        }
567
568        // If the region is live at least one location in the promoted MIR,
569        // then add a liveness constraint to the main MIR for this region
570        // at the location provided as an argument to this method
571        //
572        // add_location doesn't care about ordering so not a problem for the live regions to be
573        // unordered.
574        #[allow(rustc::potential_query_instability)]
575        for region in liveness_constraints.live_regions_unordered() {
576            self.constraints.liveness_constraints.add_location(region, location);
577        }
578    }
579}
580
581impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
582    fn visit_span(&mut self, span: Span) {
583        if !span.is_dummy() {
584            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/mod.rs:584",
                        "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(584u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("span")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("span");
                                            NAME.as_str()
                                        }], ::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(&span)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?span);
585            self.last_span = span;
586        }
587    }
588
589    #[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("visit_body",
                                    "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(589u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                    ::tracing_core::field::FieldSet::new(&[],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{ meta.fields().value_set_all(&[]) })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            if true {
                if !std::ptr::eq(self.body, body) {
                    ::core::panicking::panic("assertion failed: std::ptr::eq(self.body, body)")
                };
            };
            for (local, local_decl) in body.local_decls.iter_enumerated() {
                self.visit_local_decl(local, local_decl);
            }
            for (block, block_data) in body.basic_blocks.iter_enumerated() {
                let mut location = Location { block, statement_index: 0 };
                for stmt in &block_data.statements {
                    self.visit_statement(stmt, location);
                    location.statement_index += 1;
                }
                self.visit_terminator(block_data.terminator(), location);
                self.check_iscleanup(block_data);
            }
        }
    }
}#[instrument(skip(self, body), level = "debug")]
590    fn visit_body(&mut self, body: &Body<'tcx>) {
591        debug_assert!(std::ptr::eq(self.body, body));
592
593        for (local, local_decl) in body.local_decls.iter_enumerated() {
594            self.visit_local_decl(local, local_decl);
595        }
596
597        for (block, block_data) in body.basic_blocks.iter_enumerated() {
598            let mut location = Location { block, statement_index: 0 };
599            for stmt in &block_data.statements {
600                self.visit_statement(stmt, location);
601                location.statement_index += 1;
602            }
603
604            self.visit_terminator(block_data.terminator(), location);
605            self.check_iscleanup(block_data);
606        }
607    }
608
609    #[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("visit_statement",
                                    "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(609u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("stmt")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("stmt");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("location")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("location");
                                                        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(&stmt)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&location)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            self.super_statement(stmt, location);
            let tcx = self.tcx();
            match &stmt.kind {
                StatementKind::Assign((place, rv)) => {
                    let category =
                        match place.as_local() {
                            Some(RETURN_PLACE) => {
                                let defining_ty = &self.universal_regions.defining_ty;
                                if defining_ty.is_const() {
                                    if tcx.is_static(defining_ty.def_id()) {
                                        ConstraintCategory::UseAsStatic
                                    } else { ConstraintCategory::UseAsConst }
                                } else {
                                    ConstraintCategory::Return(ReturnConstraint::Normal)
                                }
                            }
                            Some(l) if
                                #[allow(non_exhaustive_omitted_patterns)] match self.body.local_decls[l].local_info()
                                    {
                                    LocalInfo::AggregateTemp => true,
                                    _ => false,
                                } => {
                                ConstraintCategory::Usage
                            }
                            Some(l) if !self.body.local_decls[l].is_user_variable() => {
                                ConstraintCategory::Boring
                            }
                            _ => ConstraintCategory::Assignment,
                        };
                    {
                        use ::tracing::__macro_support::Callsite as _;
                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                            {
                                static META: ::tracing::Metadata<'static> =
                                    {
                                        ::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/mod.rs:645",
                                            "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                                            ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                            ::tracing_core::__macro_support::Option::Some(645u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                            ::tracing_core::field::FieldSet::new(&["message"],
                                                ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                            ::tracing::metadata::Kind::EVENT)
                                    };
                                ::tracing::callsite::DefaultCallsite::new(&META)
                            };
                        let enabled =
                            ::tracing::Level::DEBUG <=
                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                    ::tracing::Level::DEBUG <=
                                        ::tracing::level_filters::LevelFilter::current() &&
                                {
                                    let interest = __CALLSITE.interest();
                                    !interest.is_never() &&
                                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                            interest)
                                };
                        if enabled {
                            (|value_set: ::tracing::field::ValueSet|
                                        {
                                            let meta = __CALLSITE.metadata();
                                            ::tracing::Event::dispatch(meta, &value_set);
                                            ;
                                        })({
                                    #[allow(unused_imports)]
                                    use ::tracing::field::{debug, display, Value};
                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("assignment category: {0:?} {1:?}",
                                                                        category,
                                                                        place.as_local().map(|l| &self.body.local_decls[l])) as
                                                                &dyn ::tracing::field::Value))])
                                });
                        } else { ; }
                    };
                    let place_ty = place.ty(self.body, tcx).ty;
                    {
                        use ::tracing::__macro_support::Callsite as _;
                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                            {
                                static META: ::tracing::Metadata<'static> =
                                    {
                                        ::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/mod.rs:652",
                                            "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                                            ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                            ::tracing_core::__macro_support::Option::Some(652u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                            ::tracing_core::field::FieldSet::new(&[{
                                                                const NAME:
                                                                    ::tracing::__macro_support::FieldName<{
                                                                        ::tracing::__macro_support::FieldName::len("place_ty")
                                                                    }> =
                                                                    ::tracing::__macro_support::FieldName::new("place_ty");
                                                                NAME.as_str()
                                                            }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                            ::tracing::metadata::Kind::EVENT)
                                    };
                                ::tracing::callsite::DefaultCallsite::new(&META)
                            };
                        let enabled =
                            ::tracing::Level::DEBUG <=
                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                    ::tracing::Level::DEBUG <=
                                        ::tracing::level_filters::LevelFilter::current() &&
                                {
                                    let interest = __CALLSITE.interest();
                                    !interest.is_never() &&
                                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                            interest)
                                };
                        if enabled {
                            (|value_set: ::tracing::field::ValueSet|
                                        {
                                            let meta = __CALLSITE.metadata();
                                            ::tracing::Event::dispatch(meta, &value_set);
                                            ;
                                        })({
                                    #[allow(unused_imports)]
                                    use ::tracing::field::{debug, display, Value};
                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&place_ty)
                                                                as &dyn ::tracing::field::Value))])
                                });
                        } else { ; }
                    };
                    let place_ty =
                        self.normalize(ty::Unnormalized::new_wip(place_ty),
                            location);
                    {
                        use ::tracing::__macro_support::Callsite as _;
                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                            {
                                static META: ::tracing::Metadata<'static> =
                                    {
                                        ::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/mod.rs:654",
                                            "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                                            ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                            ::tracing_core::__macro_support::Option::Some(654u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                            ::tracing_core::field::FieldSet::new(&["message"],
                                                ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                            ::tracing::metadata::Kind::EVENT)
                                    };
                                ::tracing::callsite::DefaultCallsite::new(&META)
                            };
                        let enabled =
                            ::tracing::Level::DEBUG <=
                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                    ::tracing::Level::DEBUG <=
                                        ::tracing::level_filters::LevelFilter::current() &&
                                {
                                    let interest = __CALLSITE.interest();
                                    !interest.is_never() &&
                                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                            interest)
                                };
                        if enabled {
                            (|value_set: ::tracing::field::ValueSet|
                                        {
                                            let meta = __CALLSITE.metadata();
                                            ::tracing::Event::dispatch(meta, &value_set);
                                            ;
                                        })({
                                    #[allow(unused_imports)]
                                    use ::tracing::field::{debug, display, Value};
                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("place_ty normalized: {0:?}",
                                                                        place_ty) as &dyn ::tracing::field::Value))])
                                });
                        } else { ; }
                    };
                    let rv_ty = rv.ty(self.body, tcx);
                    {
                        use ::tracing::__macro_support::Callsite as _;
                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                            {
                                static META: ::tracing::Metadata<'static> =
                                    {
                                        ::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/mod.rs:656",
                                            "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                                            ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                            ::tracing_core::__macro_support::Option::Some(656u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                            ::tracing_core::field::FieldSet::new(&[{
                                                                const NAME:
                                                                    ::tracing::__macro_support::FieldName<{
                                                                        ::tracing::__macro_support::FieldName::len("rv_ty")
                                                                    }> =
                                                                    ::tracing::__macro_support::FieldName::new("rv_ty");
                                                                NAME.as_str()
                                                            }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                            ::tracing::metadata::Kind::EVENT)
                                    };
                                ::tracing::callsite::DefaultCallsite::new(&META)
                            };
                        let enabled =
                            ::tracing::Level::DEBUG <=
                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                    ::tracing::Level::DEBUG <=
                                        ::tracing::level_filters::LevelFilter::current() &&
                                {
                                    let interest = __CALLSITE.interest();
                                    !interest.is_never() &&
                                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                            interest)
                                };
                        if enabled {
                            (|value_set: ::tracing::field::ValueSet|
                                        {
                                            let meta = __CALLSITE.metadata();
                                            ::tracing::Event::dispatch(meta, &value_set);
                                            ;
                                        })({
                                    #[allow(unused_imports)]
                                    use ::tracing::field::{debug, display, Value};
                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&rv_ty)
                                                                as &dyn ::tracing::field::Value))])
                                });
                        } else { ; }
                    };
                    let rv_ty =
                        self.normalize(ty::Unnormalized::new_wip(rv_ty), location);
                    {
                        use ::tracing::__macro_support::Callsite as _;
                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                            {
                                static META: ::tracing::Metadata<'static> =
                                    {
                                        ::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/mod.rs:658",
                                            "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                                            ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                            ::tracing_core::__macro_support::Option::Some(658u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                            ::tracing_core::field::FieldSet::new(&["message"],
                                                ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                            ::tracing::metadata::Kind::EVENT)
                                    };
                                ::tracing::callsite::DefaultCallsite::new(&META)
                            };
                        let enabled =
                            ::tracing::Level::DEBUG <=
                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                    ::tracing::Level::DEBUG <=
                                        ::tracing::level_filters::LevelFilter::current() &&
                                {
                                    let interest = __CALLSITE.interest();
                                    !interest.is_never() &&
                                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                            interest)
                                };
                        if enabled {
                            (|value_set: ::tracing::field::ValueSet|
                                        {
                                            let meta = __CALLSITE.metadata();
                                            ::tracing::Event::dispatch(meta, &value_set);
                                            ;
                                        })({
                                    #[allow(unused_imports)]
                                    use ::tracing::field::{debug, display, Value};
                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("normalized rv_ty: {0:?}",
                                                                        rv_ty) as &dyn ::tracing::field::Value))])
                                });
                        } else { ; }
                    };
                    if let Err(terr) =
                            self.sub_types(rv_ty, place_ty, location.to_locations(),
                                category) {
                        {
                            crate::type_check::mirbug(self.tcx(), self.last_span,
                                ::alloc::__export::must_use({
                                        ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                self.body().source.def_id(), stmt,
                                                format_args!("bad assignment ({0:?} = {1:?}): {2:?}",
                                                    place_ty, rv_ty, terr)))
                                    }))
                        };
                    }
                    if let Some(annotation_index) = self.rvalue_user_ty(rv) &&
                            let Err(terr) =
                                self.relate_type_and_user_type(rv_ty, ty::Invariant,
                                    &UserTypeProjection {
                                            base: annotation_index,
                                            projs: ::alloc::vec::Vec::new(),
                                        }, location.to_locations(),
                                    ConstraintCategory::TypeAnnotation(AnnotationSource::GenericArg))
                        {
                        let annotation =
                            &self.user_type_annotations[annotation_index];
                        {
                            crate::type_check::mirbug(self.tcx(), self.last_span,
                                ::alloc::__export::must_use({
                                        ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                self.body().source.def_id(), stmt,
                                                format_args!("bad user type on rvalue ({0:?} = {1:?}): {2:?}",
                                                    annotation, rv_ty, terr)))
                                    }))
                        };
                    }
                    if !self.tcx().features().unsized_fn_params() {
                        let trait_ref =
                            ty::TraitRef::new(tcx,
                                tcx.require_lang_item(LangItem::Sized, self.last_span),
                                [place_ty]);
                        self.prove_trait_ref(trait_ref, location.to_locations(),
                            ConstraintCategory::SizedBound);
                    }
                }
                StatementKind::AscribeUserType((place, projection), variance)
                    => {
                    let place_ty = place.ty(self.body, tcx).ty;
                    if let Err(terr) =
                            self.relate_type_and_user_type(place_ty, *variance,
                                projection, Locations::All(stmt.source_info.span),
                                ConstraintCategory::TypeAnnotation(AnnotationSource::Ascription))
                        {
                        let annotation =
                            &self.user_type_annotations[projection.base];
                        {
                            crate::type_check::mirbug(self.tcx(), self.last_span,
                                ::alloc::__export::must_use({
                                        ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                self.body().source.def_id(), stmt,
                                                format_args!("bad type assert ({0:?} <: {1:?} with projections {2:?}): {3:?}",
                                                    place_ty, annotation, projection.projs, terr)))
                                    }))
                        };
                    }
                }
                StatementKind::Intrinsic(NonDivergingIntrinsic::Assume(..)) |
                    StatementKind::FakeRead(..) | StatementKind::StorageLive(..)
                    | StatementKind::StorageDead(..) |
                    StatementKind::Coverage(..) |
                    StatementKind::ConstEvalCounter |
                    StatementKind::PlaceMention(..) |
                    StatementKind::BackwardIncompatibleDropHint { .. } |
                    StatementKind::Nop => {}
                StatementKind::Intrinsic(NonDivergingIntrinsic::CopyNonOverlapping(..))
                    | StatementKind::SetDiscriminant { .. } => {
                    ::rustc_middle::util::bug::bug_fmt(format_args!("Statement not allowed in this MIR phase"))
                }
            }
        }
    }
}#[instrument(skip(self), level = "debug")]
610    fn visit_statement(&mut self, stmt: &Statement<'tcx>, location: Location) {
611        self.super_statement(stmt, location);
612        let tcx = self.tcx();
613        match &stmt.kind {
614            StatementKind::Assign((place, rv)) => {
615                // Assignments to temporaries are not "interesting";
616                // they are not caused by the user, but rather artifacts
617                // of lowering. Assignments to other sorts of places *are* interesting
618                // though.
619                let category = match place.as_local() {
620                    Some(RETURN_PLACE) => {
621                        let defining_ty = &self.universal_regions.defining_ty;
622                        if defining_ty.is_const() {
623                            if tcx.is_static(defining_ty.def_id()) {
624                                ConstraintCategory::UseAsStatic
625                            } else {
626                                ConstraintCategory::UseAsConst
627                            }
628                        } else {
629                            ConstraintCategory::Return(ReturnConstraint::Normal)
630                        }
631                    }
632                    Some(l)
633                        if matches!(
634                            self.body.local_decls[l].local_info(),
635                            LocalInfo::AggregateTemp
636                        ) =>
637                    {
638                        ConstraintCategory::Usage
639                    }
640                    Some(l) if !self.body.local_decls[l].is_user_variable() => {
641                        ConstraintCategory::Boring
642                    }
643                    _ => ConstraintCategory::Assignment,
644                };
645                debug!(
646                    "assignment category: {:?} {:?}",
647                    category,
648                    place.as_local().map(|l| &self.body.local_decls[l])
649                );
650
651                let place_ty = place.ty(self.body, tcx).ty;
652                debug!(?place_ty);
653                let place_ty = self.normalize(ty::Unnormalized::new_wip(place_ty), location);
654                debug!("place_ty normalized: {:?}", place_ty);
655                let rv_ty = rv.ty(self.body, tcx);
656                debug!(?rv_ty);
657                let rv_ty = self.normalize(ty::Unnormalized::new_wip(rv_ty), location);
658                debug!("normalized rv_ty: {:?}", rv_ty);
659                if let Err(terr) =
660                    self.sub_types(rv_ty, place_ty, location.to_locations(), category)
661                {
662                    span_mirbug!(
663                        self,
664                        stmt,
665                        "bad assignment ({:?} = {:?}): {:?}",
666                        place_ty,
667                        rv_ty,
668                        terr
669                    );
670                }
671
672                if let Some(annotation_index) = self.rvalue_user_ty(rv)
673                    && let Err(terr) = self.relate_type_and_user_type(
674                        rv_ty,
675                        ty::Invariant,
676                        &UserTypeProjection { base: annotation_index, projs: vec![] },
677                        location.to_locations(),
678                        ConstraintCategory::TypeAnnotation(AnnotationSource::GenericArg),
679                    )
680                {
681                    let annotation = &self.user_type_annotations[annotation_index];
682                    span_mirbug!(
683                        self,
684                        stmt,
685                        "bad user type on rvalue ({:?} = {:?}): {:?}",
686                        annotation,
687                        rv_ty,
688                        terr
689                    );
690                }
691
692                if !self.tcx().features().unsized_fn_params() {
693                    let trait_ref = ty::TraitRef::new(
694                        tcx,
695                        tcx.require_lang_item(LangItem::Sized, self.last_span),
696                        [place_ty],
697                    );
698                    self.prove_trait_ref(
699                        trait_ref,
700                        location.to_locations(),
701                        ConstraintCategory::SizedBound,
702                    );
703                }
704            }
705            StatementKind::AscribeUserType((place, projection), variance) => {
706                let place_ty = place.ty(self.body, tcx).ty;
707                if let Err(terr) = self.relate_type_and_user_type(
708                    place_ty,
709                    *variance,
710                    projection,
711                    Locations::All(stmt.source_info.span),
712                    ConstraintCategory::TypeAnnotation(AnnotationSource::Ascription),
713                ) {
714                    let annotation = &self.user_type_annotations[projection.base];
715                    span_mirbug!(
716                        self,
717                        stmt,
718                        "bad type assert ({:?} <: {:?} with projections {:?}): {:?}",
719                        place_ty,
720                        annotation,
721                        projection.projs,
722                        terr
723                    );
724                }
725            }
726            StatementKind::Intrinsic(NonDivergingIntrinsic::Assume(..))
727            | StatementKind::FakeRead(..)
728            | StatementKind::StorageLive(..)
729            | StatementKind::StorageDead(..)
730            | StatementKind::Coverage(..)
731            | StatementKind::ConstEvalCounter
732            | StatementKind::PlaceMention(..)
733            | StatementKind::BackwardIncompatibleDropHint { .. }
734            | StatementKind::Nop => {}
735            StatementKind::Intrinsic(NonDivergingIntrinsic::CopyNonOverlapping(..))
736            | StatementKind::SetDiscriminant { .. } => {
737                bug!("Statement not allowed in this MIR phase")
738            }
739        }
740    }
741
742    #[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("visit_terminator",
                                    "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(742u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("term")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("term");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("term_location")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("term_location");
                                                        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(&term)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&term_location)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            self.super_terminator(term, term_location);
            let tcx = self.tcx();
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/mod.rs:746",
                                    "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(746u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                    ::tracing_core::field::FieldSet::new(&["message"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("terminator kind: {0:?}",
                                                                term.kind) as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            match &term.kind {
                TerminatorKind::Goto { .. } | TerminatorKind::UnwindResume |
                    TerminatorKind::UnwindTerminate(_) | TerminatorKind::Return
                    | TerminatorKind::CoroutineDrop |
                    TerminatorKind::Unreachable | TerminatorKind::Drop { .. } |
                    TerminatorKind::FalseEdge { .. } |
                    TerminatorKind::FalseUnwind { .. } |
                    TerminatorKind::InlineAsm { .. } => {}
                TerminatorKind::SwitchInt { discr, .. } => {
                    let switch_ty = discr.ty(self.body, tcx);
                    if !switch_ty.is_integral() && !switch_ty.is_char() &&
                            !switch_ty.is_bool() {
                        {
                            crate::type_check::mirbug(self.tcx(), self.last_span,
                                ::alloc::__export::must_use({
                                        ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                self.body().source.def_id(), term,
                                                format_args!("bad SwitchInt discr ty {0:?}", switch_ty)))
                                    }))
                        };
                    }
                }
                TerminatorKind::Call { func, args, .. } |
                    TerminatorKind::TailCall { func, args, .. } => {
                    let (call_source, destination, is_diverging) =
                        match term.kind {
                            TerminatorKind::Call { call_source, destination, target, ..
                                } => {
                                (call_source, destination, target.is_none())
                            }
                            TerminatorKind::TailCall { .. } => {
                                (CallSource::Normal, RETURN_PLACE.into(), false)
                            }
                            _ =>
                                ::core::panicking::panic("internal error: entered unreachable code"),
                        };
                    let func_ty = func.ty(self.body, tcx);
                    {
                        use ::tracing::__macro_support::Callsite as _;
                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                            {
                                static META: ::tracing::Metadata<'static> =
                                    {
                                        ::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/mod.rs:781",
                                            "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                                            ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                            ::tracing_core::__macro_support::Option::Some(781u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                            ::tracing_core::field::FieldSet::new(&["message"],
                                                ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                            ::tracing::metadata::Kind::EVENT)
                                    };
                                ::tracing::callsite::DefaultCallsite::new(&META)
                            };
                        let enabled =
                            ::tracing::Level::DEBUG <=
                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                    ::tracing::Level::DEBUG <=
                                        ::tracing::level_filters::LevelFilter::current() &&
                                {
                                    let interest = __CALLSITE.interest();
                                    !interest.is_never() &&
                                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                            interest)
                                };
                        if enabled {
                            (|value_set: ::tracing::field::ValueSet|
                                        {
                                            let meta = __CALLSITE.metadata();
                                            ::tracing::Event::dispatch(meta, &value_set);
                                            ;
                                        })({
                                    #[allow(unused_imports)]
                                    use ::tracing::field::{debug, display, Value};
                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("func_ty.kind: {0:?}",
                                                                        func_ty.kind()) as &dyn ::tracing::field::Value))])
                                });
                        } else { ; }
                    };
                    let sig =
                        match func_ty.kind() {
                            ty::FnDef(..) | ty::FnPtr(..) => func_ty.fn_sig(tcx),
                            _ => {
                                {
                                    crate::type_check::mirbug(self.tcx(), self.last_span,
                                        ::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                        self.body().source.def_id(), term,
                                                        format_args!("call to non-function {0:?}", func_ty)))
                                            }))
                                };
                                return;
                            }
                        };
                    let (unnormalized_sig, map) =
                        tcx.instantiate_bound_regions(sig,
                            |br|
                                {
                                    use crate::renumber::RegionCtxt;
                                    let region_ctxt_fn =
                                        ||
                                            {
                                                let reg_info =
                                                    match br.kind {
                                                        ty::BoundRegionKind::Anon => sym::anon,
                                                        ty::BoundRegionKind::Named(def_id) => 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"))
                                                        }
                                                    };
                                                RegionCtxt::LateBound(reg_info)
                                            };
                                    self.infcx.next_region_var(RegionVariableOrigin::BoundRegion(term.source_info.span,
                                            br.kind, BoundRegionConversionTime::FnCall), region_ctxt_fn)
                                });
                    {
                        use ::tracing::__macro_support::Callsite as _;
                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                            {
                                static META: ::tracing::Metadata<'static> =
                                    {
                                        ::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/mod.rs:815",
                                            "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                                            ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                            ::tracing_core::__macro_support::Option::Some(815u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                            ::tracing_core::field::FieldSet::new(&[{
                                                                const NAME:
                                                                    ::tracing::__macro_support::FieldName<{
                                                                        ::tracing::__macro_support::FieldName::len("unnormalized_sig")
                                                                    }> =
                                                                    ::tracing::__macro_support::FieldName::new("unnormalized_sig");
                                                                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(&unnormalized_sig)
                                                                as &dyn ::tracing::field::Value))])
                                });
                        } else { ; }
                    };
                    self.prove_clauses(unnormalized_sig.inputs_and_output.iter().map(|ty|
                                ty::ClauseKind::WellFormed(ty.into())),
                        term_location.to_locations(), ConstraintCategory::Boring);
                    let sig =
                        match self.deeply_normalize(ty::Unnormalized::new_wip(unnormalized_sig),
                                term_location) {
                            Ok(sig) => sig,
                            Err(guar) => { let _: ErrorGuaranteed = guar; return; }
                        };
                    if sig != unnormalized_sig {
                        self.prove_clauses(sig.inputs_and_output.iter().map(|ty|
                                    ty::ClauseKind::WellFormed(ty.into())),
                            term_location.to_locations(), ConstraintCategory::Boring);
                    }
                    self.check_call_dest(term, &sig, destination, is_diverging,
                        term_location);
                    for &late_bound_region in map.values() {
                        let region_vid =
                            self.universal_regions.to_region_vid(late_bound_region);
                        self.constraints.liveness_constraints.add_location(region_vid,
                            term_location);
                    }
                    self.check_call_inputs(term, func, &sig, args,
                        term_location, call_source);
                }
                TerminatorKind::Assert { cond, msg, .. } => {
                    let cond_ty = cond.ty(self.body, tcx);
                    if cond_ty != tcx.types.bool {
                        {
                            crate::type_check::mirbug(self.tcx(), self.last_span,
                                ::alloc::__export::must_use({
                                        ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                self.body().source.def_id(), term,
                                                format_args!("bad Assert ({0:?}, not bool", cond_ty)))
                                    }))
                        };
                    }
                    if let AssertKind::BoundsCheck { len, index } = &**msg {
                        if len.ty(self.body, tcx) != tcx.types.usize {
                            {
                                crate::type_check::mirbug(self.tcx(), self.last_span,
                                    ::alloc::__export::must_use({
                                            ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                    self.body().source.def_id(), len,
                                                    format_args!("bounds-check length non-usize {0:?}", len)))
                                        }))
                            }
                        }
                        if index.ty(self.body, tcx) != tcx.types.usize {
                            {
                                crate::type_check::mirbug(self.tcx(), self.last_span,
                                    ::alloc::__export::must_use({
                                            ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                    self.body().source.def_id(), index,
                                                    format_args!("bounds-check index non-usize {0:?}", index)))
                                        }))
                            }
                        }
                    }
                }
                TerminatorKind::Yield { value, resume_arg, .. } => {
                    match self.body.yield_ty() {
                        None => {
                            crate::type_check::mirbug(self.tcx(), self.last_span,
                                ::alloc::__export::must_use({
                                        ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                self.body().source.def_id(), term,
                                                format_args!("yield in non-coroutine")))
                                    }))
                        }
                        Some(ty) => {
                            let value_ty = value.ty(self.body, tcx);
                            if let Err(terr) =
                                    self.sub_types(value_ty, ty, term_location.to_locations(),
                                        ConstraintCategory::Yield) {
                                {
                                    crate::type_check::mirbug(self.tcx(), self.last_span,
                                        ::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                        self.body().source.def_id(), term,
                                                        format_args!("type of yield value is {0:?}, but the yield type is {1:?}: {2:?}",
                                                            value_ty, ty, terr)))
                                            }))
                                };
                            }
                        }
                    }
                    match self.body.resume_ty() {
                        None => {
                            crate::type_check::mirbug(self.tcx(), self.last_span,
                                ::alloc::__export::must_use({
                                        ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                self.body().source.def_id(), term,
                                                format_args!("yield in non-coroutine")))
                                    }))
                        }
                        Some(ty) => {
                            let resume_ty = resume_arg.ty(self.body, tcx);
                            if let Err(terr) =
                                    self.sub_types(ty, resume_ty.ty,
                                        term_location.to_locations(), ConstraintCategory::Yield) {
                                {
                                    crate::type_check::mirbug(self.tcx(), self.last_span,
                                        ::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                        self.body().source.def_id(), term,
                                                        format_args!("type of resume place is {0:?}, but the resume type is {1:?}: {2:?}",
                                                            resume_ty, ty, terr)))
                                            }))
                                };
                            }
                        }
                    }
                }
            }
        }
    }
}#[instrument(skip(self), level = "debug")]
743    fn visit_terminator(&mut self, term: &Terminator<'tcx>, term_location: Location) {
744        self.super_terminator(term, term_location);
745        let tcx = self.tcx();
746        debug!("terminator kind: {:?}", term.kind);
747        match &term.kind {
748            TerminatorKind::Goto { .. }
749            | TerminatorKind::UnwindResume
750            | TerminatorKind::UnwindTerminate(_)
751            | TerminatorKind::Return
752            | TerminatorKind::CoroutineDrop
753            | TerminatorKind::Unreachable
754            | TerminatorKind::Drop { .. }
755            | TerminatorKind::FalseEdge { .. }
756            | TerminatorKind::FalseUnwind { .. }
757            | TerminatorKind::InlineAsm { .. } => {
758                // no checks needed for these
759            }
760
761            TerminatorKind::SwitchInt { discr, .. } => {
762                let switch_ty = discr.ty(self.body, tcx);
763                if !switch_ty.is_integral() && !switch_ty.is_char() && !switch_ty.is_bool() {
764                    span_mirbug!(self, term, "bad SwitchInt discr ty {:?}", switch_ty);
765                }
766                // FIXME: check the values
767            }
768            TerminatorKind::Call { func, args, .. }
769            | TerminatorKind::TailCall { func, args, .. } => {
770                let (call_source, destination, is_diverging) = match term.kind {
771                    TerminatorKind::Call { call_source, destination, target, .. } => {
772                        (call_source, destination, target.is_none())
773                    }
774                    TerminatorKind::TailCall { .. } => {
775                        (CallSource::Normal, RETURN_PLACE.into(), false)
776                    }
777                    _ => unreachable!(),
778                };
779
780                let func_ty = func.ty(self.body, tcx);
781                debug!("func_ty.kind: {:?}", func_ty.kind());
782
783                let sig = match func_ty.kind() {
784                    ty::FnDef(..) | ty::FnPtr(..) => func_ty.fn_sig(tcx),
785                    _ => {
786                        span_mirbug!(self, term, "call to non-function {:?}", func_ty);
787                        return;
788                    }
789                };
790                let (unnormalized_sig, map) = tcx.instantiate_bound_regions(sig, |br| {
791                    use crate::renumber::RegionCtxt;
792
793                    let region_ctxt_fn = || {
794                        let reg_info = match br.kind {
795                            ty::BoundRegionKind::Anon => sym::anon,
796                            ty::BoundRegionKind::Named(def_id) => tcx.item_name(def_id),
797                            ty::BoundRegionKind::ClosureEnv => sym::env,
798                            ty::BoundRegionKind::NamedForPrinting(_) => {
799                                bug!("only used for pretty printing")
800                            }
801                        };
802
803                        RegionCtxt::LateBound(reg_info)
804                    };
805
806                    self.infcx.next_region_var(
807                        RegionVariableOrigin::BoundRegion(
808                            term.source_info.span,
809                            br.kind,
810                            BoundRegionConversionTime::FnCall,
811                        ),
812                        region_ctxt_fn,
813                    )
814                });
815                debug!(?unnormalized_sig);
816                // IMPORTANT: We have to prove well formed for the function signature before
817                // we normalize it, as otherwise types like `<&'a &'b () as Trait>::Assoc`
818                // get normalized away, causing us to ignore the `'b: 'a` bound used by the function.
819                //
820                // Normalization results in a well formed type if the input is well formed, so we
821                // don't have to check it twice.
822                //
823                // See #91068 for an example.
824                self.prove_clauses(
825                    unnormalized_sig
826                        .inputs_and_output
827                        .iter()
828                        .map(|ty| ty::ClauseKind::WellFormed(ty.into())),
829                    term_location.to_locations(),
830                    ConstraintCategory::Boring,
831                );
832
833                let sig = match self
834                    .deeply_normalize(ty::Unnormalized::new_wip(unnormalized_sig), term_location)
835                {
836                    Ok(sig) => sig,
837                    Err(guar) => {
838                        let _: ErrorGuaranteed = guar;
839                        return;
840                    }
841                };
842                // HACK(#114936): `WF(sig)` does not imply `WF(normalized(sig))`
843                // with built-in `Fn` implementations, since the impl may not be
844                // well-formed itself.
845                if sig != unnormalized_sig {
846                    self.prove_clauses(
847                        sig.inputs_and_output
848                            .iter()
849                            .map(|ty| ty::ClauseKind::WellFormed(ty.into())),
850                        term_location.to_locations(),
851                        ConstraintCategory::Boring,
852                    );
853                }
854
855                self.check_call_dest(term, &sig, destination, is_diverging, term_location);
856
857                // The ordinary liveness rules will ensure that all
858                // regions in the type of the callee are live here. We
859                // then further constrain the late-bound regions that
860                // were instantiated at the call site to be live as
861                // well. The resulting is that all the input (and
862                // output) types in the signature must be live, since
863                // all the inputs that fed into it were live.
864                for &late_bound_region in map.values() {
865                    let region_vid = self.universal_regions.to_region_vid(late_bound_region);
866                    self.constraints.liveness_constraints.add_location(region_vid, term_location);
867                }
868
869                self.check_call_inputs(term, func, &sig, args, term_location, call_source);
870            }
871            TerminatorKind::Assert { cond, msg, .. } => {
872                let cond_ty = cond.ty(self.body, tcx);
873                if cond_ty != tcx.types.bool {
874                    span_mirbug!(self, term, "bad Assert ({:?}, not bool", cond_ty);
875                }
876
877                if let AssertKind::BoundsCheck { len, index } = &**msg {
878                    if len.ty(self.body, tcx) != tcx.types.usize {
879                        span_mirbug!(self, len, "bounds-check length non-usize {:?}", len)
880                    }
881                    if index.ty(self.body, tcx) != tcx.types.usize {
882                        span_mirbug!(self, index, "bounds-check index non-usize {:?}", index)
883                    }
884                }
885            }
886            TerminatorKind::Yield { value, resume_arg, .. } => {
887                match self.body.yield_ty() {
888                    None => span_mirbug!(self, term, "yield in non-coroutine"),
889                    Some(ty) => {
890                        let value_ty = value.ty(self.body, tcx);
891                        if let Err(terr) = self.sub_types(
892                            value_ty,
893                            ty,
894                            term_location.to_locations(),
895                            ConstraintCategory::Yield,
896                        ) {
897                            span_mirbug!(
898                                self,
899                                term,
900                                "type of yield value is {:?}, but the yield type is {:?}: {:?}",
901                                value_ty,
902                                ty,
903                                terr
904                            );
905                        }
906                    }
907                }
908
909                match self.body.resume_ty() {
910                    None => span_mirbug!(self, term, "yield in non-coroutine"),
911                    Some(ty) => {
912                        let resume_ty = resume_arg.ty(self.body, tcx);
913                        if let Err(terr) = self.sub_types(
914                            ty,
915                            resume_ty.ty,
916                            term_location.to_locations(),
917                            ConstraintCategory::Yield,
918                        ) {
919                            span_mirbug!(
920                                self,
921                                term,
922                                "type of resume place is {:?}, but the resume type is {:?}: {:?}",
923                                resume_ty,
924                                ty,
925                                terr
926                            );
927                        }
928                    }
929                }
930            }
931        }
932    }
933
934    fn visit_local_decl(&mut self, local: Local, local_decl: &LocalDecl<'tcx>) {
935        self.super_local_decl(local, local_decl);
936
937        for user_ty in
938            local_decl.user_ty.as_deref().map(UserTypeProjections::projections).into_flat_iter()
939        {
940            let span = self.user_type_annotations[user_ty.base].span;
941
942            let ty = if local_decl.is_nonref_binding() {
943                local_decl.ty
944            } else if let &ty::Ref(_, rty, _) = local_decl.ty.kind() {
945                // If we have a binding of the form `let ref x: T = ..`
946                // then remove the outermost reference so we can check the
947                // type annotation for the remaining type.
948                rty
949            } else {
950                ::rustc_middle::util::bug::bug_fmt(format_args!("{0:?} with ref binding has wrong type {1}",
        local, local_decl.ty));bug!("{:?} with ref binding has wrong type {}", local, local_decl.ty);
951            };
952
953            if let Err(terr) = self.relate_type_and_user_type(
954                ty,
955                ty::Invariant,
956                user_ty,
957                Locations::All(span),
958                ConstraintCategory::TypeAnnotation(AnnotationSource::Declaration),
959            ) {
960                {
    crate::type_check::mirbug(self.tcx(), self.last_span,
        ::alloc::__export::must_use({
                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                        self.body().source.def_id(), local,
                        format_args!("bad user type on variable {0:?}: {1:?} != {2:?} ({3:?})",
                            local, local_decl.ty, local_decl.user_ty, terr)))
            }))
};span_mirbug!(
961                    self,
962                    local,
963                    "bad user type on variable {:?}: {:?} != {:?} ({:?})",
964                    local,
965                    local_decl.ty,
966                    local_decl.user_ty,
967                    terr,
968                );
969            }
970        }
971
972        // When `unsized_fn_params` is enabled, this is checked in `check_call_dest`,
973        // and `hir_typeck` still forces all non-argument locals to be sized (i.e., we don't
974        // fully re-check what was already checked on HIR).
975        if !self.tcx().features().unsized_fn_params() {
976            match self.body.local_kind(local) {
977                LocalKind::ReturnPointer | LocalKind::Arg => {
978                    // return values of normal functions are required to be
979                    // sized by typeck, but return values of ADT constructors are
980                    // not because we don't include a `Self: Sized` bounds on them.
981                    //
982                    // Unbound parts of arguments were never required to be Sized
983                    // - maybe we should make that a warning.
984                    return;
985                }
986                LocalKind::Temp => {
987                    let span = local_decl.source_info.span;
988                    let ty = local_decl.ty;
989                    self.ensure_place_sized(ty, span);
990                }
991            }
992        }
993    }
994
995    #[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("visit_rvalue",
                                    "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(995u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("rvalue")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("rvalue");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("location")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("location");
                                                        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(&rvalue)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&location)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            self.super_rvalue(rvalue, location);
            let tcx = self.tcx();
            let span = self.body.source_info(location).span;
            match rvalue {
                Rvalue::Aggregate(ak, ops) =>
                    self.check_aggregate_rvalue(rvalue, ak, ops, location),
                Rvalue::Repeat(operand, len) => {
                    let array_ty = rvalue.ty(self.body.local_decls(), tcx);
                    self.prove_clause(ty::ClauseKind::WellFormed(array_ty.into()),
                        Locations::Single(location), ConstraintCategory::Boring);
                    if len.try_to_target_usize(tcx).is_none_or(|len| len > 1) {
                        match operand {
                            Operand::Copy(..) | Operand::Constant(..) |
                                Operand::RuntimeChecks(_) => {}
                            Operand::Move(place) => {
                                let ty = place.ty(self.body, tcx).ty;
                                let trait_ref =
                                    ty::TraitRef::new(tcx,
                                        tcx.require_lang_item(LangItem::Copy, span), [ty]);
                                self.prove_trait_ref(trait_ref, Locations::Single(location),
                                    ConstraintCategory::CopyBound);
                            }
                        }
                    }
                }
                Rvalue::Cast(cast_kind, op, ty) => {
                    match *cast_kind {
                        CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer(target_safety),
                            coercion_source) => {
                            let is_implicit_coercion =
                                coercion_source == CoercionSource::Implicit;
                            let src_ty = op.ty(self.body, tcx);
                            let mut src_sig = src_ty.fn_sig(tcx);
                            if let ty::FnDef(def_id, _) = *src_ty.kind() &&
                                                let ty::FnPtr(_, target_hdr) = *ty.kind() &&
                                            tcx.codegen_fn_attrs(def_id).safe_target_features &&
                                        target_hdr.safety().is_safe() &&
                                    let Some(safe_sig) =
                                        tcx.adjust_target_feature_sig(def_id, src_sig,
                                            self.body.source.def_id()) {
                                src_sig = safe_sig;
                            }
                            if src_sig.safety().is_safe() && target_safety.is_unsafe() {
                                src_sig = tcx.safe_to_unsafe_sig(src_sig);
                            }
                            if src_sig.has_bound_regions() &&
                                            let ty::FnPtr(target_fn_tys, target_hdr) = *ty.kind() &&
                                        let target_sig = target_fn_tys.with(target_hdr) &&
                                    let Some(target_sig) = target_sig.no_bound_vars() {
                                let src_sig =
                                    self.infcx.instantiate_binder_with_fresh_vars(span,
                                        BoundRegionConversionTime::HigherRankedType, src_sig);
                                let src_ty =
                                    Ty::new_fn_ptr(self.tcx(), ty::Binder::dummy(src_sig));
                                self.prove_clause(ty::ClauseKind::WellFormed(src_ty.into()),
                                    location.to_locations(),
                                    ConstraintCategory::Cast {
                                        is_raw_ptr_dyn_type_cast: false,
                                        is_implicit_coercion,
                                        unsize_to: None,
                                    });
                                let src_ty =
                                    self.normalize(ty::Unnormalized::new_wip(src_ty), location);
                                if let Err(terr) =
                                        self.sub_types(src_ty, *ty, location.to_locations(),
                                            ConstraintCategory::Cast {
                                                is_raw_ptr_dyn_type_cast: false,
                                                is_implicit_coercion,
                                                unsize_to: None,
                                            }) {
                                    {
                                        crate::type_check::mirbug(self.tcx(), self.last_span,
                                            ::alloc::__export::must_use({
                                                    ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                            self.body().source.def_id(), rvalue,
                                                            format_args!("equating {0:?} with {1:?} yields {2:?}",
                                                                target_sig, src_sig, terr)))
                                                }))
                                    };
                                };
                            }
                            let src_ty = Ty::new_fn_ptr(tcx, src_sig);
                            self.prove_clause(ty::ClauseKind::WellFormed(src_ty.into()),
                                location.to_locations(),
                                ConstraintCategory::Cast {
                                    is_raw_ptr_dyn_type_cast: false,
                                    is_implicit_coercion,
                                    unsize_to: None,
                                });
                            let src_ty =
                                self.normalize(ty::Unnormalized::new_wip(src_ty), location);
                            if let Err(terr) =
                                    self.sub_types(src_ty, *ty, location.to_locations(),
                                        ConstraintCategory::Cast {
                                            is_raw_ptr_dyn_type_cast: false,
                                            is_implicit_coercion,
                                            unsize_to: None,
                                        }) {
                                {
                                    crate::type_check::mirbug(self.tcx(), self.last_span,
                                        ::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                        self.body().source.def_id(), rvalue,
                                                        format_args!("equating {0:?} with {1:?} yields {2:?}",
                                                            src_ty, ty, terr)))
                                            }))
                                };
                            }
                        }
                        CastKind::PointerCoercion(PointerCoercion::ClosureFnPointer(safety),
                            coercion_source) => {
                            let sig =
                                match op.ty(self.body, tcx).kind() {
                                    ty::Closure(_, args) => args.as_closure().sig(),
                                    _ =>
                                        ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached")),
                                };
                            let ty_fn_ptr_from =
                                Ty::new_fn_ptr(tcx, tcx.signature_unclosure(sig, safety));
                            let is_implicit_coercion =
                                coercion_source == CoercionSource::Implicit;
                            if let Err(terr) =
                                    self.sub_types(ty_fn_ptr_from, *ty, location.to_locations(),
                                        ConstraintCategory::Cast {
                                            is_raw_ptr_dyn_type_cast: false,
                                            is_implicit_coercion,
                                            unsize_to: None,
                                        }) {
                                {
                                    crate::type_check::mirbug(self.tcx(), self.last_span,
                                        ::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                        self.body().source.def_id(), rvalue,
                                                        format_args!("equating {0:?} with {1:?} yields {2:?}",
                                                            ty_fn_ptr_from, ty, terr)))
                                            }))
                                };
                            }
                        }
                        CastKind::PointerCoercion(PointerCoercion::UnsafeFnPointer,
                            coercion_source) => {
                            let fn_sig = op.ty(self.body, tcx).fn_sig(tcx);
                            let fn_sig =
                                self.normalize(ty::Unnormalized::new_wip(fn_sig), location);
                            let ty_fn_ptr_from = tcx.safe_to_unsafe_fn_ty(fn_sig);
                            let is_implicit_coercion =
                                coercion_source == CoercionSource::Implicit;
                            if let Err(terr) =
                                    self.sub_types(ty_fn_ptr_from, *ty, location.to_locations(),
                                        ConstraintCategory::Cast {
                                            is_raw_ptr_dyn_type_cast: false,
                                            is_implicit_coercion,
                                            unsize_to: None,
                                        }) {
                                {
                                    crate::type_check::mirbug(self.tcx(), self.last_span,
                                        ::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                        self.body().source.def_id(), rvalue,
                                                        format_args!("equating {0:?} with {1:?} yields {2:?}",
                                                            ty_fn_ptr_from, ty, terr)))
                                            }))
                                };
                            }
                        }
                        CastKind::PointerCoercion(PointerCoercion::Unsize,
                            coercion_source) => {
                            let &ty = ty;
                            let trait_ref =
                                ty::TraitRef::new(tcx,
                                    tcx.require_lang_item(LangItem::CoerceUnsized, span),
                                    [op.ty(self.body, tcx), ty]);
                            let is_implicit_coercion =
                                coercion_source == CoercionSource::Implicit;
                            let unsize_to =
                                fold_regions(tcx, ty,
                                    |r, _|
                                        {
                                            if let ty::ReVar(_) = r.kind() {
                                                tcx.lifetimes.re_erased
                                            } else { r }
                                        });
                            self.prove_trait_ref(trait_ref, location.to_locations(),
                                ConstraintCategory::Cast {
                                    is_raw_ptr_dyn_type_cast: false,
                                    is_implicit_coercion,
                                    unsize_to: Some(unsize_to),
                                });
                        }
                        CastKind::PointerCoercion(PointerCoercion::MutToConstPointer,
                            coercion_source) => {
                            let ty::RawPtr(ty_from, hir::Mutability::Mut) =
                                op.ty(self.body,
                                        tcx).kind() else {
                                    {
                                        crate::type_check::mirbug(self.tcx(), self.last_span,
                                            ::alloc::__export::must_use({
                                                    ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                            self.body().source.def_id(), rvalue,
                                                            format_args!("unexpected base type for cast {0:?}", ty)))
                                                }))
                                    };
                                    return;
                                };
                            let ty::RawPtr(ty_to, hir::Mutability::Not) =
                                ty.kind() else {
                                    {
                                        crate::type_check::mirbug(self.tcx(), self.last_span,
                                            ::alloc::__export::must_use({
                                                    ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                            self.body().source.def_id(), rvalue,
                                                            format_args!("unexpected target type for cast {0:?}", ty)))
                                                }))
                                    };
                                    return;
                                };
                            let is_implicit_coercion =
                                coercion_source == CoercionSource::Implicit;
                            if let Err(terr) =
                                    self.sub_types(*ty_from, *ty_to, location.to_locations(),
                                        ConstraintCategory::Cast {
                                            is_raw_ptr_dyn_type_cast: false,
                                            is_implicit_coercion,
                                            unsize_to: None,
                                        }) {
                                {
                                    crate::type_check::mirbug(self.tcx(), self.last_span,
                                        ::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                        self.body().source.def_id(), rvalue,
                                                        format_args!("relating {0:?} with {1:?} yields {2:?}",
                                                            ty_from, ty_to, terr)))
                                            }))
                                };
                            }
                        }
                        CastKind::PointerCoercion(PointerCoercion::ArrayToPointer,
                            coercion_source) => {
                            let ty_from = op.ty(self.body, tcx);
                            let opt_ty_elem_mut =
                                match ty_from.kind() {
                                    ty::RawPtr(array_ty, array_mut) =>
                                        match array_ty.kind() {
                                            ty::Array(ty_elem, _) => Some((ty_elem, *array_mut)),
                                            _ => None,
                                        },
                                    _ => None,
                                };
                            let Some((ty_elem, ty_mut)) =
                                opt_ty_elem_mut else {
                                    {
                                        crate::type_check::mirbug(self.tcx(), self.last_span,
                                            ::alloc::__export::must_use({
                                                    ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                            self.body().source.def_id(), rvalue,
                                                            format_args!("ArrayToPointer cast from unexpected type {0:?}",
                                                                ty_from)))
                                                }))
                                    };
                                    return;
                                };
                            let (ty_to, ty_to_mut) =
                                match ty.kind() {
                                    ty::RawPtr(ty_to, ty_to_mut) => (ty_to, *ty_to_mut),
                                    _ => {
                                        {
                                            crate::type_check::mirbug(self.tcx(), self.last_span,
                                                ::alloc::__export::must_use({
                                                        ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                                self.body().source.def_id(), rvalue,
                                                                format_args!("ArrayToPointer cast to unexpected type {0:?}",
                                                                    ty)))
                                                    }))
                                        };
                                        return;
                                    }
                                };
                            if ty_to_mut.is_mut() && ty_mut.is_not() {
                                {
                                    crate::type_check::mirbug(self.tcx(), self.last_span,
                                        ::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                        self.body().source.def_id(), rvalue,
                                                        format_args!("ArrayToPointer cast from const {0:?} to mut {1:?}",
                                                            ty, ty_to)))
                                            }))
                                };
                                return;
                            }
                            let is_implicit_coercion =
                                coercion_source == CoercionSource::Implicit;
                            if let Err(terr) =
                                    self.sub_types(*ty_elem, *ty_to, location.to_locations(),
                                        ConstraintCategory::Cast {
                                            is_raw_ptr_dyn_type_cast: false,
                                            is_implicit_coercion,
                                            unsize_to: None,
                                        }) {
                                {
                                    crate::type_check::mirbug(self.tcx(), self.last_span,
                                        ::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                        self.body().source.def_id(), rvalue,
                                                        format_args!("relating {0:?} with {1:?} yields {2:?}",
                                                            ty_elem, ty_to, terr)))
                                            }))
                                }
                            }
                        }
                        CastKind::PointerExposeProvenance => {
                            let ty_from = op.ty(self.body, tcx);
                            let cast_ty_from = CastTy::from_ty(ty_from);
                            let cast_ty_to = CastTy::from_ty(*ty);
                            match (cast_ty_from, cast_ty_to) {
                                (Some(CastTy::Ptr(_) | CastTy::FnPtr), Some(CastTy::Int(_)))
                                    => (),
                                _ => {
                                    {
                                        crate::type_check::mirbug(self.tcx(), self.last_span,
                                            ::alloc::__export::must_use({
                                                    ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                            self.body().source.def_id(), rvalue,
                                                            format_args!("Invalid PointerExposeProvenance cast {0:?} -> {1:?}",
                                                                ty_from, ty)))
                                                }))
                                    }
                                }
                            }
                        }
                        CastKind::PointerWithExposedProvenance => {
                            let ty_from = op.ty(self.body, tcx);
                            let cast_ty_from = CastTy::from_ty(ty_from);
                            let cast_ty_to = CastTy::from_ty(*ty);
                            match (cast_ty_from, cast_ty_to) {
                                (Some(CastTy::Int(_)), Some(CastTy::Ptr(_))) => (),
                                _ => {
                                    {
                                        crate::type_check::mirbug(self.tcx(), self.last_span,
                                            ::alloc::__export::must_use({
                                                    ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                            self.body().source.def_id(), rvalue,
                                                            format_args!("Invalid PointerWithExposedProvenance cast {0:?} -> {1:?}",
                                                                ty_from, ty)))
                                                }))
                                    }
                                }
                            }
                        }
                        CastKind::IntToInt => {
                            let ty_from = op.ty(self.body, tcx);
                            let cast_ty_from = CastTy::from_ty(ty_from);
                            let cast_ty_to = CastTy::from_ty(*ty);
                            match (cast_ty_from, cast_ty_to) {
                                (Some(CastTy::Int(_)), Some(CastTy::Int(_))) => (),
                                _ => {
                                    {
                                        crate::type_check::mirbug(self.tcx(), self.last_span,
                                            ::alloc::__export::must_use({
                                                    ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                            self.body().source.def_id(), rvalue,
                                                            format_args!("Invalid IntToInt cast {0:?} -> {1:?}",
                                                                ty_from, ty)))
                                                }))
                                    }
                                }
                            }
                        }
                        CastKind::IntToFloat => {
                            let ty_from = op.ty(self.body, tcx);
                            let cast_ty_from = CastTy::from_ty(ty_from);
                            let cast_ty_to = CastTy::from_ty(*ty);
                            match (cast_ty_from, cast_ty_to) {
                                (Some(CastTy::Int(_)), Some(CastTy::Float)) => (),
                                _ => {
                                    {
                                        crate::type_check::mirbug(self.tcx(), self.last_span,
                                            ::alloc::__export::must_use({
                                                    ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                            self.body().source.def_id(), rvalue,
                                                            format_args!("Invalid IntToFloat cast {0:?} -> {1:?}",
                                                                ty_from, ty)))
                                                }))
                                    }
                                }
                            }
                        }
                        CastKind::FloatToInt => {
                            let ty_from = op.ty(self.body, tcx);
                            let cast_ty_from = CastTy::from_ty(ty_from);
                            let cast_ty_to = CastTy::from_ty(*ty);
                            match (cast_ty_from, cast_ty_to) {
                                (Some(CastTy::Float), Some(CastTy::Int(_))) => (),
                                _ => {
                                    {
                                        crate::type_check::mirbug(self.tcx(), self.last_span,
                                            ::alloc::__export::must_use({
                                                    ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                            self.body().source.def_id(), rvalue,
                                                            format_args!("Invalid FloatToInt cast {0:?} -> {1:?}",
                                                                ty_from, ty)))
                                                }))
                                    }
                                }
                            }
                        }
                        CastKind::FloatToFloat => {
                            let ty_from = op.ty(self.body, tcx);
                            let cast_ty_from = CastTy::from_ty(ty_from);
                            let cast_ty_to = CastTy::from_ty(*ty);
                            match (cast_ty_from, cast_ty_to) {
                                (Some(CastTy::Float), Some(CastTy::Float)) => (),
                                _ => {
                                    {
                                        crate::type_check::mirbug(self.tcx(), self.last_span,
                                            ::alloc::__export::must_use({
                                                    ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                            self.body().source.def_id(), rvalue,
                                                            format_args!("Invalid FloatToFloat cast {0:?} -> {1:?}",
                                                                ty_from, ty)))
                                                }))
                                    }
                                }
                            }
                        }
                        CastKind::FnPtrToPtr => {
                            let ty_from = op.ty(self.body, tcx);
                            let cast_ty_from = CastTy::from_ty(ty_from);
                            let cast_ty_to = CastTy::from_ty(*ty);
                            match (cast_ty_from, cast_ty_to) {
                                (Some(CastTy::FnPtr), Some(CastTy::Ptr(_))) => (),
                                _ => {
                                    {
                                        crate::type_check::mirbug(self.tcx(), self.last_span,
                                            ::alloc::__export::must_use({
                                                    ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                            self.body().source.def_id(), rvalue,
                                                            format_args!("Invalid FnPtrToPtr cast {0:?} -> {1:?}",
                                                                ty_from, ty)))
                                                }))
                                    }
                                }
                            }
                        }
                        CastKind::PtrToPtr => {
                            let ty_from = op.ty(self.body, tcx);
                            let Some(CastTy::Ptr(src)) =
                                CastTy::from_ty(ty_from) else {
                                    ::core::panicking::panic("internal error: entered unreachable code");
                                };
                            let Some(CastTy::Ptr(dst)) =
                                CastTy::from_ty(*ty) else {
                                    ::core::panicking::panic("internal error: entered unreachable code");
                                };
                            if self.infcx.type_is_sized_modulo_regions(self.infcx.param_env,
                                    dst.ty) {
                                let trait_ref =
                                    ty::TraitRef::new(tcx,
                                        tcx.require_lang_item(LangItem::Sized, self.last_span),
                                        [dst.ty]);
                                self.prove_trait_ref(trait_ref, location.to_locations(),
                                    ConstraintCategory::Cast {
                                        is_raw_ptr_dyn_type_cast: false,
                                        is_implicit_coercion: true,
                                        unsize_to: None,
                                    });
                            } else if let ty::Dynamic(src_tty, src_lt) =
                                        *self.struct_tail(src.ty, location).kind() &&
                                    let ty::Dynamic(dst_tty, dst_lt) =
                                        *self.struct_tail(dst.ty, location).kind() {
                                match (src_tty.principal(), dst_tty.principal()) {
                                    (Some(_), Some(_)) => {
                                        let src_obj =
                                            Ty::new_dynamic(tcx,
                                                tcx.mk_poly_existential_predicates(&src_tty.without_auto_traits().collect::<Vec<_>>()),
                                                src_lt);
                                        let dst_obj =
                                            Ty::new_dynamic(tcx,
                                                tcx.mk_poly_existential_predicates(&dst_tty.without_auto_traits().collect::<Vec<_>>()),
                                                dst_lt);
                                        {
                                            use ::tracing::__macro_support::Callsite as _;
                                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                                {
                                                    static META: ::tracing::Metadata<'static> =
                                                        {
                                                            ::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/mod.rs:1542",
                                                                "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                                                                ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                                                ::tracing_core::__macro_support::Option::Some(1542u32),
                                                                ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                                                ::tracing_core::field::FieldSet::new(&[{
                                                                                    const NAME:
                                                                                        ::tracing::__macro_support::FieldName<{
                                                                                            ::tracing::__macro_support::FieldName::len("src_tty")
                                                                                        }> =
                                                                                        ::tracing::__macro_support::FieldName::new("src_tty");
                                                                                    NAME.as_str()
                                                                                },
                                                                                {
                                                                                    const NAME:
                                                                                        ::tracing::__macro_support::FieldName<{
                                                                                            ::tracing::__macro_support::FieldName::len("dst_tty")
                                                                                        }> =
                                                                                        ::tracing::__macro_support::FieldName::new("dst_tty");
                                                                                    NAME.as_str()
                                                                                },
                                                                                {
                                                                                    const NAME:
                                                                                        ::tracing::__macro_support::FieldName<{
                                                                                            ::tracing::__macro_support::FieldName::len("src_obj")
                                                                                        }> =
                                                                                        ::tracing::__macro_support::FieldName::new("src_obj");
                                                                                    NAME.as_str()
                                                                                },
                                                                                {
                                                                                    const NAME:
                                                                                        ::tracing::__macro_support::FieldName<{
                                                                                            ::tracing::__macro_support::FieldName::len("dst_obj")
                                                                                        }> =
                                                                                        ::tracing::__macro_support::FieldName::new("dst_obj");
                                                                                    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(&src_tty)
                                                                                    as &dyn ::tracing::field::Value)),
                                                                        (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&dst_tty)
                                                                                    as &dyn ::tracing::field::Value)),
                                                                        (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&src_obj)
                                                                                    as &dyn ::tracing::field::Value)),
                                                                        (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&dst_obj)
                                                                                    as &dyn ::tracing::field::Value))])
                                                    });
                                            } else { ; }
                                        };
                                        self.sub_types(src_obj, dst_obj, location.to_locations(),
                                                ConstraintCategory::Cast {
                                                    is_raw_ptr_dyn_type_cast: true,
                                                    is_implicit_coercion: false,
                                                    unsize_to: None,
                                                }).unwrap();
                                    }
                                    (None, None) => {
                                        let src_lt = self.universal_regions.to_region_vid(src_lt);
                                        let dst_lt = self.universal_regions.to_region_vid(dst_lt);
                                        self.constraints.outlives_constraints.push(OutlivesConstraint {
                                                sup: src_lt,
                                                sub: dst_lt,
                                                locations: location.to_locations(),
                                                span: location.to_locations().span(self.body),
                                                category: ConstraintCategory::Cast {
                                                    is_raw_ptr_dyn_type_cast: true,
                                                    is_implicit_coercion: false,
                                                    unsize_to: None,
                                                },
                                                variance_info: ty::VarianceDiagInfo::default(),
                                                from_closure: false,
                                            });
                                    }
                                    (None, Some(_)) =>
                                        ::rustc_middle::util::bug::bug_fmt(format_args!("introducing a principal should have errored in HIR typeck")),
                                    (Some(_), None) => {
                                        ::rustc_middle::util::bug::bug_fmt(format_args!("dropping the principal should have been an unsizing cast"))
                                    }
                                }
                            }
                        }
                        CastKind::Transmute => {
                            let ty_from = op.ty(self.body, tcx);
                            match ty_from.kind() {
                                ty::Pat(base, _) if base == ty => {}
                                _ => {
                                    crate::type_check::mirbug(self.tcx(), self.last_span,
                                        ::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                        self.body().source.def_id(), rvalue,
                                                        format_args!("Unexpected CastKind::Transmute {0:?} -> {1:?}, which is not permitted in Analysis MIR",
                                                            ty_from, ty)))
                                            }))
                                }
                            }
                        }
                        CastKind::Subtype | CastKind::BoxDerefTransmute => {
                            ::rustc_middle::util::bug::bug_fmt(format_args!("CastKind::{0:?} shouldn\'t exist in borrowck",
                                    cast_kind))
                        }
                    }
                }
                Rvalue::Ref(region, _borrow_kind, borrowed_place) => {
                    self.add_reborrow_constraint(location, *region,
                        borrowed_place);
                }
                Rvalue::Reborrow(target, mutability, borrowed_place) => {
                    self.add_generic_reborrow_constraint(*mutability, location,
                        borrowed_place, *target);
                }
                Rvalue::BinaryOp(BinOp::Eq | BinOp::Ne | BinOp::Lt | BinOp::Le
                    | BinOp::Gt | BinOp::Ge, (left, right)) => {
                    let ty_left = left.ty(self.body, tcx);
                    match ty_left.kind() {
                        ty::RawPtr(_, _) | ty::FnPtr(..) => {
                            let ty_right = right.ty(self.body, tcx);
                            let common_ty =
                                self.infcx.next_ty_var(self.body.source_info(location).span);
                            self.sub_types(ty_left, common_ty, location.to_locations(),
                                    ConstraintCategory::CallArgument(None)).unwrap_or_else(|err|
                                    {
                                        ::rustc_middle::util::bug::bug_fmt(format_args!("Could not equate type variable with {0:?}: {1:?}",
                                                ty_left, err))
                                    });
                            if let Err(terr) =
                                    self.sub_types(ty_right, common_ty, location.to_locations(),
                                        ConstraintCategory::CallArgument(None)) {
                                {
                                    crate::type_check::mirbug(self.tcx(), self.last_span,
                                        ::alloc::__export::must_use({
                                                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                        self.body().source.def_id(), rvalue,
                                                        format_args!("unexpected comparison types {0:?} and {1:?} yields {2:?}",
                                                            ty_left, ty_right, terr)))
                                            }))
                                }
                            }
                        }
                        ty::Int(_) | ty::Uint(_) | ty::Bool | ty::Char |
                            ty::Float(_) if ty_left == right.ty(self.body, tcx) => {}
                        _ => {
                            crate::type_check::mirbug(self.tcx(), self.last_span,
                                ::alloc::__export::must_use({
                                        ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                self.body().source.def_id(), rvalue,
                                                format_args!("unexpected comparison types {0:?} and {1:?}",
                                                    ty_left, right.ty(self.body, tcx))))
                                    }))
                        }
                    }
                }
                Rvalue::WrapUnsafeBinder(op, ty) => {
                    let operand_ty = op.ty(self.body, self.tcx());
                    let ty::UnsafeBinder(binder_ty) =
                        *ty.kind() else {
                            ::core::panicking::panic("internal error: entered unreachable code");
                        };
                    let expected_ty =
                        self.infcx.instantiate_binder_with_fresh_vars(self.body().source_info(location).span,
                            BoundRegionConversionTime::HigherRankedType,
                            binder_ty.into());
                    self.sub_types(operand_ty, expected_ty,
                            location.to_locations(),
                            ConstraintCategory::Boring).unwrap();
                }
                Rvalue::Use(_, _) | Rvalue::UnaryOp(_, _) |
                    Rvalue::CopyForDeref(_) | Rvalue::BinaryOp(..) |
                    Rvalue::RawPtr(..) | Rvalue::ThreadLocalRef(..) |
                    Rvalue::Discriminant(..) => {}
            }
        }
    }
}#[instrument(skip(self), level = "debug")]
996    fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
997        self.super_rvalue(rvalue, location);
998        let tcx = self.tcx();
999        let span = self.body.source_info(location).span;
1000        match rvalue {
1001            Rvalue::Aggregate(ak, ops) => self.check_aggregate_rvalue(rvalue, ak, ops, location),
1002
1003            Rvalue::Repeat(operand, len) => {
1004                let array_ty = rvalue.ty(self.body.local_decls(), tcx);
1005                self.prove_clause(
1006                    ty::ClauseKind::WellFormed(array_ty.into()),
1007                    Locations::Single(location),
1008                    ConstraintCategory::Boring,
1009                );
1010
1011                // If the length cannot be evaluated we must assume that the length can be larger
1012                // than 1.
1013                // If the length is larger than 1, the repeat expression will need to copy the
1014                // element, so we require the `Copy` trait.
1015                if len.try_to_target_usize(tcx).is_none_or(|len| len > 1) {
1016                    match operand {
1017                        Operand::Copy(..) | Operand::Constant(..) | Operand::RuntimeChecks(_) => {
1018                            // These are always okay: direct use of a const, or a value that can
1019                            // evidently be copied.
1020                        }
1021                        Operand::Move(place) => {
1022                            // Make sure that repeated elements implement `Copy`.
1023                            let ty = place.ty(self.body, tcx).ty;
1024                            let trait_ref = ty::TraitRef::new(
1025                                tcx,
1026                                tcx.require_lang_item(LangItem::Copy, span),
1027                                [ty],
1028                            );
1029
1030                            self.prove_trait_ref(
1031                                trait_ref,
1032                                Locations::Single(location),
1033                                ConstraintCategory::CopyBound,
1034                            );
1035                        }
1036                    }
1037                }
1038            }
1039
1040            Rvalue::Cast(cast_kind, op, ty) => {
1041                match *cast_kind {
1042                    CastKind::PointerCoercion(
1043                        PointerCoercion::ReifyFnPointer(target_safety),
1044                        coercion_source,
1045                    ) => {
1046                        let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
1047                        let src_ty = op.ty(self.body, tcx);
1048                        let mut src_sig = src_ty.fn_sig(tcx);
1049                        if let ty::FnDef(def_id, _) = *src_ty.kind()
1050                            && let ty::FnPtr(_, target_hdr) = *ty.kind()
1051                            && tcx.codegen_fn_attrs(def_id).safe_target_features
1052                            && target_hdr.safety().is_safe()
1053                            && let Some(safe_sig) = tcx.adjust_target_feature_sig(
1054                                def_id,
1055                                src_sig,
1056                                self.body.source.def_id(),
1057                            )
1058                        {
1059                            src_sig = safe_sig;
1060                        }
1061
1062                        if src_sig.safety().is_safe() && target_safety.is_unsafe() {
1063                            src_sig = tcx.safe_to_unsafe_sig(src_sig);
1064                        }
1065
1066                        // HACK: This shouldn't be necessary... We can remove this when we actually
1067                        // get binders with where clauses, then elaborate implied bounds into that
1068                        // binder, and implement a higher-ranked subtyping algorithm that actually
1069                        // respects these implied bounds.
1070                        //
1071                        // This protects against the case where we are casting from a higher-ranked
1072                        // fn item to a non-higher-ranked fn pointer, where the cast throws away
1073                        // implied bounds that would've needed to be checked at the call site. This
1074                        // only works when we're casting to a non-higher-ranked fn ptr, since
1075                        // placeholders in the target signature could have untracked implied
1076                        // bounds, resulting in incorrect errors.
1077                        //
1078                        // We check that this signature is WF before subtyping the signature with
1079                        // the target fn sig.
1080                        if src_sig.has_bound_regions()
1081                            && let ty::FnPtr(target_fn_tys, target_hdr) = *ty.kind()
1082                            && let target_sig = target_fn_tys.with(target_hdr)
1083                            && let Some(target_sig) = target_sig.no_bound_vars()
1084                        {
1085                            let src_sig = self.infcx.instantiate_binder_with_fresh_vars(
1086                                span,
1087                                BoundRegionConversionTime::HigherRankedType,
1088                                src_sig,
1089                            );
1090                            let src_ty = Ty::new_fn_ptr(self.tcx(), ty::Binder::dummy(src_sig));
1091                            self.prove_clause(
1092                                ty::ClauseKind::WellFormed(src_ty.into()),
1093                                location.to_locations(),
1094                                ConstraintCategory::Cast {
1095                                    is_raw_ptr_dyn_type_cast: false,
1096                                    is_implicit_coercion,
1097                                    unsize_to: None,
1098                                },
1099                            );
1100
1101                            let src_ty =
1102                                self.normalize(ty::Unnormalized::new_wip(src_ty), location);
1103                            if let Err(terr) = self.sub_types(
1104                                src_ty,
1105                                *ty,
1106                                location.to_locations(),
1107                                ConstraintCategory::Cast {
1108                                    is_raw_ptr_dyn_type_cast: false,
1109                                    is_implicit_coercion,
1110                                    unsize_to: None,
1111                                },
1112                            ) {
1113                                span_mirbug!(
1114                                    self,
1115                                    rvalue,
1116                                    "equating {:?} with {:?} yields {:?}",
1117                                    target_sig,
1118                                    src_sig,
1119                                    terr
1120                                );
1121                            };
1122                        }
1123
1124                        let src_ty = Ty::new_fn_ptr(tcx, src_sig);
1125                        // HACK: We want to assert that the signature of the source fn is
1126                        // well-formed, because we don't enforce that via the WF of FnDef
1127                        // types normally. This should be removed when we improve the tracking
1128                        // of implied bounds of fn signatures.
1129                        self.prove_clause(
1130                            ty::ClauseKind::WellFormed(src_ty.into()),
1131                            location.to_locations(),
1132                            ConstraintCategory::Cast {
1133                                is_raw_ptr_dyn_type_cast: false,
1134                                is_implicit_coercion,
1135                                unsize_to: None,
1136                            },
1137                        );
1138
1139                        // The type that we see in the fcx is like
1140                        // `foo::<'a, 'b>`, where `foo` is the path to a
1141                        // function definition. When we extract the
1142                        // signature, it comes from the `fn_sig` query,
1143                        // and hence may contain unnormalized results.
1144                        let src_ty = self.normalize(ty::Unnormalized::new_wip(src_ty), location);
1145                        if let Err(terr) = self.sub_types(
1146                            src_ty,
1147                            *ty,
1148                            location.to_locations(),
1149                            ConstraintCategory::Cast {
1150                                is_raw_ptr_dyn_type_cast: false,
1151                                is_implicit_coercion,
1152                                unsize_to: None,
1153                            },
1154                        ) {
1155                            span_mirbug!(
1156                                self,
1157                                rvalue,
1158                                "equating {:?} with {:?} yields {:?}",
1159                                src_ty,
1160                                ty,
1161                                terr
1162                            );
1163                        }
1164                    }
1165
1166                    CastKind::PointerCoercion(
1167                        PointerCoercion::ClosureFnPointer(safety),
1168                        coercion_source,
1169                    ) => {
1170                        let sig = match op.ty(self.body, tcx).kind() {
1171                            ty::Closure(_, args) => args.as_closure().sig(),
1172                            _ => bug!(),
1173                        };
1174                        let ty_fn_ptr_from =
1175                            Ty::new_fn_ptr(tcx, tcx.signature_unclosure(sig, safety));
1176
1177                        let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
1178                        if let Err(terr) = self.sub_types(
1179                            ty_fn_ptr_from,
1180                            *ty,
1181                            location.to_locations(),
1182                            ConstraintCategory::Cast {
1183                                is_raw_ptr_dyn_type_cast: false,
1184                                is_implicit_coercion,
1185                                unsize_to: None,
1186                            },
1187                        ) {
1188                            span_mirbug!(
1189                                self,
1190                                rvalue,
1191                                "equating {:?} with {:?} yields {:?}",
1192                                ty_fn_ptr_from,
1193                                ty,
1194                                terr
1195                            );
1196                        }
1197                    }
1198
1199                    CastKind::PointerCoercion(
1200                        PointerCoercion::UnsafeFnPointer,
1201                        coercion_source,
1202                    ) => {
1203                        let fn_sig = op.ty(self.body, tcx).fn_sig(tcx);
1204
1205                        // The type that we see in the fcx is like
1206                        // `foo::<'a, 'b>`, where `foo` is the path to a
1207                        // function definition. When we extract the
1208                        // signature, it comes from the `fn_sig` query,
1209                        // and hence may contain unnormalized results.
1210                        let fn_sig = self.normalize(ty::Unnormalized::new_wip(fn_sig), location);
1211
1212                        let ty_fn_ptr_from = tcx.safe_to_unsafe_fn_ty(fn_sig);
1213
1214                        let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
1215                        if let Err(terr) = self.sub_types(
1216                            ty_fn_ptr_from,
1217                            *ty,
1218                            location.to_locations(),
1219                            ConstraintCategory::Cast {
1220                                is_raw_ptr_dyn_type_cast: false,
1221                                is_implicit_coercion,
1222                                unsize_to: None,
1223                            },
1224                        ) {
1225                            span_mirbug!(
1226                                self,
1227                                rvalue,
1228                                "equating {:?} with {:?} yields {:?}",
1229                                ty_fn_ptr_from,
1230                                ty,
1231                                terr
1232                            );
1233                        }
1234                    }
1235
1236                    CastKind::PointerCoercion(PointerCoercion::Unsize, coercion_source) => {
1237                        let &ty = ty;
1238                        let trait_ref = ty::TraitRef::new(
1239                            tcx,
1240                            tcx.require_lang_item(LangItem::CoerceUnsized, span),
1241                            [op.ty(self.body, tcx), ty],
1242                        );
1243
1244                        let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
1245                        let unsize_to = fold_regions(tcx, ty, |r, _| {
1246                            if let ty::ReVar(_) = r.kind() { tcx.lifetimes.re_erased } else { r }
1247                        });
1248                        self.prove_trait_ref(
1249                            trait_ref,
1250                            location.to_locations(),
1251                            ConstraintCategory::Cast {
1252                                is_raw_ptr_dyn_type_cast: false,
1253                                is_implicit_coercion,
1254                                unsize_to: Some(unsize_to),
1255                            },
1256                        );
1257                    }
1258
1259                    CastKind::PointerCoercion(
1260                        PointerCoercion::MutToConstPointer,
1261                        coercion_source,
1262                    ) => {
1263                        let ty::RawPtr(ty_from, hir::Mutability::Mut) =
1264                            op.ty(self.body, tcx).kind()
1265                        else {
1266                            span_mirbug!(self, rvalue, "unexpected base type for cast {:?}", ty,);
1267                            return;
1268                        };
1269                        let ty::RawPtr(ty_to, hir::Mutability::Not) = ty.kind() else {
1270                            span_mirbug!(self, rvalue, "unexpected target type for cast {:?}", ty,);
1271                            return;
1272                        };
1273                        let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
1274                        if let Err(terr) = self.sub_types(
1275                            *ty_from,
1276                            *ty_to,
1277                            location.to_locations(),
1278                            ConstraintCategory::Cast {
1279                                is_raw_ptr_dyn_type_cast: false,
1280                                is_implicit_coercion,
1281                                unsize_to: None,
1282                            },
1283                        ) {
1284                            span_mirbug!(
1285                                self,
1286                                rvalue,
1287                                "relating {:?} with {:?} yields {:?}",
1288                                ty_from,
1289                                ty_to,
1290                                terr
1291                            );
1292                        }
1293                    }
1294
1295                    CastKind::PointerCoercion(PointerCoercion::ArrayToPointer, coercion_source) => {
1296                        let ty_from = op.ty(self.body, tcx);
1297
1298                        let opt_ty_elem_mut = match ty_from.kind() {
1299                            ty::RawPtr(array_ty, array_mut) => match array_ty.kind() {
1300                                ty::Array(ty_elem, _) => Some((ty_elem, *array_mut)),
1301                                _ => None,
1302                            },
1303                            _ => None,
1304                        };
1305
1306                        let Some((ty_elem, ty_mut)) = opt_ty_elem_mut else {
1307                            span_mirbug!(
1308                                self,
1309                                rvalue,
1310                                "ArrayToPointer cast from unexpected type {:?}",
1311                                ty_from,
1312                            );
1313                            return;
1314                        };
1315
1316                        let (ty_to, ty_to_mut) = match ty.kind() {
1317                            ty::RawPtr(ty_to, ty_to_mut) => (ty_to, *ty_to_mut),
1318                            _ => {
1319                                span_mirbug!(
1320                                    self,
1321                                    rvalue,
1322                                    "ArrayToPointer cast to unexpected type {:?}",
1323                                    ty,
1324                                );
1325                                return;
1326                            }
1327                        };
1328
1329                        if ty_to_mut.is_mut() && ty_mut.is_not() {
1330                            span_mirbug!(
1331                                self,
1332                                rvalue,
1333                                "ArrayToPointer cast from const {:?} to mut {:?}",
1334                                ty,
1335                                ty_to
1336                            );
1337                            return;
1338                        }
1339
1340                        let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
1341                        if let Err(terr) = self.sub_types(
1342                            *ty_elem,
1343                            *ty_to,
1344                            location.to_locations(),
1345                            ConstraintCategory::Cast {
1346                                is_raw_ptr_dyn_type_cast: false,
1347                                is_implicit_coercion,
1348                                unsize_to: None,
1349                            },
1350                        ) {
1351                            span_mirbug!(
1352                                self,
1353                                rvalue,
1354                                "relating {:?} with {:?} yields {:?}",
1355                                ty_elem,
1356                                ty_to,
1357                                terr
1358                            )
1359                        }
1360                    }
1361
1362                    CastKind::PointerExposeProvenance => {
1363                        let ty_from = op.ty(self.body, tcx);
1364                        let cast_ty_from = CastTy::from_ty(ty_from);
1365                        let cast_ty_to = CastTy::from_ty(*ty);
1366                        match (cast_ty_from, cast_ty_to) {
1367                            (Some(CastTy::Ptr(_) | CastTy::FnPtr), Some(CastTy::Int(_))) => (),
1368                            _ => {
1369                                span_mirbug!(
1370                                    self,
1371                                    rvalue,
1372                                    "Invalid PointerExposeProvenance cast {:?} -> {:?}",
1373                                    ty_from,
1374                                    ty
1375                                )
1376                            }
1377                        }
1378                    }
1379
1380                    CastKind::PointerWithExposedProvenance => {
1381                        let ty_from = op.ty(self.body, tcx);
1382                        let cast_ty_from = CastTy::from_ty(ty_from);
1383                        let cast_ty_to = CastTy::from_ty(*ty);
1384                        match (cast_ty_from, cast_ty_to) {
1385                            (Some(CastTy::Int(_)), Some(CastTy::Ptr(_))) => (),
1386                            _ => {
1387                                span_mirbug!(
1388                                    self,
1389                                    rvalue,
1390                                    "Invalid PointerWithExposedProvenance cast {:?} -> {:?}",
1391                                    ty_from,
1392                                    ty
1393                                )
1394                            }
1395                        }
1396                    }
1397                    CastKind::IntToInt => {
1398                        let ty_from = op.ty(self.body, tcx);
1399                        let cast_ty_from = CastTy::from_ty(ty_from);
1400                        let cast_ty_to = CastTy::from_ty(*ty);
1401                        match (cast_ty_from, cast_ty_to) {
1402                            (Some(CastTy::Int(_)), Some(CastTy::Int(_))) => (),
1403                            _ => {
1404                                span_mirbug!(
1405                                    self,
1406                                    rvalue,
1407                                    "Invalid IntToInt cast {:?} -> {:?}",
1408                                    ty_from,
1409                                    ty
1410                                )
1411                            }
1412                        }
1413                    }
1414                    CastKind::IntToFloat => {
1415                        let ty_from = op.ty(self.body, tcx);
1416                        let cast_ty_from = CastTy::from_ty(ty_from);
1417                        let cast_ty_to = CastTy::from_ty(*ty);
1418                        match (cast_ty_from, cast_ty_to) {
1419                            (Some(CastTy::Int(_)), Some(CastTy::Float)) => (),
1420                            _ => {
1421                                span_mirbug!(
1422                                    self,
1423                                    rvalue,
1424                                    "Invalid IntToFloat cast {:?} -> {:?}",
1425                                    ty_from,
1426                                    ty
1427                                )
1428                            }
1429                        }
1430                    }
1431                    CastKind::FloatToInt => {
1432                        let ty_from = op.ty(self.body, tcx);
1433                        let cast_ty_from = CastTy::from_ty(ty_from);
1434                        let cast_ty_to = CastTy::from_ty(*ty);
1435                        match (cast_ty_from, cast_ty_to) {
1436                            (Some(CastTy::Float), Some(CastTy::Int(_))) => (),
1437                            _ => {
1438                                span_mirbug!(
1439                                    self,
1440                                    rvalue,
1441                                    "Invalid FloatToInt cast {:?} -> {:?}",
1442                                    ty_from,
1443                                    ty
1444                                )
1445                            }
1446                        }
1447                    }
1448                    CastKind::FloatToFloat => {
1449                        let ty_from = op.ty(self.body, tcx);
1450                        let cast_ty_from = CastTy::from_ty(ty_from);
1451                        let cast_ty_to = CastTy::from_ty(*ty);
1452                        match (cast_ty_from, cast_ty_to) {
1453                            (Some(CastTy::Float), Some(CastTy::Float)) => (),
1454                            _ => {
1455                                span_mirbug!(
1456                                    self,
1457                                    rvalue,
1458                                    "Invalid FloatToFloat cast {:?} -> {:?}",
1459                                    ty_from,
1460                                    ty
1461                                )
1462                            }
1463                        }
1464                    }
1465                    CastKind::FnPtrToPtr => {
1466                        let ty_from = op.ty(self.body, tcx);
1467                        let cast_ty_from = CastTy::from_ty(ty_from);
1468                        let cast_ty_to = CastTy::from_ty(*ty);
1469                        match (cast_ty_from, cast_ty_to) {
1470                            (Some(CastTy::FnPtr), Some(CastTy::Ptr(_))) => (),
1471                            _ => {
1472                                span_mirbug!(
1473                                    self,
1474                                    rvalue,
1475                                    "Invalid FnPtrToPtr cast {:?} -> {:?}",
1476                                    ty_from,
1477                                    ty
1478                                )
1479                            }
1480                        }
1481                    }
1482                    CastKind::PtrToPtr => {
1483                        let ty_from = op.ty(self.body, tcx);
1484                        let Some(CastTy::Ptr(src)) = CastTy::from_ty(ty_from) else {
1485                            unreachable!();
1486                        };
1487                        let Some(CastTy::Ptr(dst)) = CastTy::from_ty(*ty) else {
1488                            unreachable!();
1489                        };
1490
1491                        if self.infcx.type_is_sized_modulo_regions(self.infcx.param_env, dst.ty) {
1492                            // Wide to thin ptr cast. This may even occur in an env with
1493                            // impossible clauses, such as `where dyn Trait: Sized`.
1494                            // In this case, we don't want to fall into the case below,
1495                            // since the types may not actually be equatable, but it's
1496                            // fine to perform this operation in an impossible env.
1497                            let trait_ref = ty::TraitRef::new(
1498                                tcx,
1499                                tcx.require_lang_item(LangItem::Sized, self.last_span),
1500                                [dst.ty],
1501                            );
1502                            self.prove_trait_ref(
1503                                trait_ref,
1504                                location.to_locations(),
1505                                ConstraintCategory::Cast {
1506                                    is_raw_ptr_dyn_type_cast: false,
1507                                    is_implicit_coercion: true,
1508                                    unsize_to: None,
1509                                },
1510                            );
1511                        } else if let ty::Dynamic(src_tty, src_lt) =
1512                            *self.struct_tail(src.ty, location).kind()
1513                            && let ty::Dynamic(dst_tty, dst_lt) =
1514                                *self.struct_tail(dst.ty, location).kind()
1515                        {
1516                            match (src_tty.principal(), dst_tty.principal()) {
1517                                (Some(_), Some(_)) => {
1518                                    // This checks (lifetime part of) vtable validity for pointer casts,
1519                                    // which is irrelevant when there are aren't principal traits on
1520                                    // both sides (aka only auto traits).
1521                                    //
1522                                    // Note that other checks (such as denying `dyn Send` -> `dyn
1523                                    // Debug`) are in `rustc_hir_typeck`.
1524
1525                                    // Remove auto traits.
1526                                    // Auto trait checks are handled in `rustc_hir_typeck`.
1527                                    let src_obj = Ty::new_dynamic(
1528                                        tcx,
1529                                        tcx.mk_poly_existential_predicates(
1530                                            &src_tty.without_auto_traits().collect::<Vec<_>>(),
1531                                        ),
1532                                        src_lt,
1533                                    );
1534                                    let dst_obj = Ty::new_dynamic(
1535                                        tcx,
1536                                        tcx.mk_poly_existential_predicates(
1537                                            &dst_tty.without_auto_traits().collect::<Vec<_>>(),
1538                                        ),
1539                                        dst_lt,
1540                                    );
1541
1542                                    debug!(?src_tty, ?dst_tty, ?src_obj, ?dst_obj);
1543
1544                                    // Trait parameters are invariant, the only part that actually has
1545                                    // subtyping here is the lifetime bound of the dyn-type.
1546                                    //
1547                                    // For example in `dyn Trait<'a> + 'b <: dyn Trait<'c> + 'd`  we would
1548                                    // require that `'a == 'c` but only that `'b: 'd`.
1549                                    //
1550                                    // We must not allow freely casting lifetime bounds of dyn-types as it
1551                                    // may allow for inaccessible VTable methods being callable: #136702
1552                                    self.sub_types(
1553                                        src_obj,
1554                                        dst_obj,
1555                                        location.to_locations(),
1556                                        ConstraintCategory::Cast {
1557                                            is_raw_ptr_dyn_type_cast: true,
1558                                            is_implicit_coercion: false,
1559                                            unsize_to: None,
1560                                        },
1561                                    )
1562                                    .unwrap();
1563                                }
1564                                (None, None) => {
1565                                    // `struct_tail` returns regions which haven't been mapped
1566                                    // to nll vars yet so we do it here as `outlives_constraints`
1567                                    // expects nll vars.
1568                                    let src_lt = self.universal_regions.to_region_vid(src_lt);
1569                                    let dst_lt = self.universal_regions.to_region_vid(dst_lt);
1570
1571                                    // The principalless (no non-auto traits) case:
1572                                    // You can only cast `dyn Send + 'long` to `dyn Send + 'short`.
1573                                    self.constraints.outlives_constraints.push(
1574                                        OutlivesConstraint {
1575                                            sup: src_lt,
1576                                            sub: dst_lt,
1577                                            locations: location.to_locations(),
1578                                            span: location.to_locations().span(self.body),
1579                                            category: ConstraintCategory::Cast {
1580                                                is_raw_ptr_dyn_type_cast: true,
1581                                                is_implicit_coercion: false,
1582                                                unsize_to: None,
1583                                            },
1584                                            variance_info: ty::VarianceDiagInfo::default(),
1585                                            from_closure: false,
1586                                        },
1587                                    );
1588                                }
1589                                (None, Some(_)) => bug!(
1590                                    "introducing a principal should have errored in HIR typeck"
1591                                ),
1592                                (Some(_), None) => {
1593                                    bug!("dropping the principal should have been an unsizing cast")
1594                                }
1595                            }
1596                        }
1597                    }
1598                    CastKind::Transmute => {
1599                        let ty_from = op.ty(self.body, tcx);
1600                        match ty_from.kind() {
1601                            ty::Pat(base, _) if base == ty => {}
1602                            _ => span_mirbug!(
1603                                self,
1604                                rvalue,
1605                                "Unexpected CastKind::Transmute {ty_from:?} -> {ty:?}, which is not permitted in Analysis MIR",
1606                            ),
1607                        }
1608                    }
1609                    CastKind::Subtype | CastKind::BoxDerefTransmute => {
1610                        bug!("CastKind::{cast_kind:?} shouldn't exist in borrowck")
1611                    }
1612                }
1613            }
1614
1615            Rvalue::Ref(region, _borrow_kind, borrowed_place) => {
1616                self.add_reborrow_constraint(location, *region, borrowed_place);
1617            }
1618
1619            Rvalue::Reborrow(target, mutability, borrowed_place) => {
1620                self.add_generic_reborrow_constraint(
1621                    *mutability,
1622                    location,
1623                    borrowed_place,
1624                    *target,
1625                );
1626            }
1627
1628            Rvalue::BinaryOp(
1629                BinOp::Eq | BinOp::Ne | BinOp::Lt | BinOp::Le | BinOp::Gt | BinOp::Ge,
1630                (left, right),
1631            ) => {
1632                let ty_left = left.ty(self.body, tcx);
1633                match ty_left.kind() {
1634                    // Types with regions are comparable if they have a common super-type.
1635                    ty::RawPtr(_, _) | ty::FnPtr(..) => {
1636                        let ty_right = right.ty(self.body, tcx);
1637                        let common_ty =
1638                            self.infcx.next_ty_var(self.body.source_info(location).span);
1639                        self.sub_types(
1640                            ty_left,
1641                            common_ty,
1642                            location.to_locations(),
1643                            ConstraintCategory::CallArgument(None),
1644                        )
1645                        .unwrap_or_else(|err| {
1646                            bug!("Could not equate type variable with {:?}: {:?}", ty_left, err)
1647                        });
1648                        if let Err(terr) = self.sub_types(
1649                            ty_right,
1650                            common_ty,
1651                            location.to_locations(),
1652                            ConstraintCategory::CallArgument(None),
1653                        ) {
1654                            span_mirbug!(
1655                                self,
1656                                rvalue,
1657                                "unexpected comparison types {:?} and {:?} yields {:?}",
1658                                ty_left,
1659                                ty_right,
1660                                terr
1661                            )
1662                        }
1663                    }
1664                    // For types with no regions we can just check that the
1665                    // both operands have the same type.
1666                    ty::Int(_) | ty::Uint(_) | ty::Bool | ty::Char | ty::Float(_)
1667                        if ty_left == right.ty(self.body, tcx) => {}
1668                    // Other types are compared by trait methods, not by
1669                    // `Rvalue::BinaryOp`.
1670                    _ => span_mirbug!(
1671                        self,
1672                        rvalue,
1673                        "unexpected comparison types {:?} and {:?}",
1674                        ty_left,
1675                        right.ty(self.body, tcx)
1676                    ),
1677                }
1678            }
1679
1680            Rvalue::WrapUnsafeBinder(op, ty) => {
1681                let operand_ty = op.ty(self.body, self.tcx());
1682                let ty::UnsafeBinder(binder_ty) = *ty.kind() else {
1683                    unreachable!();
1684                };
1685                let expected_ty = self.infcx.instantiate_binder_with_fresh_vars(
1686                    self.body().source_info(location).span,
1687                    BoundRegionConversionTime::HigherRankedType,
1688                    binder_ty.into(),
1689                );
1690                self.sub_types(
1691                    operand_ty,
1692                    expected_ty,
1693                    location.to_locations(),
1694                    ConstraintCategory::Boring,
1695                )
1696                .unwrap();
1697            }
1698
1699            Rvalue::Use(_, _)
1700            | Rvalue::UnaryOp(_, _)
1701            | Rvalue::CopyForDeref(_)
1702            | Rvalue::BinaryOp(..)
1703            | Rvalue::RawPtr(..)
1704            | Rvalue::ThreadLocalRef(..)
1705            | Rvalue::Discriminant(..) => {}
1706        }
1707    }
1708
1709    #[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("visit_operand",
                                    "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1709u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("op")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("op");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("location")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("location");
                                                        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(&op)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&location)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            self.super_operand(op, location);
            if let Operand::Constant(constant) = op {
                let maybe_uneval =
                    match constant.const_ {
                        Const::Val(..) | Const::Ty(_, _) => None,
                        Const::Unevaluated(uv, _) => Some(uv),
                    };
                if let Some(uv) = maybe_uneval {
                    if uv.promoted.is_none() {
                        let tcx = self.tcx();
                        let def_id = uv.def;
                        if tcx.def_kind(def_id) == DefKind::AnonConst &&
                                tcx.anon_const_kind(def_id) ==
                                    ty::AnonConstKind::NonTypeSystemInline {
                            let def_id = def_id.expect_local();
                            let clauses =
                                self.prove_closure_bounds(tcx, def_id, uv.args, location);
                            self.normalize_and_prove_instantiated_clauses(def_id.to_def_id(),
                                clauses, location.to_locations());
                        }
                    }
                }
            }
        }
    }
}#[instrument(level = "debug", skip(self))]
1710    fn visit_operand(&mut self, op: &Operand<'tcx>, location: Location) {
1711        self.super_operand(op, location);
1712        if let Operand::Constant(constant) = op {
1713            let maybe_uneval = match constant.const_ {
1714                Const::Val(..) | Const::Ty(_, _) => None,
1715                Const::Unevaluated(uv, _) => Some(uv),
1716            };
1717
1718            if let Some(uv) = maybe_uneval {
1719                if uv.promoted.is_none() {
1720                    let tcx = self.tcx();
1721                    let def_id = uv.def;
1722                    if tcx.def_kind(def_id) == DefKind::AnonConst
1723                        && tcx.anon_const_kind(def_id) == ty::AnonConstKind::NonTypeSystemInline
1724                    {
1725                        let def_id = def_id.expect_local();
1726                        let clauses = self.prove_closure_bounds(tcx, def_id, uv.args, location);
1727                        self.normalize_and_prove_instantiated_clauses(
1728                            def_id.to_def_id(),
1729                            clauses,
1730                            location.to_locations(),
1731                        );
1732                    }
1733                }
1734            }
1735        }
1736    }
1737
1738    #[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("visit_const_operand",
                                    "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(1738u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("constant")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("constant");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("location")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("location");
                                                        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(&constant)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&location)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            self.super_const_operand(constant, location);
            let ty = constant.const_.ty();
            self.infcx.tcx.for_each_free_region(&ty,
                |live_region|
                    {
                        let live_region_vid =
                            self.universal_regions.to_region_vid(live_region);
                        self.constraints.liveness_constraints.add_location(live_region_vid,
                            location);
                    });
            let locations = location.to_locations();
            if let Some(annotation_index) = constant.user_ty {
                if let Err(terr) =
                        self.relate_type_and_user_type(constant.const_.ty(),
                            ty::Invariant,
                            &UserTypeProjection {
                                    base: annotation_index,
                                    projs: ::alloc::vec::Vec::new(),
                                }, locations,
                            ConstraintCategory::TypeAnnotation(AnnotationSource::GenericArg))
                    {
                    let annotation =
                        &self.user_type_annotations[annotation_index];
                    {
                        crate::type_check::mirbug(self.tcx(), self.last_span,
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                            self.body().source.def_id(), constant,
                                            format_args!("bad constant user type {0:?} vs {1:?}: {2:?}",
                                                annotation, constant.const_.ty(), terr)))
                                }))
                    };
                }
            } else {
                let tcx = self.tcx();
                let maybe_uneval =
                    match constant.const_ {
                        Const::Ty(_, ct) =>
                            match ct.kind() {
                                ty::ConstKind::Alias(_, alias_const) =>
                                    match alias_const.kind {
                                        ty::AliasConstKind::Projection { def_id } |
                                            ty::AliasConstKind::Inherent { def_id } |
                                            ty::AliasConstKind::Free { def_id } |
                                            ty::AliasConstKind::Anon { def_id } =>
                                            Some(UnevaluatedConst {
                                                    def: def_id,
                                                    args: alias_const.args,
                                                    promoted: None,
                                                }),
                                    },
                                _ => None,
                            },
                        Const::Unevaluated(uv, _) => Some(uv),
                        _ => None,
                    };
                if let Some(uv) = maybe_uneval {
                    if let Some(promoted) = uv.promoted {
                        let promoted_body = &self.promoted[promoted];
                        self.check_promoted(promoted_body, location);
                        let promoted_ty = promoted_body.return_ty();
                        if let Err(terr) =
                                self.eq_types(ty, promoted_ty, locations,
                                    ConstraintCategory::Boring) {
                            {
                                crate::type_check::mirbug(self.tcx(), self.last_span,
                                    ::alloc::__export::must_use({
                                            ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                    self.body().source.def_id(), promoted,
                                                    format_args!("bad promoted type ({0:?}: {1:?}): {2:?}", ty,
                                                        promoted_ty, terr)))
                                        }))
                            };
                        };
                    } else {
                        self.ascribe_user_type(constant.const_.ty(),
                            ty::UserType::new(ty::UserTypeKind::TypeOf(uv.def,
                                    UserArgs { args: uv.args, user_self_ty: None })),
                            locations.span(self.body));
                    }
                } else if let Some(static_def_id) =
                        constant.check_static_ptr(tcx) {
                    let unnormalized_ty =
                        tcx.type_of(static_def_id).instantiate_identity();
                    let normalized_ty =
                        self.normalize(unnormalized_ty, locations);
                    let literal_ty =
                        constant.const_.ty().builtin_deref(true).unwrap();
                    if let Err(terr) =
                            self.eq_types(literal_ty, normalized_ty, locations,
                                ConstraintCategory::Boring) {
                        {
                            crate::type_check::mirbug(self.tcx(), self.last_span,
                                ::alloc::__export::must_use({
                                        ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                                self.body().source.def_id(), constant,
                                                format_args!("bad static type {0:?} ({1:?})", constant,
                                                    terr)))
                                    }))
                        };
                    }
                } else if let Const::Ty(_, ct) = constant.const_ &&
                        let ty::ConstKind::Param(p) = ct.kind() {
                    let body_def_id =
                        self.universal_regions.defining_ty.def_id();
                    let const_param =
                        tcx.generics_of(body_def_id).const_param(p, tcx);
                    self.ascribe_user_type(constant.const_.ty(),
                        ty::UserType::new(ty::UserTypeKind::TypeOf(const_param.def_id,
                                UserArgs {
                                    args: self.universal_regions.defining_ty.args(),
                                    user_self_ty: None,
                                })), locations.span(self.body));
                }
                if let ty::FnDef(def_id, args) = *constant.const_.ty().kind()
                    {
                    let args = args.no_bound_vars().unwrap();
                    let instantiated_clauses =
                        tcx.clauses_of(def_id).instantiate(tcx, args);
                    self.normalize_and_prove_instantiated_clauses(def_id,
                        instantiated_clauses, locations);
                    {
                        match (&tcx.trait_impl_of_assoc(def_id), &None) {
                            (left_val, right_val) => {
                                if !(*left_val == *right_val) {
                                    let kind = ::core::panicking::AssertKind::Eq;
                                    ::core::panicking::assert_failed(kind, &*left_val,
                                        &*right_val, ::core::option::Option::None);
                                }
                            }
                        }
                    };
                    self.prove_clauses(args.types().map(|ty|
                                ty::ClauseKind::WellFormed(ty.into())), locations,
                        ConstraintCategory::Boring);
                }
            }
        }
    }
}#[instrument(level = "debug", skip(self))]
1739    fn visit_const_operand(&mut self, constant: &ConstOperand<'tcx>, location: Location) {
1740        self.super_const_operand(constant, location);
1741        let ty = constant.const_.ty();
1742
1743        self.infcx.tcx.for_each_free_region(&ty, |live_region| {
1744            let live_region_vid = self.universal_regions.to_region_vid(live_region);
1745            self.constraints.liveness_constraints.add_location(live_region_vid, location);
1746        });
1747
1748        let locations = location.to_locations();
1749        if let Some(annotation_index) = constant.user_ty {
1750            if let Err(terr) = self.relate_type_and_user_type(
1751                constant.const_.ty(),
1752                ty::Invariant,
1753                &UserTypeProjection { base: annotation_index, projs: vec![] },
1754                locations,
1755                ConstraintCategory::TypeAnnotation(AnnotationSource::GenericArg),
1756            ) {
1757                let annotation = &self.user_type_annotations[annotation_index];
1758                span_mirbug!(
1759                    self,
1760                    constant,
1761                    "bad constant user type {:?} vs {:?}: {:?}",
1762                    annotation,
1763                    constant.const_.ty(),
1764                    terr,
1765                );
1766            }
1767        } else {
1768            let tcx = self.tcx();
1769            let maybe_uneval = match constant.const_ {
1770                Const::Ty(_, ct) => match ct.kind() {
1771                    ty::ConstKind::Alias(_, alias_const) => match alias_const.kind {
1772                        ty::AliasConstKind::Projection { def_id }
1773                        | ty::AliasConstKind::Inherent { def_id }
1774                        | ty::AliasConstKind::Free { def_id }
1775                        | ty::AliasConstKind::Anon { def_id } => Some(UnevaluatedConst {
1776                            def: def_id,
1777                            args: alias_const.args,
1778                            promoted: None,
1779                        }),
1780                    },
1781                    _ => None,
1782                },
1783                Const::Unevaluated(uv, _) => Some(uv),
1784                _ => None,
1785            };
1786
1787            if let Some(uv) = maybe_uneval {
1788                if let Some(promoted) = uv.promoted {
1789                    let promoted_body = &self.promoted[promoted];
1790                    self.check_promoted(promoted_body, location);
1791                    let promoted_ty = promoted_body.return_ty();
1792                    if let Err(terr) =
1793                        self.eq_types(ty, promoted_ty, locations, ConstraintCategory::Boring)
1794                    {
1795                        span_mirbug!(
1796                            self,
1797                            promoted,
1798                            "bad promoted type ({:?}: {:?}): {:?}",
1799                            ty,
1800                            promoted_ty,
1801                            terr
1802                        );
1803                    };
1804                } else {
1805                    self.ascribe_user_type(
1806                        constant.const_.ty(),
1807                        ty::UserType::new(ty::UserTypeKind::TypeOf(
1808                            uv.def,
1809                            UserArgs { args: uv.args, user_self_ty: None },
1810                        )),
1811                        locations.span(self.body),
1812                    );
1813                }
1814            } else if let Some(static_def_id) = constant.check_static_ptr(tcx) {
1815                let unnormalized_ty = tcx.type_of(static_def_id).instantiate_identity();
1816                let normalized_ty = self.normalize(unnormalized_ty, locations);
1817                let literal_ty = constant.const_.ty().builtin_deref(true).unwrap();
1818
1819                if let Err(terr) =
1820                    self.eq_types(literal_ty, normalized_ty, locations, ConstraintCategory::Boring)
1821                {
1822                    span_mirbug!(self, constant, "bad static type {:?} ({:?})", constant, terr);
1823                }
1824            } else if let Const::Ty(_, ct) = constant.const_
1825                && let ty::ConstKind::Param(p) = ct.kind()
1826            {
1827                let body_def_id = self.universal_regions.defining_ty.def_id();
1828                let const_param = tcx.generics_of(body_def_id).const_param(p, tcx);
1829                self.ascribe_user_type(
1830                    constant.const_.ty(),
1831                    ty::UserType::new(ty::UserTypeKind::TypeOf(
1832                        const_param.def_id,
1833                        UserArgs {
1834                            args: self.universal_regions.defining_ty.args(),
1835                            user_self_ty: None,
1836                        },
1837                    )),
1838                    locations.span(self.body),
1839                );
1840            }
1841
1842            if let ty::FnDef(def_id, args) = *constant.const_.ty().kind() {
1843                let args = args.no_bound_vars().unwrap();
1844                let instantiated_clauses = tcx.clauses_of(def_id).instantiate(tcx, args);
1845                self.normalize_and_prove_instantiated_clauses(
1846                    def_id,
1847                    instantiated_clauses,
1848                    locations,
1849                );
1850
1851                assert_eq!(tcx.trait_impl_of_assoc(def_id), None);
1852                self.prove_clauses(
1853                    args.types().map(|ty| ty::ClauseKind::WellFormed(ty.into())),
1854                    locations,
1855                    ConstraintCategory::Boring,
1856                );
1857            }
1858        }
1859    }
1860
1861    fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, location: Location) {
1862        self.super_place(place, context, location);
1863        let tcx = self.tcx();
1864        let place_ty = place.ty(self.body, tcx);
1865        if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context {
1866            let trait_ref = ty::TraitRef::new(
1867                tcx,
1868                tcx.require_lang_item(LangItem::Copy, self.last_span),
1869                [place_ty.ty],
1870            );
1871
1872            // To have a `Copy` operand, the type `T` of the
1873            // value must be `Copy`. Note that we prove that `T: Copy`,
1874            // rather than using the `is_copy_modulo_regions`
1875            // test. This is important because
1876            // `is_copy_modulo_regions` ignores the resulting region
1877            // obligations and assumes they pass. This can result in
1878            // bounds from `Copy` impls being unsoundly ignored (e.g.,
1879            // #29149). Note that we decide to use `Copy` before knowing
1880            // whether the bounds fully apply: in effect, the rule is
1881            // that if a value of some type could implement `Copy`, then
1882            // it must.
1883            self.prove_trait_ref(trait_ref, location.to_locations(), ConstraintCategory::CopyBound);
1884        }
1885    }
1886
1887    fn visit_projection_elem(
1888        &mut self,
1889        place: PlaceRef<'tcx>,
1890        elem: PlaceElem<'tcx>,
1891        context: PlaceContext,
1892        location: Location,
1893    ) {
1894        let tcx = self.tcx();
1895        let base_ty = place.ty(self.body(), tcx);
1896        match elem {
1897            // All these projections don't add any constraints, so there's nothing to
1898            // do here. We check their invariants in the MIR validator after all.
1899            ProjectionElem::Deref
1900            | ProjectionElem::Index(_)
1901            | ProjectionElem::ConstantIndex { .. }
1902            | ProjectionElem::Subslice { .. }
1903            | ProjectionElem::Downcast(..) => {}
1904            ProjectionElem::Field(field, fty) => {
1905                let fty = self.normalize(ty::Unnormalized::new_wip(fty), location);
1906                let ty = PlaceTy::field_ty(tcx, base_ty.ty, base_ty.variant_index, field);
1907                let ty = self.normalize(ty, location);
1908                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/mod.rs:1908",
                        "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(1908u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("fty")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("fty");
                                            NAME.as_str()
                                        },
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("ty")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("ty");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::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(&fty)
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ty)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?fty, ?ty);
1909
1910                if let Err(terr) = self.relate_types(
1911                    ty,
1912                    context.ambient_variance(),
1913                    fty,
1914                    location.to_locations(),
1915                    ConstraintCategory::Boring,
1916                ) {
1917                    {
    crate::type_check::mirbug(self.tcx(), self.last_span,
        ::alloc::__export::must_use({
                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                        self.body().source.def_id(), place,
                        format_args!("bad field access ({0:?}: {1:?}): {2:?}", ty,
                            fty, terr)))
            }))
};span_mirbug!(self, place, "bad field access ({:?}: {:?}): {:?}", ty, fty, terr);
1918                }
1919            }
1920            ProjectionElem::OpaqueCast(ty) => {
1921                let ty = self.normalize(ty::Unnormalized::new_wip(ty), location);
1922                self.relate_types(
1923                    ty,
1924                    context.ambient_variance(),
1925                    base_ty.ty,
1926                    location.to_locations(),
1927                    ConstraintCategory::TypeAnnotation(AnnotationSource::OpaqueCast),
1928                )
1929                .unwrap();
1930            }
1931            ProjectionElem::UnwrapUnsafeBinder(ty) => {
1932                let ty::UnsafeBinder(binder_ty) = *base_ty.ty.kind() else {
1933                    ::core::panicking::panic("internal error: entered unreachable code");unreachable!();
1934                };
1935                let found_ty = self.infcx.instantiate_binder_with_fresh_vars(
1936                    self.body.source_info(location).span,
1937                    BoundRegionConversionTime::HigherRankedType,
1938                    binder_ty.into(),
1939                );
1940                self.relate_types(
1941                    ty,
1942                    context.ambient_variance(),
1943                    found_ty,
1944                    location.to_locations(),
1945                    ConstraintCategory::Boring,
1946                )
1947                .unwrap();
1948            }
1949        }
1950    }
1951}
1952
1953impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
1954    fn check_call_dest(
1955        &mut self,
1956        term: &Terminator<'tcx>,
1957        sig: &ty::FnSig<'tcx>,
1958        destination: Place<'tcx>,
1959        is_diverging: bool,
1960        term_location: Location,
1961    ) {
1962        let tcx = self.tcx();
1963        if is_diverging {
1964            // The signature in this call can reference region variables,
1965            // so erase them before calling a query.
1966            let output_ty = self.tcx().erase_and_anonymize_regions(sig.output());
1967            if !output_ty
1968                .is_privately_uninhabited(self.tcx(), self.infcx.typing_env(self.infcx.param_env))
1969            {
1970                {
    crate::type_check::mirbug(self.tcx(), self.last_span,
        ::alloc::__export::must_use({
                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                        self.body().source.def_id(), term,
                        format_args!("call to non-diverging function {0:?} w/o dest",
                            sig)))
            }))
};span_mirbug!(self, term, "call to non-diverging function {:?} w/o dest", sig);
1971            }
1972        } else {
1973            let dest_ty = destination.ty(self.body, tcx).ty;
1974            let dest_ty = self.normalize(ty::Unnormalized::new_wip(dest_ty), term_location);
1975            let category = match destination.as_local() {
1976                Some(RETURN_PLACE) => {
1977                    if let DefiningTy::Const(def_id, _) | DefiningTy::InlineConst(def_id, _) =
1978                        self.universal_regions.defining_ty
1979                    {
1980                        if tcx.is_static(def_id) {
1981                            ConstraintCategory::UseAsStatic
1982                        } else {
1983                            ConstraintCategory::UseAsConst
1984                        }
1985                    } else {
1986                        ConstraintCategory::Return(ReturnConstraint::Normal)
1987                    }
1988                }
1989                Some(l) if !self.body.local_decls[l].is_user_variable() => {
1990                    ConstraintCategory::Boring
1991                }
1992                // The return type of a call is interesting for diagnostics.
1993                _ => ConstraintCategory::Assignment,
1994            };
1995
1996            let locations = term_location.to_locations();
1997
1998            if let Err(terr) = self.sub_types(sig.output(), dest_ty, locations, category) {
1999                {
    crate::type_check::mirbug(self.tcx(), self.last_span,
        ::alloc::__export::must_use({
                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                        self.body().source.def_id(), term,
                        format_args!("call dest mismatch ({0:?} <- {1:?}): {2:?}",
                            dest_ty, sig.output(), terr)))
            }))
};span_mirbug!(
2000                    self,
2001                    term,
2002                    "call dest mismatch ({:?} <- {:?}): {:?}",
2003                    dest_ty,
2004                    sig.output(),
2005                    terr
2006                );
2007            }
2008
2009            // When `unsized_fn_params` is not enabled,
2010            // this check is done at `visit_local_decl`.
2011            if self.tcx().features().unsized_fn_params() {
2012                let span = term.source_info.span;
2013                self.ensure_place_sized(dest_ty, span);
2014            }
2015        }
2016    }
2017
2018    #[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("check_call_inputs",
                                    "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(2018u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("sig")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("sig");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("args")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("args");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::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(&sig)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            if args.len() < sig.inputs().len() ||
                    (args.len() > sig.inputs().len() && !sig.c_variadic()) {
                {
                    crate::type_check::mirbug(self.tcx(), self.last_span,
                        ::alloc::__export::must_use({
                                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                        self.body().source.def_id(), term,
                                        format_args!("call to {0:?} with wrong # of args", sig)))
                            }))
                };
            }
            let func_ty = func.ty(self.body, self.infcx.tcx);
            if let ty::FnDef(def_id, _) = *func_ty.kind() {
                if let Some(name @
                        (sym::simd_shuffle | sym::simd_insert | sym::simd_extract))
                        = self.tcx().intrinsic(def_id).map(|i| i.name) {
                    let idx = match name { sym::simd_shuffle => 2, _ => 1, };
                    if !#[allow(non_exhaustive_omitted_patterns)] match args[idx]
                                {
                                Spanned { node: Operand::Constant(_), .. } => true,
                                _ => false,
                            } {
                        self.tcx().dcx().emit_err(SimdIntrinsicArgConst {
                                span: term.source_info.span,
                                arg: idx + 1,
                                intrinsic: name.to_string(),
                            });
                    }
                }
            }
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/mod.rs:2054",
                                    "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                                    ::tracing_core::__macro_support::Option::Some(2054u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("func_ty")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("func_ty");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&func_ty)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            for (n, (fn_arg, op_arg)) in
                iter::zip(sig.inputs(), args).enumerate() {
                let op_arg_ty = op_arg.node.ty(self.body, self.tcx());
                let op_arg_ty =
                    self.normalize(ty::Unnormalized::new_wip(op_arg_ty),
                        term_location);
                let category =
                    if call_source.from_hir_call() {
                        ConstraintCategory::CallArgument(Some(self.infcx.tcx.erase_and_anonymize_regions(func_ty)))
                    } else { ConstraintCategory::Boring };
                if let Err(terr) =
                        self.sub_types(op_arg_ty, *fn_arg,
                            term_location.to_locations(), category) {
                    {
                        crate::type_check::mirbug(self.tcx(), self.last_span,
                            ::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                                            self.body().source.def_id(), term,
                                            format_args!("bad arg #{0:?} ({1:?} <- {2:?}): {3:?}", n,
                                                fn_arg, op_arg_ty, terr)))
                                }))
                    };
                }
            }
        }
    }
}#[instrument(level = "debug", skip(self, term, func, term_location, call_source))]
2019    fn check_call_inputs(
2020        &mut self,
2021        term: &Terminator<'tcx>,
2022        func: &Operand<'tcx>,
2023        sig: &ty::FnSig<'tcx>,
2024        args: &[Spanned<Operand<'tcx>>],
2025        term_location: Location,
2026        call_source: CallSource,
2027    ) {
2028        if args.len() < sig.inputs().len() || (args.len() > sig.inputs().len() && !sig.c_variadic())
2029        {
2030            span_mirbug!(self, term, "call to {:?} with wrong # of args", sig);
2031        }
2032
2033        let func_ty = func.ty(self.body, self.infcx.tcx);
2034        if let ty::FnDef(def_id, _) = *func_ty.kind() {
2035            // Some of the SIMD intrinsics are special: they need a particular argument to be a
2036            // constant. (Eventually this should use const-generics, but those are not up for the
2037            // task yet: https://github.com/rust-lang/rust/issues/85229.)
2038            if let Some(name @ (sym::simd_shuffle | sym::simd_insert | sym::simd_extract)) =
2039                self.tcx().intrinsic(def_id).map(|i| i.name)
2040            {
2041                let idx = match name {
2042                    sym::simd_shuffle => 2,
2043                    _ => 1,
2044                };
2045                if !matches!(args[idx], Spanned { node: Operand::Constant(_), .. }) {
2046                    self.tcx().dcx().emit_err(SimdIntrinsicArgConst {
2047                        span: term.source_info.span,
2048                        arg: idx + 1,
2049                        intrinsic: name.to_string(),
2050                    });
2051                }
2052            }
2053        }
2054        debug!(?func_ty);
2055
2056        for (n, (fn_arg, op_arg)) in iter::zip(sig.inputs(), args).enumerate() {
2057            let op_arg_ty = op_arg.node.ty(self.body, self.tcx());
2058
2059            let op_arg_ty = self.normalize(ty::Unnormalized::new_wip(op_arg_ty), term_location);
2060            let category = if call_source.from_hir_call() {
2061                ConstraintCategory::CallArgument(Some(
2062                    self.infcx.tcx.erase_and_anonymize_regions(func_ty),
2063                ))
2064            } else {
2065                ConstraintCategory::Boring
2066            };
2067            if let Err(terr) =
2068                self.sub_types(op_arg_ty, *fn_arg, term_location.to_locations(), category)
2069            {
2070                span_mirbug!(
2071                    self,
2072                    term,
2073                    "bad arg #{:?} ({:?} <- {:?}): {:?}",
2074                    n,
2075                    fn_arg,
2076                    op_arg_ty,
2077                    terr
2078                );
2079            }
2080        }
2081    }
2082
2083    fn check_iscleanup(&mut self, block_data: &BasicBlockData<'tcx>) {
2084        let is_cleanup = block_data.is_cleanup;
2085        match block_data.terminator().kind {
2086            TerminatorKind::Goto { target } => {
2087                self.assert_iscleanup(block_data, target, is_cleanup)
2088            }
2089            TerminatorKind::SwitchInt { ref targets, .. } => {
2090                for target in targets.all_targets() {
2091                    self.assert_iscleanup(block_data, *target, is_cleanup);
2092                }
2093            }
2094            TerminatorKind::UnwindResume => {
2095                if !is_cleanup {
2096                    {
    crate::type_check::mirbug(self.tcx(), self.last_span,
        ::alloc::__export::must_use({
                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                        self.body().source.def_id(), block_data,
                        format_args!("resume on non-cleanup block!")))
            }))
}span_mirbug!(self, block_data, "resume on non-cleanup block!")
2097                }
2098            }
2099            TerminatorKind::UnwindTerminate(_) => {
2100                if !is_cleanup {
2101                    {
    crate::type_check::mirbug(self.tcx(), self.last_span,
        ::alloc::__export::must_use({
                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                        self.body().source.def_id(), block_data,
                        format_args!("terminate on non-cleanup block!")))
            }))
}span_mirbug!(self, block_data, "terminate on non-cleanup block!")
2102                }
2103            }
2104            TerminatorKind::Return => {
2105                if is_cleanup {
2106                    {
    crate::type_check::mirbug(self.tcx(), self.last_span,
        ::alloc::__export::must_use({
                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                        self.body().source.def_id(), block_data,
                        format_args!("return on cleanup block")))
            }))
}span_mirbug!(self, block_data, "return on cleanup block")
2107                }
2108            }
2109            TerminatorKind::TailCall { .. } => {
2110                if is_cleanup {
2111                    {
    crate::type_check::mirbug(self.tcx(), self.last_span,
        ::alloc::__export::must_use({
                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                        self.body().source.def_id(), block_data,
                        format_args!("tailcall on cleanup block")))
            }))
}span_mirbug!(self, block_data, "tailcall on cleanup block")
2112                }
2113            }
2114            TerminatorKind::CoroutineDrop { .. } => {
2115                if is_cleanup {
2116                    {
    crate::type_check::mirbug(self.tcx(), self.last_span,
        ::alloc::__export::must_use({
                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                        self.body().source.def_id(), block_data,
                        format_args!("coroutine_drop in cleanup block")))
            }))
}span_mirbug!(self, block_data, "coroutine_drop in cleanup block")
2117                }
2118            }
2119            TerminatorKind::Yield { resume, drop, .. } => {
2120                if is_cleanup {
2121                    {
    crate::type_check::mirbug(self.tcx(), self.last_span,
        ::alloc::__export::must_use({
                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                        self.body().source.def_id(), block_data,
                        format_args!("yield in cleanup block")))
            }))
}span_mirbug!(self, block_data, "yield in cleanup block")
2122                }
2123                self.assert_iscleanup(block_data, resume, is_cleanup);
2124                if let Some(drop) = drop {
2125                    self.assert_iscleanup(block_data, drop, is_cleanup);
2126                }
2127            }
2128            TerminatorKind::Unreachable => {}
2129            TerminatorKind::Drop { target, unwind, drop, .. } => {
2130                self.assert_iscleanup(block_data, target, is_cleanup);
2131                self.assert_iscleanup_unwind(block_data, unwind, is_cleanup);
2132                if let Some(drop) = drop {
2133                    self.assert_iscleanup(block_data, drop, is_cleanup);
2134                }
2135            }
2136            TerminatorKind::Assert { target, unwind, .. } => {
2137                self.assert_iscleanup(block_data, target, is_cleanup);
2138                self.assert_iscleanup_unwind(block_data, unwind, is_cleanup);
2139            }
2140            TerminatorKind::Call { ref target, unwind, .. } => {
2141                if let &Some(target) = target {
2142                    self.assert_iscleanup(block_data, target, is_cleanup);
2143                }
2144                self.assert_iscleanup_unwind(block_data, unwind, is_cleanup);
2145            }
2146            TerminatorKind::FalseEdge { real_target, imaginary_target } => {
2147                self.assert_iscleanup(block_data, real_target, is_cleanup);
2148                self.assert_iscleanup(block_data, imaginary_target, is_cleanup);
2149            }
2150            TerminatorKind::FalseUnwind { real_target, unwind } => {
2151                self.assert_iscleanup(block_data, real_target, is_cleanup);
2152                self.assert_iscleanup_unwind(block_data, unwind, is_cleanup);
2153            }
2154            TerminatorKind::InlineAsm { ref targets, unwind, .. } => {
2155                for &target in targets {
2156                    self.assert_iscleanup(block_data, target, is_cleanup);
2157                }
2158                self.assert_iscleanup_unwind(block_data, unwind, is_cleanup);
2159            }
2160        }
2161    }
2162
2163    fn assert_iscleanup(&mut self, ctxt: &dyn fmt::Debug, bb: BasicBlock, iscleanuppad: bool) {
2164        if self.body[bb].is_cleanup != iscleanuppad {
2165            {
    crate::type_check::mirbug(self.tcx(), self.last_span,
        ::alloc::__export::must_use({
                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                        self.body().source.def_id(), ctxt,
                        format_args!("cleanuppad mismatch: {0:?} should be {1:?}",
                            bb, iscleanuppad)))
            }))
};span_mirbug!(self, ctxt, "cleanuppad mismatch: {:?} should be {:?}", bb, iscleanuppad);
2166        }
2167    }
2168
2169    fn assert_iscleanup_unwind(
2170        &mut self,
2171        ctxt: &dyn fmt::Debug,
2172        unwind: UnwindAction,
2173        is_cleanup: bool,
2174    ) {
2175        match unwind {
2176            UnwindAction::Cleanup(unwind) => {
2177                if is_cleanup {
2178                    {
    crate::type_check::mirbug(self.tcx(), self.last_span,
        ::alloc::__export::must_use({
                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                        self.body().source.def_id(), ctxt,
                        format_args!("unwind on cleanup block")))
            }))
}span_mirbug!(self, ctxt, "unwind on cleanup block")
2179                }
2180                self.assert_iscleanup(ctxt, unwind, true);
2181            }
2182            UnwindAction::Continue => {
2183                if is_cleanup {
2184                    {
    crate::type_check::mirbug(self.tcx(), self.last_span,
        ::alloc::__export::must_use({
                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                        self.body().source.def_id(), ctxt,
                        format_args!("unwind on cleanup block")))
            }))
}span_mirbug!(self, ctxt, "unwind on cleanup block")
2185                }
2186            }
2187            UnwindAction::Unreachable | UnwindAction::Terminate(_) => (),
2188        }
2189    }
2190
2191    fn ensure_place_sized(&mut self, ty: Ty<'tcx>, span: Span) {
2192        let tcx = self.tcx();
2193
2194        // Erase the regions from `ty` to get a global type. The
2195        // `Sized` bound in no way depends on precise regions, so this
2196        // shouldn't affect `is_sized`.
2197        let erased_ty = tcx.erase_and_anonymize_regions(ty);
2198        // FIXME(#132279): Using `Ty::is_sized` causes us to incorrectly handle opaques here.
2199        if !erased_ty.is_sized(tcx, self.infcx.typing_env(self.infcx.param_env)) {
2200            // in current MIR construction, all non-control-flow rvalue
2201            // expressions evaluate through `as_temp` or `into` a return
2202            // slot or local, so to find all unsized rvalues it is enough
2203            // to check all temps, return slots and locals.
2204            if self.reported_errors.replace((ty, span)).is_none() {
2205                // While this is located in `nll::typeck` this error is not
2206                // an NLL error, it's a required check to prevent creation
2207                // of unsized rvalues in a call expression.
2208                self.tcx().dcx().emit_err(MoveUnsized { ty, span });
2209            }
2210        }
2211    }
2212
2213    fn aggregate_field_ty(
2214        &mut self,
2215        ak: &AggregateKind<'tcx>,
2216        field_index: FieldIdx,
2217        location: Location,
2218    ) -> Result<Ty<'tcx>, FieldAccessError> {
2219        let tcx = self.tcx();
2220
2221        match *ak {
2222            AggregateKind::Adt(adt_did, variant_index, args, _, active_field_index) => {
2223                let def = tcx.adt_def(adt_did);
2224                let variant = &def.variant(variant_index);
2225                let adj_field_index = active_field_index.unwrap_or(field_index);
2226                if let Some(field) = variant.fields.get(adj_field_index) {
2227                    Ok(self.normalize(field.ty(tcx, args), location))
2228                } else {
2229                    Err(FieldAccessError::OutOfRange { field_count: variant.fields.len() })
2230                }
2231            }
2232            AggregateKind::Closure(_, args) => {
2233                match args.as_closure().upvar_tys().get(field_index.as_usize()) {
2234                    Some(ty) => Ok(*ty),
2235                    None => Err(FieldAccessError::OutOfRange {
2236                        field_count: args.as_closure().upvar_tys().len(),
2237                    }),
2238                }
2239            }
2240            AggregateKind::Coroutine(_, args) => {
2241                // It doesn't make sense to look at a field beyond the captured
2242                // upvars.
2243                // Otherwise it require a variant index, and are not initialized
2244                // in aggregate rvalues.
2245                let upvar_tys = &args.as_coroutine().upvar_tys();
2246                if let Some(ty) = upvar_tys.get(field_index.as_usize()) {
2247                    Ok(*ty)
2248                } else {
2249                    Err(FieldAccessError::OutOfRange { field_count: upvar_tys.len() })
2250                }
2251            }
2252            AggregateKind::CoroutineClosure(_, args) => {
2253                match args.as_coroutine_closure().upvar_tys().get(field_index.as_usize()) {
2254                    Some(ty) => Ok(*ty),
2255                    None => Err(FieldAccessError::OutOfRange {
2256                        field_count: args.as_coroutine_closure().upvar_tys().len(),
2257                    }),
2258                }
2259            }
2260            AggregateKind::Array(ty) => Ok(ty),
2261            AggregateKind::Tuple | AggregateKind::RawPtr(..) => {
2262                {
    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
            format_args!("This should have been covered in check_rvalues")));
};unreachable!("This should have been covered in check_rvalues");
2263            }
2264        }
2265    }
2266
2267    /// If this rvalue supports a user-given type annotation, then
2268    /// extract and return it. This represents the final type of the
2269    /// rvalue and will be unified with the inferred type.
2270    fn rvalue_user_ty(&self, rvalue: &Rvalue<'tcx>) -> Option<UserTypeAnnotationIndex> {
2271        match rvalue {
2272            Rvalue::Use(..)
2273            | Rvalue::ThreadLocalRef(..)
2274            | Rvalue::Repeat(..)
2275            | Rvalue::Ref(..)
2276            | Rvalue::Reborrow(..)
2277            | Rvalue::RawPtr(..)
2278            | Rvalue::Cast(..)
2279            | Rvalue::BinaryOp(..)
2280            | Rvalue::CopyForDeref(..)
2281            | Rvalue::UnaryOp(..)
2282            | Rvalue::Discriminant(..)
2283            | Rvalue::WrapUnsafeBinder(..) => None,
2284
2285            Rvalue::Aggregate(aggregate, _) => match **aggregate {
2286                AggregateKind::Adt(_, _, _, user_ty, _) => user_ty,
2287                AggregateKind::Array(_) => None,
2288                AggregateKind::Tuple => None,
2289                AggregateKind::Closure(_, _) => None,
2290                AggregateKind::Coroutine(_, _) => None,
2291                AggregateKind::CoroutineClosure(_, _) => None,
2292                AggregateKind::RawPtr(_, _) => None,
2293            },
2294        }
2295    }
2296
2297    fn check_aggregate_rvalue(
2298        &mut self,
2299        rvalue: &Rvalue<'tcx>,
2300        aggregate_kind: &AggregateKind<'tcx>,
2301        operands: &IndexSlice<FieldIdx, Operand<'tcx>>,
2302        location: Location,
2303    ) {
2304        let tcx = self.tcx();
2305
2306        self.prove_aggregate_predicates(aggregate_kind, location);
2307
2308        if *aggregate_kind == AggregateKind::Tuple {
2309            // tuple rvalue field type is always the type of the op. Nothing to check here.
2310            return;
2311        }
2312
2313        if let AggregateKind::RawPtr(..) = aggregate_kind {
2314            ::rustc_middle::util::bug::bug_fmt(format_args!("RawPtr should only be in runtime MIR"));bug!("RawPtr should only be in runtime MIR");
2315        }
2316
2317        for (i, operand) in operands.iter_enumerated() {
2318            let field_ty = match self.aggregate_field_ty(aggregate_kind, i, location) {
2319                Ok(field_ty) => field_ty,
2320                Err(FieldAccessError::OutOfRange { field_count }) => {
2321                    {
    crate::type_check::mirbug(self.tcx(), self.last_span,
        ::alloc::__export::must_use({
                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                        self.body().source.def_id(), rvalue,
                        format_args!("accessed field #{0} but variant only has {1}",
                            i.as_u32(), field_count)))
            }))
};span_mirbug!(
2322                        self,
2323                        rvalue,
2324                        "accessed field #{} but variant only has {}",
2325                        i.as_u32(),
2326                        field_count,
2327                    );
2328                    continue;
2329                }
2330            };
2331            let operand_ty = operand.ty(self.body, tcx);
2332            let operand_ty = self.normalize(ty::Unnormalized::new_wip(operand_ty), location);
2333
2334            if let Err(terr) = self.sub_types(
2335                operand_ty,
2336                field_ty,
2337                location.to_locations(),
2338                ConstraintCategory::Boring,
2339            ) {
2340                {
    crate::type_check::mirbug(self.tcx(), self.last_span,
        ::alloc::__export::must_use({
                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                        self.body().source.def_id(), rvalue,
                        format_args!("{0:?} is not a subtype of {1:?}: {2:?}",
                            operand_ty, field_ty, terr)))
            }))
};span_mirbug!(
2341                    self,
2342                    rvalue,
2343                    "{:?} is not a subtype of {:?}: {:?}",
2344                    operand_ty,
2345                    field_ty,
2346                    terr
2347                );
2348            }
2349        }
2350    }
2351
2352    /// Adds the constraints that arise from a borrow expression `&'a P` at the location `L`.
2353    ///
2354    /// # Parameters
2355    ///
2356    /// - `location`: the location `L` where the borrow expression occurs
2357    /// - `borrow_region`: the region `'a` associated with the borrow
2358    /// - `borrowed_place`: the place `P` being borrowed
2359    fn add_reborrow_constraint(
2360        &mut self,
2361        location: Location,
2362        borrow_region: ty::Region<'tcx>,
2363        borrowed_place: &Place<'tcx>,
2364    ) {
2365        // These constraints are only meaningful during borrowck:
2366        let Self { borrow_set, location_table, polonius_facts, constraints, .. } = self;
2367
2368        // In Polonius mode, we also push a `loan_issued_at` fact
2369        // linking the loan to the region (in some cases, though,
2370        // there is no loan associated with this borrow expression --
2371        // that occurs when we are borrowing an unsafe place, for
2372        // example).
2373        if let Some(polonius_facts) = polonius_facts {
2374            let _prof_timer = self.infcx.tcx.prof.generic_activity("polonius_fact_generation");
2375            if let Some(idxs) = borrow_set.borrows_at_location(&location) {
2376                let region_vid = borrow_region.as_var();
2377                for borrow_index in idxs {
2378                    polonius_facts.loan_issued_at.push((
2379                        region_vid.into(),
2380                        *borrow_index,
2381                        location_table.mid_index(location),
2382                    ));
2383                }
2384            }
2385        }
2386
2387        // If we are reborrowing the referent of another reference, we
2388        // need to add outlives relationships. In a case like `&mut
2389        // *p`, where the `p` has type `&'b mut Foo`, for example, we
2390        // need to ensure that `'b: 'a`.
2391
2392        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/mod.rs:2392",
                        "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(2392u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("add_reborrow_constraint({0:?}, {1:?}, {2:?})",
                                                    location, borrow_region, borrowed_place) as
                                            &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(
2393            "add_reborrow_constraint({:?}, {:?}, {:?})",
2394            location, borrow_region, borrowed_place
2395        );
2396
2397        let tcx = self.infcx.tcx;
2398        let def = self.body.source.def_id().expect_local();
2399        let upvars = tcx.closure_captures(def);
2400        let field =
2401            path_utils::is_upvar_field_projection(tcx, upvars, borrowed_place.as_ref(), self.body);
2402        let category = if let Some(field) = field {
2403            ConstraintCategory::ClosureUpvar(field)
2404        } else {
2405            ConstraintCategory::Boring
2406        };
2407
2408        for (base, elem) in borrowed_place.as_ref().iter_projections().rev() {
2409            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/mod.rs:2409",
                        "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(2409u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("add_reborrow_constraint - iteration {0:?}",
                                                    elem) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("add_reborrow_constraint - iteration {:?}", elem);
2410
2411            match elem {
2412                ProjectionElem::Deref => {
2413                    let base_ty = base.ty(self.body, tcx).ty;
2414
2415                    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/mod.rs:2415",
                        "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(2415u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("add_reborrow_constraint - base_ty = {0:?}",
                                                    base_ty) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("add_reborrow_constraint - base_ty = {:?}", base_ty);
2416                    match base_ty.kind() {
2417                        ty::Ref(ref_region, _, mutbl) => {
2418                            constraints.outlives_constraints.push(OutlivesConstraint {
2419                                sup: ref_region.as_var(),
2420                                sub: borrow_region.as_var(),
2421                                locations: location.to_locations(),
2422                                span: location.to_locations().span(self.body),
2423                                category,
2424                                variance_info: ty::VarianceDiagInfo::default(),
2425                                from_closure: false,
2426                            });
2427
2428                            match mutbl {
2429                                hir::Mutability::Not => {
2430                                    // Immutable reference. We don't need the base
2431                                    // to be valid for the entire lifetime of
2432                                    // the borrow.
2433                                    break;
2434                                }
2435                                hir::Mutability::Mut => {
2436                                    // Mutable reference. We *do* need the base
2437                                    // to be valid, because after the base becomes
2438                                    // invalid, someone else can use our mutable deref.
2439
2440                                    // This is in order to make the following function
2441                                    // illegal:
2442                                    // ```
2443                                    // fn unsafe_deref<'a, 'b>(x: &'a &'b mut T) -> &'b mut T {
2444                                    //     &mut *x
2445                                    // }
2446                                    // ```
2447                                    //
2448                                    // As otherwise you could clone `&mut T` using the
2449                                    // following function:
2450                                    // ```
2451                                    // fn bad(x: &mut T) -> (&mut T, &mut T) {
2452                                    //     let my_clone = unsafe_deref(&'a x);
2453                                    //     ENDREGION 'a;
2454                                    //     (my_clone, x)
2455                                    // }
2456                                    // ```
2457                                }
2458                            }
2459                        }
2460                        ty::RawPtr(..) => {
2461                            // deref of raw pointer, guaranteed to be valid
2462                            break;
2463                        }
2464                        ty::Adt(def, _) if def.is_box() => {
2465                            // deref of `Box`, need the base to be valid - propagate
2466                        }
2467                        _ => ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected deref ty {0:?} in {1:?}",
        base_ty, borrowed_place))bug!("unexpected deref ty {:?} in {:?}", base_ty, borrowed_place),
2468                    }
2469                }
2470                ProjectionElem::Field(..)
2471                | ProjectionElem::Downcast(..)
2472                | ProjectionElem::OpaqueCast(..)
2473                | ProjectionElem::Index(..)
2474                | ProjectionElem::ConstantIndex { .. }
2475                | ProjectionElem::Subslice { .. }
2476                | ProjectionElem::UnwrapUnsafeBinder(_) => {
2477                    // other field access
2478                }
2479            }
2480        }
2481    }
2482
2483    fn add_generic_reborrow_constraint(
2484        &mut self,
2485        mutability: Mutability,
2486        location: Location,
2487        borrowed_place: &Place<'tcx>,
2488        dest_ty: Ty<'tcx>,
2489    ) {
2490        let Self { borrow_set, location_table, polonius_facts, constraints, infcx, body, .. } =
2491            self;
2492
2493        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/mod.rs:2493",
                        "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(2493u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("add_generic_reborrow_constraint({0:?}, {1:?}, {2:?}, {3:?})",
                                                    mutability, location, borrowed_place, dest_ty) as
                                            &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(
2494            "add_generic_reborrow_constraint({:?}, {:?}, {:?}, {:?})",
2495            mutability, location, borrowed_place, dest_ty
2496        );
2497
2498        let tcx = infcx.tcx;
2499        let def = body.source.def_id().expect_local();
2500        let upvars = tcx.closure_captures(def);
2501        let field =
2502            path_utils::is_upvar_field_projection(tcx, upvars, borrowed_place.as_ref(), body);
2503        let category = if let Some(field) = field {
2504            ConstraintCategory::ClosureUpvar(field)
2505        } else {
2506            ConstraintCategory::Boring
2507        };
2508
2509        let borrowed_ty = borrowed_place.ty(self.body, tcx).ty;
2510
2511        let ty::Adt(dest_adt, dest_args) = dest_ty.kind() else { ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"))bug!() };
2512        let [dest_arg, ..] = ***dest_args else { ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"))bug!() };
2513        let ty::GenericArgKind::Lifetime(dest_region) = dest_arg.kind() else { ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"))bug!() };
2514        constraints.liveness_constraints.add_location(dest_region.as_var(), location);
2515
2516        // In Polonius mode, we also push a `loan_issued_at` fact
2517        // linking the loan to the region.
2518        if let Some(polonius_facts) = polonius_facts {
2519            let _prof_timer = infcx.tcx.prof.generic_activity("polonius_fact_generation");
2520            if let Some(borrows) = borrow_set.borrows_at_location(&location) {
2521                let region_vid = dest_region.as_var();
2522                for borrow_index in borrows {
2523                    polonius_facts.loan_issued_at.push((
2524                        region_vid.into(),
2525                        *borrow_index,
2526                        location_table.mid_index(location),
2527                    ));
2528                }
2529            }
2530        }
2531
2532        if mutability.is_not() {
2533            // FIXME(reborrow): for CoerceShared we need to relate the types manually, field by
2534            // field. We cannot just attempt to relate `T` and `<T as CoerceShared>::Target` by
2535            // calling relate_types as they are (generally) two unrelated user-defined ADTs, such as
2536            // `CustomMut<'a>` and `CustomRef<'a>`, or `CustomMut<'a, T>` and `CustomRef<'a, T>`.
2537            // Field-by-field relate_types is expected to work based on the wf-checks that the
2538            // CoerceShared trait performs.
2539            let ty::Adt(borrowed_adt, borrowed_args) = borrowed_ty.kind() else { ::core::panicking::panic("internal error: entered unreachable code")unreachable!() };
2540            let borrowed_fields = borrowed_adt.all_fields().collect::<Vec<_>>();
2541            for dest_field in dest_adt.all_fields() {
2542                let Some(borrowed_field) =
2543                    borrowed_fields.iter().find(|f| f.name == dest_field.name)
2544                else {
2545                    continue;
2546                };
2547                let dest_ty = dest_field.ty(tcx, dest_args).skip_norm_wip();
2548                let borrowed_ty = borrowed_field.ty(tcx, borrowed_args).skip_norm_wip();
2549                if let (
2550                    ty::Ref(borrow_region, _, Mutability::Mut),
2551                    ty::Ref(ref_region, _, Mutability::Not),
2552                ) = (borrowed_ty.kind(), dest_ty.kind())
2553                {
2554                    self.relate_types(
2555                        borrowed_ty.peel_refs(),
2556                        ty::Variance::Covariant,
2557                        dest_ty.peel_refs(),
2558                        location.to_locations(),
2559                        category,
2560                    )
2561                    .unwrap();
2562                    self.constraints.outlives_constraints.push(OutlivesConstraint {
2563                        sup: ref_region.as_var(),
2564                        sub: borrow_region.as_var(),
2565                        locations: location.to_locations(),
2566                        span: location.to_locations().span(self.body),
2567                        category,
2568                        variance_info: ty::VarianceDiagInfo::default(),
2569                        from_closure: false,
2570                    });
2571                } else {
2572                    self.relate_types(
2573                        borrowed_ty,
2574                        ty::Variance::Covariant,
2575                        dest_ty,
2576                        location.to_locations(),
2577                        category,
2578                    )
2579                    .unwrap();
2580                }
2581            }
2582        } else {
2583            // Exclusive reborrow
2584            self.relate_types(
2585                borrowed_ty,
2586                ty::Variance::Covariant,
2587                dest_ty,
2588                location.to_locations(),
2589                category,
2590            )
2591            .unwrap();
2592        }
2593    }
2594
2595    fn prove_aggregate_predicates(
2596        &mut self,
2597        aggregate_kind: &AggregateKind<'tcx>,
2598        location: Location,
2599    ) {
2600        let tcx = self.tcx();
2601
2602        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/mod.rs:2602",
                        "rustc_borrowck::type_check", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
                        ::tracing_core::__macro_support::Option::Some(2602u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("prove_aggregate_predicates(aggregate_kind={0:?}, location={1:?})",
                                                    aggregate_kind, location) as
                                            &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(
2603            "prove_aggregate_predicates(aggregate_kind={:?}, location={:?})",
2604            aggregate_kind, location
2605        );
2606
2607        let (def_id, instantiated_clauses) = match *aggregate_kind {
2608            AggregateKind::Adt(adt_did, _, args, _, _) => {
2609                (adt_did, tcx.clauses_of(adt_did).instantiate(tcx, args))
2610            }
2611
2612            // For closures, we have some **extra requirements** we
2613            // have to check. In particular, in their upvars and
2614            // signatures, closures often reference various regions
2615            // from the surrounding function -- we call those the
2616            // closure's free regions. When we borrow-check (and hence
2617            // region-check) closures, we may find that the closure
2618            // requires certain relationships between those free
2619            // regions. However, because those free regions refer to
2620            // portions of the CFG of their caller, the closure is not
2621            // in a position to verify those relationships. In that
2622            // case, the requirements get "propagated" to us, and so
2623            // we have to solve them here where we instantiate the
2624            // closure.
2625            //
2626            // Despite the opacity of the previous paragraph, this is
2627            // actually relatively easy to understand in terms of the
2628            // desugaring. A closure gets desugared to a struct, and
2629            // these extra requirements are basically like where
2630            // clauses on the struct.
2631            AggregateKind::Closure(def_id, args)
2632            | AggregateKind::CoroutineClosure(def_id, args)
2633            | AggregateKind::Coroutine(def_id, args) => {
2634                (def_id, self.prove_closure_bounds(tcx, def_id.expect_local(), args, location))
2635            }
2636
2637            AggregateKind::Array(_) | AggregateKind::Tuple | AggregateKind::RawPtr(..) => {
2638                (CRATE_DEF_ID.to_def_id(), ty::InstantiatedClauses::empty())
2639            }
2640        };
2641
2642        self.normalize_and_prove_instantiated_clauses(
2643            def_id,
2644            instantiated_clauses,
2645            location.to_locations(),
2646        );
2647    }
2648
2649    fn prove_closure_bounds(
2650        &mut self,
2651        tcx: TyCtxt<'tcx>,
2652        def_id: LocalDefId,
2653        args: GenericArgsRef<'tcx>,
2654        location: Location,
2655    ) -> ty::InstantiatedClauses<'tcx> {
2656        let root_def_id = self.root_cx.root_def_id();
2657        // We will have to handle propagated closure requirements for this closure,
2658        // but need to defer this until the nested body has been fully borrow checked.
2659        self.deferred_closure_requirements.push((def_id, args, location.to_locations()));
2660
2661        // Equate closure args to regions inherited from `root_def_id`. Fixes #98589.
2662        let typeck_root_args = ty::GenericArgs::identity_for_item(tcx, root_def_id);
2663
2664        let parent_args = match tcx.def_kind(def_id) {
2665            // We don't want to dispatch on 3 different kind of closures here, so take
2666            // advantage of the fact that the `parent_args` is the same length as the
2667            // `typeck_root_args`.
2668            DefKind::Closure => {
2669                // FIXME(async_closures): It may be useful to add a debug assert here
2670                // to actually call `type_of` and check the `parent_args` are the same
2671                // length as the `typeck_root_args`.
2672                &args[..typeck_root_args.len()]
2673            }
2674            DefKind::AnonConst
2675                if tcx.anon_const_kind(def_id) == ty::AnonConstKind::NonTypeSystemInline =>
2676            {
2677                args.as_inline_const().parent_args()
2678            }
2679            other => ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected item {0:?}",
        other))bug!("unexpected item {:?}", other),
2680        };
2681        let parent_args = tcx.mk_args(parent_args);
2682
2683        {
    match (&typeck_root_args.len(), &parent_args.len()) {
        (left_val, right_val) => {
            if !(*left_val == *right_val) {
                let kind = ::core::panicking::AssertKind::Eq;
                ::core::panicking::assert_failed(kind, &*left_val,
                    &*right_val, ::core::option::Option::None);
            }
        }
    }
};assert_eq!(typeck_root_args.len(), parent_args.len());
2684        if let Err(_) = self.eq_args(
2685            typeck_root_args,
2686            parent_args,
2687            location.to_locations(),
2688            ConstraintCategory::BoringNoLocation,
2689        ) {
2690            {
    crate::type_check::mirbug(self.tcx(), self.last_span,
        ::alloc::__export::must_use({
                ::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
                        self.body().source.def_id(), def_id,
                        format_args!("could not relate closure to parent {0:?} != {1:?}",
                            typeck_root_args, parent_args)))
            }))
};span_mirbug!(
2691                self,
2692                def_id,
2693                "could not relate closure to parent {:?} != {:?}",
2694                typeck_root_args,
2695                parent_args
2696            );
2697        }
2698
2699        tcx.clauses_of(def_id).instantiate(tcx, args)
2700    }
2701}
2702
2703trait NormalizeLocation: fmt::Debug + Copy {
2704    fn to_locations(self) -> Locations;
2705}
2706
2707impl NormalizeLocation for Locations {
2708    fn to_locations(self) -> Locations {
2709        self
2710    }
2711}
2712
2713impl NormalizeLocation for Location {
2714    fn to_locations(self) -> Locations {
2715        Locations::Single(self)
2716    }
2717}
2718
2719/// Runs `infcx.instantiate_opaque_types`. Unlike other `TypeOp`s,
2720/// this is not canonicalized - it directly affects the main `InferCtxt`
2721/// that we use during MIR borrowchecking.
2722#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for InstantiateOpaqueType<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field3_finish(f,
            "InstantiateOpaqueType", "base_universe", &self.base_universe,
            "region_constraints", &self.region_constraints, "obligations",
            &&self.obligations)
    }
}Debug)]
2723pub(super) struct InstantiateOpaqueType<'tcx> {
2724    pub base_universe: Option<ty::UniverseIndex>,
2725    pub region_constraints: Option<RegionConstraintData<'tcx>>,
2726    pub obligations: PredicateObligations<'tcx>,
2727}
2728
2729impl<'tcx> TypeOp<'tcx> for InstantiateOpaqueType<'tcx> {
2730    type Output = ();
2731    /// We use this type itself to store the information used
2732    /// when reporting errors. Since this is not a query, we don't
2733    /// re-run anything during error reporting - we just use the information
2734    /// we saved to help extract an error from the already-existing region
2735    /// constraints in our `InferCtxt`
2736    type ErrorInfo = InstantiateOpaqueType<'tcx>;
2737
2738    fn fully_perform(
2739        mut self,
2740        infcx: &InferCtxt<'tcx>,
2741        root_def_id: LocalDefId,
2742        span: Span,
2743    ) -> Result<TypeOpOutput<'tcx, Self>, ErrorGuaranteed> {
2744        let (mut output, region_constraints) =
2745            scrape_region_constraints(infcx, root_def_id, "InstantiateOpaqueType", span, |ocx| {
2746                ocx.register_obligations(self.obligations.clone());
2747                Ok(())
2748            })?;
2749        self.region_constraints = Some(region_constraints);
2750        output.error_info = Some(self);
2751        Ok(output)
2752    }
2753}