1use 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::def::DefKind;
12use rustc_hir::def_id::LocalDefId;
13use rustc_hir::lang_items::LangItem;
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, CoroutineArgsExt,
30 GenericArgsRef, Ty, TyCtxt, 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
75pub(crate) fn type_check<'tcx>(
98 root_cx: &mut 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 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(&["normalized_inputs_and_output"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&normalized_inputs_and_output)
as &dyn 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: ®ion_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 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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("encountered an error region; removing constraints!")
as &dyn Value))])
});
} else { ; }
};debug!("encountered an error region; removing constraints!");
199 constraints.outlives_constraints = Default::default();
200 constraints.type_tests = Default::default();
201 root_cx.set_tainted_by_errors(guar);
202 infcx.set_tainted_by_errors(guar);
203 }
204
205 MirTypeckResults {
206 constraints,
207 universal_region_relations,
208 region_bound_pairs,
209 known_type_outlives_obligations,
210 deferred_closure_requirements,
211 polonius_context,
212 }
213}
214
215#[track_caller]
216fn mirbug(tcx: TyCtxt<'_>, span: Span, msg: String) {
217 tcx.dcx().span_delayed_bug(span, msg);
221}
222
223enum FieldAccessError {
224 OutOfRange { field_count: usize },
225}
226
227struct TypeChecker<'a, 'tcx> {
232 root_cx: &'a mut BorrowCheckRootCtxt<'tcx>,
233 infcx: &'a BorrowckInferCtxt<'tcx>,
234 last_span: Span,
235 body: &'a Body<'tcx>,
236 promoted: &'a IndexSlice<Promoted, Body<'tcx>>,
239 user_type_annotations: &'a CanonicalUserTypeAnnotations<'tcx>,
242 region_bound_pairs: &'a RegionBoundPairs<'tcx>,
243 known_type_outlives_obligations: &'a [ty::PolyTypeOutlivesPredicate<'tcx>],
244 reported_errors: FxIndexSet<(Ty<'tcx>, Span)>,
245 universal_regions: &'a UniversalRegions<'tcx>,
246 location_table: &'a PoloniusLocationTable,
247 polonius_facts: &'a mut Option<PoloniusFacts>,
248 borrow_set: &'a BorrowSet<'tcx>,
249 constraints: &'a mut MirTypeckRegionConstraints<'tcx>,
250 deferred_closure_requirements: &'a mut DeferredClosureRequirements<'tcx>,
251 polonius_context: Option<PoloniusContext>,
253}
254
255pub(crate) struct MirTypeckResults<'tcx> {
258 pub(crate) constraints: MirTypeckRegionConstraints<'tcx>,
259 pub(crate) universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
260 pub(crate) region_bound_pairs: Frozen<RegionBoundPairs<'tcx>>,
261 pub(crate) known_type_outlives_obligations: Frozen<Vec<ty::PolyTypeOutlivesPredicate<'tcx>>>,
262 pub(crate) deferred_closure_requirements: DeferredClosureRequirements<'tcx>,
263 pub(crate) polonius_context: Option<PoloniusContext>,
264}
265
266#[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)] pub(crate) struct MirTypeckRegionConstraints<'tcx> {
270 pub(crate) placeholder_indices: PlaceholderIndices<'tcx>,
276
277 pub(crate) placeholder_index_to_region: IndexVec<PlaceholderIndex, ty::Region<'tcx>>,
283
284 pub(crate) liveness_constraints: LivenessValues,
292
293 pub(crate) outlives_constraints: OutlivesConstraintSet<'tcx>,
294
295 pub(crate) universe_causes: FxIndexMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
296
297 pub(crate) type_tests: Vec<TypeTest<'tcx>>,
298}
299
300impl<'tcx> MirTypeckRegionConstraints<'tcx> {
301 pub(crate) fn placeholder_region(
304 &mut self,
305 infcx: &InferCtxt<'tcx>,
306 placeholder: ty::PlaceholderRegion<'tcx>,
307 ) -> ty::Region<'tcx> {
308 let placeholder_index = self.placeholder_indices.insert(placeholder);
309 match self.placeholder_index_to_region.get(placeholder_index) {
310 Some(&v) => v,
311 None => {
312 let origin = NllRegionVariableOrigin::Placeholder(placeholder);
313 let region = infcx.next_nll_region_var_in_universe(origin, placeholder.universe);
314 self.placeholder_index_to_region.push(region);
315 region
316 }
317 }
318 }
319}
320
321#[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)]
326pub enum Locations {
327 All(Span),
363
364 Single(Location),
368}
369
370impl Locations {
371 pub fn from_location(&self) -> Option<Location> {
372 match self {
373 Locations::All(_) => None,
374 Locations::Single(from_location) => Some(*from_location),
375 }
376 }
377
378 pub fn span(&self, body: &Body<'_>) -> Span {
380 match self {
381 Locations::All(span) => *span,
382 Locations::Single(l) => body.source_info(*l).span,
383 }
384 }
385}
386
387impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
388 fn tcx(&self) -> TyCtxt<'tcx> {
389 self.infcx.tcx
390 }
391
392 fn body(&self) -> &Body<'tcx> {
393 self.body
394 }
395
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(397u32),
::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(&[]) })
} 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:399",
"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(399u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
::tracing_core::field::FieldSet::new(&["self.user_type_annotations"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&self.user_type_annotations)
as &dyn 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")]
398 fn check_user_type_annotations(&mut self) {
399 debug!(?self.user_type_annotations);
400 for user_annotation in self.user_type_annotations {
401 let CanonicalUserTypeAnnotation { span, ref user_ty, inferred_ty } = *user_annotation;
402 let annotation = self.instantiate_canonical(span, user_ty);
403 self.ascribe_user_type(inferred_ty, annotation, span);
404 }
405 }
406
407 #[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(407u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
::tracing_core::field::FieldSet::new(&["locations",
"category"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&locations)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&category)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = 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:414",
"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(414u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("constraints generated: {0:#?}",
data) as &dyn 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")]
408 fn push_region_constraints(
409 &mut self,
410 locations: Locations,
411 category: ConstraintCategory<'tcx>,
412 data: &QueryRegionConstraints<'tcx>,
413 ) {
414 debug!("constraints generated: {:#?}", data);
415
416 constraint_conversion::ConstraintConversion::new(
417 self.infcx,
418 self.universal_regions,
419 self.region_bound_pairs,
420 self.known_type_outlives_obligations,
421 locations,
422 locations.span(self.body),
423 category,
424 self.constraints,
425 )
426 .convert_all(data);
427 }
428
429 fn sub_types(
431 &mut self,
432 sub: Ty<'tcx>,
433 sup: Ty<'tcx>,
434 locations: Locations,
435 category: ConstraintCategory<'tcx>,
436 ) -> Result<(), NoSolution> {
437 self.relate_types(sup, ty::Contravariant, sub, locations, category)
440 }
441
442 #[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(442u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
::tracing_core::field::FieldSet::new(&["expected", "found",
"locations"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&expected)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&found)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&locations)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: Result<(), NoSolution> = loop {};
return __tracing_attr_fake_return;
}
{
self.relate_types(expected, ty::Invariant, found, locations,
category)
}
}
}#[instrument(skip(self, category), level = "debug")]
443 fn eq_types(
444 &mut self,
445 expected: Ty<'tcx>,
446 found: Ty<'tcx>,
447 locations: Locations,
448 category: ConstraintCategory<'tcx>,
449 ) -> Result<(), NoSolution> {
450 self.relate_types(expected, ty::Invariant, found, locations, category)
451 }
452
453 #[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(453u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
::tracing_core::field::FieldSet::new(&["a", "v", "user_ty",
"locations", "category"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&a)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&v)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&user_ty)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&locations)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&category)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: Result<(), 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:463",
"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(463u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
::tracing_core::field::FieldSet::new(&["annotated_type"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&annotated_type)
as &dyn 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|
self.normalize(ty::Unnormalized::new_wip(ty), locations),
|ty, variant_index, field, ()|
{
PlaceTy::field_ty(tcx, ty, variant_index,
field).skip_norm_wip()
},
|_|
::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:491",
"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(491u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
::tracing_core::field::FieldSet::new(&["curr_projected_ty"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&curr_projected_ty)
as &dyn 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")]
454 fn relate_type_and_user_type(
455 &mut self,
456 a: Ty<'tcx>,
457 v: ty::Variance,
458 user_ty: &UserTypeProjection,
459 locations: Locations,
460 category: ConstraintCategory<'tcx>,
461 ) -> Result<(), NoSolution> {
462 let annotated_type = self.user_type_annotations[user_ty.base].inferred_ty;
463 trace!(?annotated_type);
464 let mut curr_projected_ty = PlaceTy::from_ty(annotated_type);
465
466 let tcx = self.infcx.tcx;
467
468 for proj in &user_ty.projs {
469 if !self.infcx.next_trait_solver()
472 && let ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) =
473 curr_projected_ty.ty.kind()
474 {
475 return Ok(());
479 }
480 let projected_ty = curr_projected_ty.projection_ty_core(
481 tcx,
482 proj,
483 |ty| self.normalize(ty::Unnormalized::new_wip(ty), locations),
484 |ty, variant_index, field, ()| {
485 PlaceTy::field_ty(tcx, ty, variant_index, field).skip_norm_wip()
486 },
487 |_| unreachable!(),
488 );
489 curr_projected_ty = projected_ty;
490 }
491 trace!(?curr_projected_ty);
492
493 let mut a = a;
500 let mut ty = curr_projected_ty.ty;
501 if !self.infcx.next_trait_solver() {
502 a = self.normalize(ty::Unnormalized::new_wip(a), locations);
503 ty = self.normalize(ty::Unnormalized::new_wip(ty), locations);
504 }
505 self.relate_types(ty, v.xform(ty::Contravariant), a, locations, category)?;
506
507 Ok(())
508 }
509
510 fn check_promoted(&mut self, promoted_body: &'a Body<'tcx>, location: Location) {
511 let parent_body = mem::replace(&mut self.body, promoted_body);
516
517 let polonius_facts = &mut None;
520 let mut constraints = Default::default();
521 let mut liveness_constraints =
522 LivenessValues::without_specific_points(Rc::new(DenseLocationMap::new(promoted_body)));
523 let mut deferred_closure_requirements = Default::default();
524
525 let mut swap_constraints = |this: &mut Self| {
528 mem::swap(this.polonius_facts, polonius_facts);
529 mem::swap(&mut this.constraints.outlives_constraints, &mut constraints);
530 mem::swap(&mut this.constraints.liveness_constraints, &mut liveness_constraints);
531 mem::swap(this.deferred_closure_requirements, &mut deferred_closure_requirements);
532 };
533
534 swap_constraints(self);
535
536 self.visit_body(promoted_body);
537
538 self.body = parent_body;
539
540 swap_constraints(self);
542 let locations = location.to_locations();
543 for constraint in constraints.outlives().iter() {
544 let mut constraint = *constraint;
545 constraint.locations = locations;
546 if let ConstraintCategory::Return(_)
547 | ConstraintCategory::UseAsConst
548 | ConstraintCategory::UseAsStatic = constraint.category
549 {
550 constraint.category = ConstraintCategory::Boring;
553 }
554 self.constraints.outlives_constraints.push(constraint)
555 }
556
557 for (closure_def_id, args, _locations) in deferred_closure_requirements {
564 self.deferred_closure_requirements.push((closure_def_id, args, locations));
565 }
566
567 #[allow(rustc::potential_query_instability)]
574 for region in liveness_constraints.live_regions_unordered() {
575 self.constraints.liveness_constraints.add_location(region, location);
576 }
577 }
578}
579
580impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
581 fn visit_span(&mut self, span: Span) {
582 if !span.is_dummy() {
583 {
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:583",
"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(583u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
::tracing_core::field::FieldSet::new(&["span"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&span) as
&dyn Value))])
});
} else { ; }
};debug!(?span);
584 self.last_span = span;
585 }
586 }
587
588 #[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(588u32),
::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(&[]) })
} 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")]
589 fn visit_body(&mut self, body: &Body<'tcx>) {
590 debug_assert!(std::ptr::eq(self.body, body));
591
592 for (local, local_decl) in body.local_decls.iter_enumerated() {
593 self.visit_local_decl(local, local_decl);
594 }
595
596 for (block, block_data) in body.basic_blocks.iter_enumerated() {
597 let mut location = Location { block, statement_index: 0 };
598 for stmt in &block_data.statements {
599 self.visit_statement(stmt, location);
600 location.statement_index += 1;
601 }
602
603 self.visit_terminator(block_data.terminator(), location);
604 self.check_iscleanup(block_data);
605 }
606 }
607
608 #[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(608u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
::tracing_core::field::FieldSet::new(&["stmt", "location"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&stmt)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&location)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = 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:644",
"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(644u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("assignment category: {0:?} {1:?}",
category,
place.as_local().map(|l| &self.body.local_decls[l])) as
&dyn 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:651",
"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(651u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
::tracing_core::field::FieldSet::new(&["place_ty"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&place_ty)
as &dyn 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:653",
"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(653u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("place_ty normalized: {0:?}",
place_ty) as &dyn 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:655",
"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(655u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
::tracing_core::field::FieldSet::new(&["rv_ty"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&rv_ty) as
&dyn 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:657",
"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(657u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("normalized rv_ty: {0:?}",
rv_ty) as &dyn 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")]
609 fn visit_statement(&mut self, stmt: &Statement<'tcx>, location: Location) {
610 self.super_statement(stmt, location);
611 let tcx = self.tcx();
612 match &stmt.kind {
613 StatementKind::Assign((place, rv)) => {
614 let category = match place.as_local() {
619 Some(RETURN_PLACE) => {
620 let defining_ty = &self.universal_regions.defining_ty;
621 if defining_ty.is_const() {
622 if tcx.is_static(defining_ty.def_id()) {
623 ConstraintCategory::UseAsStatic
624 } else {
625 ConstraintCategory::UseAsConst
626 }
627 } else {
628 ConstraintCategory::Return(ReturnConstraint::Normal)
629 }
630 }
631 Some(l)
632 if matches!(
633 self.body.local_decls[l].local_info(),
634 LocalInfo::AggregateTemp
635 ) =>
636 {
637 ConstraintCategory::Usage
638 }
639 Some(l) if !self.body.local_decls[l].is_user_variable() => {
640 ConstraintCategory::Boring
641 }
642 _ => ConstraintCategory::Assignment,
643 };
644 debug!(
645 "assignment category: {:?} {:?}",
646 category,
647 place.as_local().map(|l| &self.body.local_decls[l])
648 );
649
650 let place_ty = place.ty(self.body, tcx).ty;
651 debug!(?place_ty);
652 let place_ty = self.normalize(ty::Unnormalized::new_wip(place_ty), location);
653 debug!("place_ty normalized: {:?}", place_ty);
654 let rv_ty = rv.ty(self.body, tcx);
655 debug!(?rv_ty);
656 let rv_ty = self.normalize(ty::Unnormalized::new_wip(rv_ty), location);
657 debug!("normalized rv_ty: {:?}", rv_ty);
658 if let Err(terr) =
659 self.sub_types(rv_ty, place_ty, location.to_locations(), category)
660 {
661 span_mirbug!(
662 self,
663 stmt,
664 "bad assignment ({:?} = {:?}): {:?}",
665 place_ty,
666 rv_ty,
667 terr
668 );
669 }
670
671 if let Some(annotation_index) = self.rvalue_user_ty(rv)
672 && let Err(terr) = self.relate_type_and_user_type(
673 rv_ty,
674 ty::Invariant,
675 &UserTypeProjection { base: annotation_index, projs: vec![] },
676 location.to_locations(),
677 ConstraintCategory::TypeAnnotation(AnnotationSource::GenericArg),
678 )
679 {
680 let annotation = &self.user_type_annotations[annotation_index];
681 span_mirbug!(
682 self,
683 stmt,
684 "bad user type on rvalue ({:?} = {:?}): {:?}",
685 annotation,
686 rv_ty,
687 terr
688 );
689 }
690
691 if !self.tcx().features().unsized_fn_params() {
692 let trait_ref = ty::TraitRef::new(
693 tcx,
694 tcx.require_lang_item(LangItem::Sized, self.last_span),
695 [place_ty],
696 );
697 self.prove_trait_ref(
698 trait_ref,
699 location.to_locations(),
700 ConstraintCategory::SizedBound,
701 );
702 }
703 }
704 StatementKind::AscribeUserType((place, projection), variance) => {
705 let place_ty = place.ty(self.body, tcx).ty;
706 if let Err(terr) = self.relate_type_and_user_type(
707 place_ty,
708 *variance,
709 projection,
710 Locations::All(stmt.source_info.span),
711 ConstraintCategory::TypeAnnotation(AnnotationSource::Ascription),
712 ) {
713 let annotation = &self.user_type_annotations[projection.base];
714 span_mirbug!(
715 self,
716 stmt,
717 "bad type assert ({:?} <: {:?} with projections {:?}): {:?}",
718 place_ty,
719 annotation,
720 projection.projs,
721 terr
722 );
723 }
724 }
725 StatementKind::Intrinsic(NonDivergingIntrinsic::Assume(..))
726 | StatementKind::FakeRead(..)
727 | StatementKind::StorageLive(..)
728 | StatementKind::StorageDead(..)
729 | StatementKind::Coverage(..)
730 | StatementKind::ConstEvalCounter
731 | StatementKind::PlaceMention(..)
732 | StatementKind::BackwardIncompatibleDropHint { .. }
733 | StatementKind::Nop => {}
734 StatementKind::Intrinsic(NonDivergingIntrinsic::CopyNonOverlapping(..))
735 | StatementKind::SetDiscriminant { .. } => {
736 bug!("Statement not allowed in this MIR phase")
737 }
738 }
739 }
740
741 #[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(741u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
::tracing_core::field::FieldSet::new(&["term",
"term_location"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&term)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&term_location)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = 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:745",
"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(745u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("terminator kind: {0:?}",
term.kind) as &dyn 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:780",
"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(780u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("func_ty.kind: {0:?}",
func_ty.kind()) as &dyn 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:814",
"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(814u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
::tracing_core::field::FieldSet::new(&["unnormalized_sig"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&unnormalized_sig)
as &dyn Value))])
});
} else { ; }
};
self.prove_predicates(unnormalized_sig.inputs_and_output.iter().map(|ty|
{
ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(ty.into())))
}), term_location.to_locations(),
ConstraintCategory::Boring);
let sig =
self.deeply_normalize(unnormalized_sig, term_location);
if sig != unnormalized_sig {
self.prove_predicates(sig.inputs_and_output.iter().map(|ty|
{
ty::Binder::dummy(ty::PredicateKind::Clause(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")]
742 fn visit_terminator(&mut self, term: &Terminator<'tcx>, term_location: Location) {
743 self.super_terminator(term, term_location);
744 let tcx = self.tcx();
745 debug!("terminator kind: {:?}", term.kind);
746 match &term.kind {
747 TerminatorKind::Goto { .. }
748 | TerminatorKind::UnwindResume
749 | TerminatorKind::UnwindTerminate(_)
750 | TerminatorKind::Return
751 | TerminatorKind::CoroutineDrop
752 | TerminatorKind::Unreachable
753 | TerminatorKind::Drop { .. }
754 | TerminatorKind::FalseEdge { .. }
755 | TerminatorKind::FalseUnwind { .. }
756 | TerminatorKind::InlineAsm { .. } => {
757 }
759
760 TerminatorKind::SwitchInt { discr, .. } => {
761 let switch_ty = discr.ty(self.body, tcx);
762 if !switch_ty.is_integral() && !switch_ty.is_char() && !switch_ty.is_bool() {
763 span_mirbug!(self, term, "bad SwitchInt discr ty {:?}", switch_ty);
764 }
765 }
767 TerminatorKind::Call { func, args, .. }
768 | TerminatorKind::TailCall { func, args, .. } => {
769 let (call_source, destination, is_diverging) = match term.kind {
770 TerminatorKind::Call { call_source, destination, target, .. } => {
771 (call_source, destination, target.is_none())
772 }
773 TerminatorKind::TailCall { .. } => {
774 (CallSource::Normal, RETURN_PLACE.into(), false)
775 }
776 _ => unreachable!(),
777 };
778
779 let func_ty = func.ty(self.body, tcx);
780 debug!("func_ty.kind: {:?}", func_ty.kind());
781
782 let sig = match func_ty.kind() {
783 ty::FnDef(..) | ty::FnPtr(..) => func_ty.fn_sig(tcx),
784 _ => {
785 span_mirbug!(self, term, "call to non-function {:?}", func_ty);
786 return;
787 }
788 };
789 let (unnormalized_sig, map) = tcx.instantiate_bound_regions(sig, |br| {
790 use crate::renumber::RegionCtxt;
791
792 let region_ctxt_fn = || {
793 let reg_info = match br.kind {
794 ty::BoundRegionKind::Anon => sym::anon,
795 ty::BoundRegionKind::Named(def_id) => tcx.item_name(def_id),
796 ty::BoundRegionKind::ClosureEnv => sym::env,
797 ty::BoundRegionKind::NamedForPrinting(_) => {
798 bug!("only used for pretty printing")
799 }
800 };
801
802 RegionCtxt::LateBound(reg_info)
803 };
804
805 self.infcx.next_region_var(
806 RegionVariableOrigin::BoundRegion(
807 term.source_info.span,
808 br.kind,
809 BoundRegionConversionTime::FnCall,
810 ),
811 region_ctxt_fn,
812 )
813 });
814 debug!(?unnormalized_sig);
815 self.prove_predicates(
824 unnormalized_sig.inputs_and_output.iter().map(|ty| {
825 ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(
826 ty.into(),
827 )))
828 }),
829 term_location.to_locations(),
830 ConstraintCategory::Boring,
831 );
832
833 let sig = self.deeply_normalize(unnormalized_sig, term_location);
834 if sig != unnormalized_sig {
838 self.prove_predicates(
839 sig.inputs_and_output.iter().map(|ty| {
840 ty::Binder::dummy(ty::PredicateKind::Clause(
841 ty::ClauseKind::WellFormed(ty.into()),
842 ))
843 }),
844 term_location.to_locations(),
845 ConstraintCategory::Boring,
846 );
847 }
848
849 self.check_call_dest(term, &sig, destination, is_diverging, term_location);
850
851 for &late_bound_region in map.values() {
859 let region_vid = self.universal_regions.to_region_vid(late_bound_region);
860 self.constraints.liveness_constraints.add_location(region_vid, term_location);
861 }
862
863 self.check_call_inputs(term, func, &sig, args, term_location, call_source);
864 }
865 TerminatorKind::Assert { cond, msg, .. } => {
866 let cond_ty = cond.ty(self.body, tcx);
867 if cond_ty != tcx.types.bool {
868 span_mirbug!(self, term, "bad Assert ({:?}, not bool", cond_ty);
869 }
870
871 if let AssertKind::BoundsCheck { len, index } = &**msg {
872 if len.ty(self.body, tcx) != tcx.types.usize {
873 span_mirbug!(self, len, "bounds-check length non-usize {:?}", len)
874 }
875 if index.ty(self.body, tcx) != tcx.types.usize {
876 span_mirbug!(self, index, "bounds-check index non-usize {:?}", index)
877 }
878 }
879 }
880 TerminatorKind::Yield { value, resume_arg, .. } => {
881 match self.body.yield_ty() {
882 None => span_mirbug!(self, term, "yield in non-coroutine"),
883 Some(ty) => {
884 let value_ty = value.ty(self.body, tcx);
885 if let Err(terr) = self.sub_types(
886 value_ty,
887 ty,
888 term_location.to_locations(),
889 ConstraintCategory::Yield,
890 ) {
891 span_mirbug!(
892 self,
893 term,
894 "type of yield value is {:?}, but the yield type is {:?}: {:?}",
895 value_ty,
896 ty,
897 terr
898 );
899 }
900 }
901 }
902
903 match self.body.resume_ty() {
904 None => span_mirbug!(self, term, "yield in non-coroutine"),
905 Some(ty) => {
906 let resume_ty = resume_arg.ty(self.body, tcx);
907 if let Err(terr) = self.sub_types(
908 ty,
909 resume_ty.ty,
910 term_location.to_locations(),
911 ConstraintCategory::Yield,
912 ) {
913 span_mirbug!(
914 self,
915 term,
916 "type of resume place is {:?}, but the resume type is {:?}: {:?}",
917 resume_ty,
918 ty,
919 terr
920 );
921 }
922 }
923 }
924 }
925 }
926 }
927
928 fn visit_local_decl(&mut self, local: Local, local_decl: &LocalDecl<'tcx>) {
929 self.super_local_decl(local, local_decl);
930
931 for user_ty in
932 local_decl.user_ty.as_deref().into_iter().flat_map(UserTypeProjections::projections)
933 {
934 let span = self.user_type_annotations[user_ty.base].span;
935
936 let ty = if local_decl.is_nonref_binding() {
937 local_decl.ty
938 } else if let &ty::Ref(_, rty, _) = local_decl.ty.kind() {
939 rty
943 } else {
944 ::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);
945 };
946
947 if let Err(terr) = self.relate_type_and_user_type(
948 ty,
949 ty::Invariant,
950 user_ty,
951 Locations::All(span),
952 ConstraintCategory::TypeAnnotation(AnnotationSource::Declaration),
953 ) {
954 {
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!(
955 self,
956 local,
957 "bad user type on variable {:?}: {:?} != {:?} ({:?})",
958 local,
959 local_decl.ty,
960 local_decl.user_ty,
961 terr,
962 );
963 }
964 }
965
966 if !self.tcx().features().unsized_fn_params() {
970 match self.body.local_kind(local) {
971 LocalKind::ReturnPointer | LocalKind::Arg => {
972 return;
979 }
980 LocalKind::Temp => {
981 let span = local_decl.source_info.span;
982 let ty = local_decl.ty;
983 self.ensure_place_sized(ty, span);
984 }
985 }
986 }
987 }
988
989 #[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(989u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
::tracing_core::field::FieldSet::new(&["rvalue",
"location"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&rvalue)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&location)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = 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_predicate(ty::PredicateKind::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_predicate(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_predicate(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:1536",
"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(1536u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
::tracing_core::field::FieldSet::new(&["src_tty", "dst_tty",
"src_obj", "dst_obj"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&src_tty) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&dst_tty) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&src_obj) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&dst_obj) as
&dyn 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 => {
::rustc_middle::util::bug::bug_fmt(format_args!("CastKind::Subtype shouldn\'t exist in borrowck"))
}
}
}
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")]
990 fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
991 self.super_rvalue(rvalue, location);
992 let tcx = self.tcx();
993 let span = self.body.source_info(location).span;
994 match rvalue {
995 Rvalue::Aggregate(ak, ops) => self.check_aggregate_rvalue(rvalue, ak, ops, location),
996
997 Rvalue::Repeat(operand, len) => {
998 let array_ty = rvalue.ty(self.body.local_decls(), tcx);
999 self.prove_predicate(
1000 ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(array_ty.into())),
1001 Locations::Single(location),
1002 ConstraintCategory::Boring,
1003 );
1004
1005 if len.try_to_target_usize(tcx).is_none_or(|len| len > 1) {
1010 match operand {
1011 Operand::Copy(..) | Operand::Constant(..) | Operand::RuntimeChecks(_) => {
1012 }
1015 Operand::Move(place) => {
1016 let ty = place.ty(self.body, tcx).ty;
1018 let trait_ref = ty::TraitRef::new(
1019 tcx,
1020 tcx.require_lang_item(LangItem::Copy, span),
1021 [ty],
1022 );
1023
1024 self.prove_trait_ref(
1025 trait_ref,
1026 Locations::Single(location),
1027 ConstraintCategory::CopyBound,
1028 );
1029 }
1030 }
1031 }
1032 }
1033
1034 Rvalue::Cast(cast_kind, op, ty) => {
1035 match *cast_kind {
1036 CastKind::PointerCoercion(
1037 PointerCoercion::ReifyFnPointer(target_safety),
1038 coercion_source,
1039 ) => {
1040 let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
1041 let src_ty = op.ty(self.body, tcx);
1042 let mut src_sig = src_ty.fn_sig(tcx);
1043 if let ty::FnDef(def_id, _) = *src_ty.kind()
1044 && let ty::FnPtr(_, target_hdr) = *ty.kind()
1045 && tcx.codegen_fn_attrs(def_id).safe_target_features
1046 && target_hdr.safety().is_safe()
1047 && let Some(safe_sig) = tcx.adjust_target_feature_sig(
1048 def_id,
1049 src_sig,
1050 self.body.source.def_id(),
1051 )
1052 {
1053 src_sig = safe_sig;
1054 }
1055
1056 if src_sig.safety().is_safe() && target_safety.is_unsafe() {
1057 src_sig = tcx.safe_to_unsafe_sig(src_sig);
1058 }
1059
1060 if src_sig.has_bound_regions()
1075 && let ty::FnPtr(target_fn_tys, target_hdr) = *ty.kind()
1076 && let target_sig = target_fn_tys.with(target_hdr)
1077 && let Some(target_sig) = target_sig.no_bound_vars()
1078 {
1079 let src_sig = self.infcx.instantiate_binder_with_fresh_vars(
1080 span,
1081 BoundRegionConversionTime::HigherRankedType,
1082 src_sig,
1083 );
1084 let src_ty = Ty::new_fn_ptr(self.tcx(), ty::Binder::dummy(src_sig));
1085 self.prove_predicate(
1086 ty::ClauseKind::WellFormed(src_ty.into()),
1087 location.to_locations(),
1088 ConstraintCategory::Cast {
1089 is_raw_ptr_dyn_type_cast: false,
1090 is_implicit_coercion,
1091 unsize_to: None,
1092 },
1093 );
1094
1095 let src_ty =
1096 self.normalize(ty::Unnormalized::new_wip(src_ty), location);
1097 if let Err(terr) = self.sub_types(
1098 src_ty,
1099 *ty,
1100 location.to_locations(),
1101 ConstraintCategory::Cast {
1102 is_raw_ptr_dyn_type_cast: false,
1103 is_implicit_coercion,
1104 unsize_to: None,
1105 },
1106 ) {
1107 span_mirbug!(
1108 self,
1109 rvalue,
1110 "equating {:?} with {:?} yields {:?}",
1111 target_sig,
1112 src_sig,
1113 terr
1114 );
1115 };
1116 }
1117
1118 let src_ty = Ty::new_fn_ptr(tcx, src_sig);
1119 self.prove_predicate(
1124 ty::ClauseKind::WellFormed(src_ty.into()),
1125 location.to_locations(),
1126 ConstraintCategory::Cast {
1127 is_raw_ptr_dyn_type_cast: false,
1128 is_implicit_coercion,
1129 unsize_to: None,
1130 },
1131 );
1132
1133 let src_ty = self.normalize(ty::Unnormalized::new_wip(src_ty), location);
1139 if let Err(terr) = self.sub_types(
1140 src_ty,
1141 *ty,
1142 location.to_locations(),
1143 ConstraintCategory::Cast {
1144 is_raw_ptr_dyn_type_cast: false,
1145 is_implicit_coercion,
1146 unsize_to: None,
1147 },
1148 ) {
1149 span_mirbug!(
1150 self,
1151 rvalue,
1152 "equating {:?} with {:?} yields {:?}",
1153 src_ty,
1154 ty,
1155 terr
1156 );
1157 }
1158 }
1159
1160 CastKind::PointerCoercion(
1161 PointerCoercion::ClosureFnPointer(safety),
1162 coercion_source,
1163 ) => {
1164 let sig = match op.ty(self.body, tcx).kind() {
1165 ty::Closure(_, args) => args.as_closure().sig(),
1166 _ => bug!(),
1167 };
1168 let ty_fn_ptr_from =
1169 Ty::new_fn_ptr(tcx, tcx.signature_unclosure(sig, safety));
1170
1171 let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
1172 if let Err(terr) = self.sub_types(
1173 ty_fn_ptr_from,
1174 *ty,
1175 location.to_locations(),
1176 ConstraintCategory::Cast {
1177 is_raw_ptr_dyn_type_cast: false,
1178 is_implicit_coercion,
1179 unsize_to: None,
1180 },
1181 ) {
1182 span_mirbug!(
1183 self,
1184 rvalue,
1185 "equating {:?} with {:?} yields {:?}",
1186 ty_fn_ptr_from,
1187 ty,
1188 terr
1189 );
1190 }
1191 }
1192
1193 CastKind::PointerCoercion(
1194 PointerCoercion::UnsafeFnPointer,
1195 coercion_source,
1196 ) => {
1197 let fn_sig = op.ty(self.body, tcx).fn_sig(tcx);
1198
1199 let fn_sig = self.normalize(ty::Unnormalized::new_wip(fn_sig), location);
1205
1206 let ty_fn_ptr_from = tcx.safe_to_unsafe_fn_ty(fn_sig);
1207
1208 let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
1209 if let Err(terr) = self.sub_types(
1210 ty_fn_ptr_from,
1211 *ty,
1212 location.to_locations(),
1213 ConstraintCategory::Cast {
1214 is_raw_ptr_dyn_type_cast: false,
1215 is_implicit_coercion,
1216 unsize_to: None,
1217 },
1218 ) {
1219 span_mirbug!(
1220 self,
1221 rvalue,
1222 "equating {:?} with {:?} yields {:?}",
1223 ty_fn_ptr_from,
1224 ty,
1225 terr
1226 );
1227 }
1228 }
1229
1230 CastKind::PointerCoercion(PointerCoercion::Unsize, coercion_source) => {
1231 let &ty = ty;
1232 let trait_ref = ty::TraitRef::new(
1233 tcx,
1234 tcx.require_lang_item(LangItem::CoerceUnsized, span),
1235 [op.ty(self.body, tcx), ty],
1236 );
1237
1238 let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
1239 let unsize_to = fold_regions(tcx, ty, |r, _| {
1240 if let ty::ReVar(_) = r.kind() { tcx.lifetimes.re_erased } else { r }
1241 });
1242 self.prove_trait_ref(
1243 trait_ref,
1244 location.to_locations(),
1245 ConstraintCategory::Cast {
1246 is_raw_ptr_dyn_type_cast: false,
1247 is_implicit_coercion,
1248 unsize_to: Some(unsize_to),
1249 },
1250 );
1251 }
1252
1253 CastKind::PointerCoercion(
1254 PointerCoercion::MutToConstPointer,
1255 coercion_source,
1256 ) => {
1257 let ty::RawPtr(ty_from, hir::Mutability::Mut) =
1258 op.ty(self.body, tcx).kind()
1259 else {
1260 span_mirbug!(self, rvalue, "unexpected base type for cast {:?}", ty,);
1261 return;
1262 };
1263 let ty::RawPtr(ty_to, hir::Mutability::Not) = ty.kind() else {
1264 span_mirbug!(self, rvalue, "unexpected target type for cast {:?}", ty,);
1265 return;
1266 };
1267 let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
1268 if let Err(terr) = self.sub_types(
1269 *ty_from,
1270 *ty_to,
1271 location.to_locations(),
1272 ConstraintCategory::Cast {
1273 is_raw_ptr_dyn_type_cast: false,
1274 is_implicit_coercion,
1275 unsize_to: None,
1276 },
1277 ) {
1278 span_mirbug!(
1279 self,
1280 rvalue,
1281 "relating {:?} with {:?} yields {:?}",
1282 ty_from,
1283 ty_to,
1284 terr
1285 );
1286 }
1287 }
1288
1289 CastKind::PointerCoercion(PointerCoercion::ArrayToPointer, coercion_source) => {
1290 let ty_from = op.ty(self.body, tcx);
1291
1292 let opt_ty_elem_mut = match ty_from.kind() {
1293 ty::RawPtr(array_ty, array_mut) => match array_ty.kind() {
1294 ty::Array(ty_elem, _) => Some((ty_elem, *array_mut)),
1295 _ => None,
1296 },
1297 _ => None,
1298 };
1299
1300 let Some((ty_elem, ty_mut)) = opt_ty_elem_mut else {
1301 span_mirbug!(
1302 self,
1303 rvalue,
1304 "ArrayToPointer cast from unexpected type {:?}",
1305 ty_from,
1306 );
1307 return;
1308 };
1309
1310 let (ty_to, ty_to_mut) = match ty.kind() {
1311 ty::RawPtr(ty_to, ty_to_mut) => (ty_to, *ty_to_mut),
1312 _ => {
1313 span_mirbug!(
1314 self,
1315 rvalue,
1316 "ArrayToPointer cast to unexpected type {:?}",
1317 ty,
1318 );
1319 return;
1320 }
1321 };
1322
1323 if ty_to_mut.is_mut() && ty_mut.is_not() {
1324 span_mirbug!(
1325 self,
1326 rvalue,
1327 "ArrayToPointer cast from const {:?} to mut {:?}",
1328 ty,
1329 ty_to
1330 );
1331 return;
1332 }
1333
1334 let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
1335 if let Err(terr) = self.sub_types(
1336 *ty_elem,
1337 *ty_to,
1338 location.to_locations(),
1339 ConstraintCategory::Cast {
1340 is_raw_ptr_dyn_type_cast: false,
1341 is_implicit_coercion,
1342 unsize_to: None,
1343 },
1344 ) {
1345 span_mirbug!(
1346 self,
1347 rvalue,
1348 "relating {:?} with {:?} yields {:?}",
1349 ty_elem,
1350 ty_to,
1351 terr
1352 )
1353 }
1354 }
1355
1356 CastKind::PointerExposeProvenance => {
1357 let ty_from = op.ty(self.body, tcx);
1358 let cast_ty_from = CastTy::from_ty(ty_from);
1359 let cast_ty_to = CastTy::from_ty(*ty);
1360 match (cast_ty_from, cast_ty_to) {
1361 (Some(CastTy::Ptr(_) | CastTy::FnPtr), Some(CastTy::Int(_))) => (),
1362 _ => {
1363 span_mirbug!(
1364 self,
1365 rvalue,
1366 "Invalid PointerExposeProvenance cast {:?} -> {:?}",
1367 ty_from,
1368 ty
1369 )
1370 }
1371 }
1372 }
1373
1374 CastKind::PointerWithExposedProvenance => {
1375 let ty_from = op.ty(self.body, tcx);
1376 let cast_ty_from = CastTy::from_ty(ty_from);
1377 let cast_ty_to = CastTy::from_ty(*ty);
1378 match (cast_ty_from, cast_ty_to) {
1379 (Some(CastTy::Int(_)), Some(CastTy::Ptr(_))) => (),
1380 _ => {
1381 span_mirbug!(
1382 self,
1383 rvalue,
1384 "Invalid PointerWithExposedProvenance cast {:?} -> {:?}",
1385 ty_from,
1386 ty
1387 )
1388 }
1389 }
1390 }
1391 CastKind::IntToInt => {
1392 let ty_from = op.ty(self.body, tcx);
1393 let cast_ty_from = CastTy::from_ty(ty_from);
1394 let cast_ty_to = CastTy::from_ty(*ty);
1395 match (cast_ty_from, cast_ty_to) {
1396 (Some(CastTy::Int(_)), Some(CastTy::Int(_))) => (),
1397 _ => {
1398 span_mirbug!(
1399 self,
1400 rvalue,
1401 "Invalid IntToInt cast {:?} -> {:?}",
1402 ty_from,
1403 ty
1404 )
1405 }
1406 }
1407 }
1408 CastKind::IntToFloat => {
1409 let ty_from = op.ty(self.body, tcx);
1410 let cast_ty_from = CastTy::from_ty(ty_from);
1411 let cast_ty_to = CastTy::from_ty(*ty);
1412 match (cast_ty_from, cast_ty_to) {
1413 (Some(CastTy::Int(_)), Some(CastTy::Float)) => (),
1414 _ => {
1415 span_mirbug!(
1416 self,
1417 rvalue,
1418 "Invalid IntToFloat cast {:?} -> {:?}",
1419 ty_from,
1420 ty
1421 )
1422 }
1423 }
1424 }
1425 CastKind::FloatToInt => {
1426 let ty_from = op.ty(self.body, tcx);
1427 let cast_ty_from = CastTy::from_ty(ty_from);
1428 let cast_ty_to = CastTy::from_ty(*ty);
1429 match (cast_ty_from, cast_ty_to) {
1430 (Some(CastTy::Float), Some(CastTy::Int(_))) => (),
1431 _ => {
1432 span_mirbug!(
1433 self,
1434 rvalue,
1435 "Invalid FloatToInt cast {:?} -> {:?}",
1436 ty_from,
1437 ty
1438 )
1439 }
1440 }
1441 }
1442 CastKind::FloatToFloat => {
1443 let ty_from = op.ty(self.body, tcx);
1444 let cast_ty_from = CastTy::from_ty(ty_from);
1445 let cast_ty_to = CastTy::from_ty(*ty);
1446 match (cast_ty_from, cast_ty_to) {
1447 (Some(CastTy::Float), Some(CastTy::Float)) => (),
1448 _ => {
1449 span_mirbug!(
1450 self,
1451 rvalue,
1452 "Invalid FloatToFloat cast {:?} -> {:?}",
1453 ty_from,
1454 ty
1455 )
1456 }
1457 }
1458 }
1459 CastKind::FnPtrToPtr => {
1460 let ty_from = op.ty(self.body, tcx);
1461 let cast_ty_from = CastTy::from_ty(ty_from);
1462 let cast_ty_to = CastTy::from_ty(*ty);
1463 match (cast_ty_from, cast_ty_to) {
1464 (Some(CastTy::FnPtr), Some(CastTy::Ptr(_))) => (),
1465 _ => {
1466 span_mirbug!(
1467 self,
1468 rvalue,
1469 "Invalid FnPtrToPtr cast {:?} -> {:?}",
1470 ty_from,
1471 ty
1472 )
1473 }
1474 }
1475 }
1476 CastKind::PtrToPtr => {
1477 let ty_from = op.ty(self.body, tcx);
1478 let Some(CastTy::Ptr(src)) = CastTy::from_ty(ty_from) else {
1479 unreachable!();
1480 };
1481 let Some(CastTy::Ptr(dst)) = CastTy::from_ty(*ty) else {
1482 unreachable!();
1483 };
1484
1485 if self.infcx.type_is_sized_modulo_regions(self.infcx.param_env, dst.ty) {
1486 let trait_ref = ty::TraitRef::new(
1492 tcx,
1493 tcx.require_lang_item(LangItem::Sized, self.last_span),
1494 [dst.ty],
1495 );
1496 self.prove_trait_ref(
1497 trait_ref,
1498 location.to_locations(),
1499 ConstraintCategory::Cast {
1500 is_raw_ptr_dyn_type_cast: false,
1501 is_implicit_coercion: true,
1502 unsize_to: None,
1503 },
1504 );
1505 } else if let ty::Dynamic(src_tty, src_lt) =
1506 *self.struct_tail(src.ty, location).kind()
1507 && let ty::Dynamic(dst_tty, dst_lt) =
1508 *self.struct_tail(dst.ty, location).kind()
1509 {
1510 match (src_tty.principal(), dst_tty.principal()) {
1511 (Some(_), Some(_)) => {
1512 let src_obj = Ty::new_dynamic(
1522 tcx,
1523 tcx.mk_poly_existential_predicates(
1524 &src_tty.without_auto_traits().collect::<Vec<_>>(),
1525 ),
1526 src_lt,
1527 );
1528 let dst_obj = Ty::new_dynamic(
1529 tcx,
1530 tcx.mk_poly_existential_predicates(
1531 &dst_tty.without_auto_traits().collect::<Vec<_>>(),
1532 ),
1533 dst_lt,
1534 );
1535
1536 debug!(?src_tty, ?dst_tty, ?src_obj, ?dst_obj);
1537
1538 self.sub_types(
1547 src_obj,
1548 dst_obj,
1549 location.to_locations(),
1550 ConstraintCategory::Cast {
1551 is_raw_ptr_dyn_type_cast: true,
1552 is_implicit_coercion: false,
1553 unsize_to: None,
1554 },
1555 )
1556 .unwrap();
1557 }
1558 (None, None) => {
1559 let src_lt = self.universal_regions.to_region_vid(src_lt);
1563 let dst_lt = self.universal_regions.to_region_vid(dst_lt);
1564
1565 self.constraints.outlives_constraints.push(
1568 OutlivesConstraint {
1569 sup: src_lt,
1570 sub: dst_lt,
1571 locations: location.to_locations(),
1572 span: location.to_locations().span(self.body),
1573 category: ConstraintCategory::Cast {
1574 is_raw_ptr_dyn_type_cast: true,
1575 is_implicit_coercion: false,
1576 unsize_to: None,
1577 },
1578 variance_info: ty::VarianceDiagInfo::default(),
1579 from_closure: false,
1580 },
1581 );
1582 }
1583 (None, Some(_)) => bug!(
1584 "introducing a principal should have errored in HIR typeck"
1585 ),
1586 (Some(_), None) => {
1587 bug!("dropping the principal should have been an unsizing cast")
1588 }
1589 }
1590 }
1591 }
1592 CastKind::Transmute => {
1593 let ty_from = op.ty(self.body, tcx);
1594 match ty_from.kind() {
1595 ty::Pat(base, _) if base == ty => {}
1596 _ => span_mirbug!(
1597 self,
1598 rvalue,
1599 "Unexpected CastKind::Transmute {ty_from:?} -> {ty:?}, which is not permitted in Analysis MIR",
1600 ),
1601 }
1602 }
1603 CastKind::Subtype => {
1604 bug!("CastKind::Subtype shouldn't exist in borrowck")
1605 }
1606 }
1607 }
1608
1609 Rvalue::Ref(region, _borrow_kind, borrowed_place) => {
1610 self.add_reborrow_constraint(location, *region, borrowed_place);
1611 }
1612
1613 Rvalue::Reborrow(target, mutability, borrowed_place) => {
1614 self.add_generic_reborrow_constraint(
1615 *mutability,
1616 location,
1617 borrowed_place,
1618 *target,
1619 );
1620 }
1621
1622 Rvalue::BinaryOp(
1623 BinOp::Eq | BinOp::Ne | BinOp::Lt | BinOp::Le | BinOp::Gt | BinOp::Ge,
1624 (left, right),
1625 ) => {
1626 let ty_left = left.ty(self.body, tcx);
1627 match ty_left.kind() {
1628 ty::RawPtr(_, _) | ty::FnPtr(..) => {
1630 let ty_right = right.ty(self.body, tcx);
1631 let common_ty =
1632 self.infcx.next_ty_var(self.body.source_info(location).span);
1633 self.sub_types(
1634 ty_left,
1635 common_ty,
1636 location.to_locations(),
1637 ConstraintCategory::CallArgument(None),
1638 )
1639 .unwrap_or_else(|err| {
1640 bug!("Could not equate type variable with {:?}: {:?}", ty_left, err)
1641 });
1642 if let Err(terr) = self.sub_types(
1643 ty_right,
1644 common_ty,
1645 location.to_locations(),
1646 ConstraintCategory::CallArgument(None),
1647 ) {
1648 span_mirbug!(
1649 self,
1650 rvalue,
1651 "unexpected comparison types {:?} and {:?} yields {:?}",
1652 ty_left,
1653 ty_right,
1654 terr
1655 )
1656 }
1657 }
1658 ty::Int(_) | ty::Uint(_) | ty::Bool | ty::Char | ty::Float(_)
1661 if ty_left == right.ty(self.body, tcx) => {}
1662 _ => span_mirbug!(
1665 self,
1666 rvalue,
1667 "unexpected comparison types {:?} and {:?}",
1668 ty_left,
1669 right.ty(self.body, tcx)
1670 ),
1671 }
1672 }
1673
1674 Rvalue::WrapUnsafeBinder(op, ty) => {
1675 let operand_ty = op.ty(self.body, self.tcx());
1676 let ty::UnsafeBinder(binder_ty) = *ty.kind() else {
1677 unreachable!();
1678 };
1679 let expected_ty = self.infcx.instantiate_binder_with_fresh_vars(
1680 self.body().source_info(location).span,
1681 BoundRegionConversionTime::HigherRankedType,
1682 binder_ty.into(),
1683 );
1684 self.sub_types(
1685 operand_ty,
1686 expected_ty,
1687 location.to_locations(),
1688 ConstraintCategory::Boring,
1689 )
1690 .unwrap();
1691 }
1692
1693 Rvalue::Use(_, _)
1694 | Rvalue::UnaryOp(_, _)
1695 | Rvalue::CopyForDeref(_)
1696 | Rvalue::BinaryOp(..)
1697 | Rvalue::RawPtr(..)
1698 | Rvalue::ThreadLocalRef(..)
1699 | Rvalue::Discriminant(..) => {}
1700 }
1701 }
1702
1703 #[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(1703u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
::tracing_core::field::FieldSet::new(&["op", "location"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&op)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&location)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = 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::InlineConst {
let def_id = def_id.expect_local();
let predicates =
self.prove_closure_bounds(tcx, def_id, uv.args, location);
self.normalize_and_prove_instantiated_predicates(def_id.to_def_id(),
predicates, location.to_locations());
}
}
}
}
}
}
}#[instrument(level = "debug", skip(self))]
1704 fn visit_operand(&mut self, op: &Operand<'tcx>, location: Location) {
1705 self.super_operand(op, location);
1706 if let Operand::Constant(constant) = op {
1707 let maybe_uneval = match constant.const_ {
1708 Const::Val(..) | Const::Ty(_, _) => None,
1709 Const::Unevaluated(uv, _) => Some(uv),
1710 };
1711
1712 if let Some(uv) = maybe_uneval {
1713 if uv.promoted.is_none() {
1714 let tcx = self.tcx();
1715 let def_id = uv.def;
1716 if tcx.def_kind(def_id) == DefKind::InlineConst {
1717 let def_id = def_id.expect_local();
1718 let predicates = self.prove_closure_bounds(tcx, def_id, uv.args, location);
1719 self.normalize_and_prove_instantiated_predicates(
1720 def_id.to_def_id(),
1721 predicates,
1722 location.to_locations(),
1723 );
1724 }
1725 }
1726 }
1727 }
1728 }
1729
1730 #[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(1730u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
::tracing_core::field::FieldSet::new(&["constant",
"location"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&constant)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&location)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = 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::Unevaluated(uv) =>
match uv.kind {
ty::UnevaluatedConstKind::Projection { def_id } |
ty::UnevaluatedConstKind::Inherent { def_id } |
ty::UnevaluatedConstKind::Free { def_id } |
ty::UnevaluatedConstKind::Anon { def_id } => {
Some(UnevaluatedConst {
def: def_id,
args: uv.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 instantiated_predicates =
tcx.predicates_of(def_id).instantiate(tcx, args);
self.normalize_and_prove_instantiated_predicates(def_id,
instantiated_predicates, 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_predicates(args.types().map(|ty|
ty::ClauseKind::WellFormed(ty.into())), locations,
ConstraintCategory::Boring);
}
}
}
}
}#[instrument(level = "debug", skip(self))]
1731 fn visit_const_operand(&mut self, constant: &ConstOperand<'tcx>, location: Location) {
1732 self.super_const_operand(constant, location);
1733 let ty = constant.const_.ty();
1734
1735 self.infcx.tcx.for_each_free_region(&ty, |live_region| {
1736 let live_region_vid = self.universal_regions.to_region_vid(live_region);
1737 self.constraints.liveness_constraints.add_location(live_region_vid, location);
1738 });
1739
1740 let locations = location.to_locations();
1741 if let Some(annotation_index) = constant.user_ty {
1742 if let Err(terr) = self.relate_type_and_user_type(
1743 constant.const_.ty(),
1744 ty::Invariant,
1745 &UserTypeProjection { base: annotation_index, projs: vec![] },
1746 locations,
1747 ConstraintCategory::TypeAnnotation(AnnotationSource::GenericArg),
1748 ) {
1749 let annotation = &self.user_type_annotations[annotation_index];
1750 span_mirbug!(
1751 self,
1752 constant,
1753 "bad constant user type {:?} vs {:?}: {:?}",
1754 annotation,
1755 constant.const_.ty(),
1756 terr,
1757 );
1758 }
1759 } else {
1760 let tcx = self.tcx();
1761 let maybe_uneval = match constant.const_ {
1762 Const::Ty(_, ct) => match ct.kind() {
1763 ty::ConstKind::Unevaluated(uv) => match uv.kind {
1764 ty::UnevaluatedConstKind::Projection { def_id }
1765 | ty::UnevaluatedConstKind::Inherent { def_id }
1766 | ty::UnevaluatedConstKind::Free { def_id }
1767 | ty::UnevaluatedConstKind::Anon { def_id } => {
1768 Some(UnevaluatedConst { def: def_id, args: uv.args, promoted: None })
1769 }
1770 },
1771 _ => None,
1772 },
1773 Const::Unevaluated(uv, _) => Some(uv),
1774 _ => None,
1775 };
1776
1777 if let Some(uv) = maybe_uneval {
1778 if let Some(promoted) = uv.promoted {
1779 let promoted_body = &self.promoted[promoted];
1780 self.check_promoted(promoted_body, location);
1781 let promoted_ty = promoted_body.return_ty();
1782 if let Err(terr) =
1783 self.eq_types(ty, promoted_ty, locations, ConstraintCategory::Boring)
1784 {
1785 span_mirbug!(
1786 self,
1787 promoted,
1788 "bad promoted type ({:?}: {:?}): {:?}",
1789 ty,
1790 promoted_ty,
1791 terr
1792 );
1793 };
1794 } else {
1795 self.ascribe_user_type(
1796 constant.const_.ty(),
1797 ty::UserType::new(ty::UserTypeKind::TypeOf(
1798 uv.def,
1799 UserArgs { args: uv.args, user_self_ty: None },
1800 )),
1801 locations.span(self.body),
1802 );
1803 }
1804 } else if let Some(static_def_id) = constant.check_static_ptr(tcx) {
1805 let unnormalized_ty = tcx.type_of(static_def_id).instantiate_identity();
1806 let normalized_ty = self.normalize(unnormalized_ty, locations);
1807 let literal_ty = constant.const_.ty().builtin_deref(true).unwrap();
1808
1809 if let Err(terr) =
1810 self.eq_types(literal_ty, normalized_ty, locations, ConstraintCategory::Boring)
1811 {
1812 span_mirbug!(self, constant, "bad static type {:?} ({:?})", constant, terr);
1813 }
1814 } else if let Const::Ty(_, ct) = constant.const_
1815 && let ty::ConstKind::Param(p) = ct.kind()
1816 {
1817 let body_def_id = self.universal_regions.defining_ty.def_id();
1818 let const_param = tcx.generics_of(body_def_id).const_param(p, tcx);
1819 self.ascribe_user_type(
1820 constant.const_.ty(),
1821 ty::UserType::new(ty::UserTypeKind::TypeOf(
1822 const_param.def_id,
1823 UserArgs {
1824 args: self.universal_regions.defining_ty.args(),
1825 user_self_ty: None,
1826 },
1827 )),
1828 locations.span(self.body),
1829 );
1830 }
1831
1832 if let ty::FnDef(def_id, args) = *constant.const_.ty().kind() {
1833 let instantiated_predicates = tcx.predicates_of(def_id).instantiate(tcx, args);
1834 self.normalize_and_prove_instantiated_predicates(
1835 def_id,
1836 instantiated_predicates,
1837 locations,
1838 );
1839
1840 assert_eq!(tcx.trait_impl_of_assoc(def_id), None);
1841 self.prove_predicates(
1842 args.types().map(|ty| ty::ClauseKind::WellFormed(ty.into())),
1843 locations,
1844 ConstraintCategory::Boring,
1845 );
1846 }
1847 }
1848 }
1849
1850 fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, location: Location) {
1851 self.super_place(place, context, location);
1852 let tcx = self.tcx();
1853 let place_ty = place.ty(self.body, tcx);
1854 if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context {
1855 let trait_ref = ty::TraitRef::new(
1856 tcx,
1857 tcx.require_lang_item(LangItem::Copy, self.last_span),
1858 [place_ty.ty],
1859 );
1860
1861 self.prove_trait_ref(trait_ref, location.to_locations(), ConstraintCategory::CopyBound);
1873 }
1874 }
1875
1876 fn visit_projection_elem(
1877 &mut self,
1878 place: PlaceRef<'tcx>,
1879 elem: PlaceElem<'tcx>,
1880 context: PlaceContext,
1881 location: Location,
1882 ) {
1883 let tcx = self.tcx();
1884 let base_ty = place.ty(self.body(), tcx);
1885 match elem {
1886 ProjectionElem::Deref
1889 | ProjectionElem::Index(_)
1890 | ProjectionElem::ConstantIndex { .. }
1891 | ProjectionElem::Subslice { .. }
1892 | ProjectionElem::Downcast(..) => {}
1893 ProjectionElem::Field(field, fty) => {
1894 let fty = self.normalize(ty::Unnormalized::new_wip(fty), location);
1895 let ty = PlaceTy::field_ty(tcx, base_ty.ty, base_ty.variant_index, field);
1896 let ty = self.normalize(ty, location);
1897 {
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:1897",
"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(1897u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
::tracing_core::field::FieldSet::new(&["fty", "ty"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&fty) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&ty) as
&dyn Value))])
});
} else { ; }
};debug!(?fty, ?ty);
1898
1899 if let Err(terr) = self.relate_types(
1900 ty,
1901 context.ambient_variance(),
1902 fty,
1903 location.to_locations(),
1904 ConstraintCategory::Boring,
1905 ) {
1906 {
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);
1907 }
1908 }
1909 ProjectionElem::OpaqueCast(ty) => {
1910 let ty = self.normalize(ty::Unnormalized::new_wip(ty), location);
1911 self.relate_types(
1912 ty,
1913 context.ambient_variance(),
1914 base_ty.ty,
1915 location.to_locations(),
1916 ConstraintCategory::TypeAnnotation(AnnotationSource::OpaqueCast),
1917 )
1918 .unwrap();
1919 }
1920 ProjectionElem::UnwrapUnsafeBinder(ty) => {
1921 let ty::UnsafeBinder(binder_ty) = *base_ty.ty.kind() else {
1922 ::core::panicking::panic("internal error: entered unreachable code");unreachable!();
1923 };
1924 let found_ty = self.infcx.instantiate_binder_with_fresh_vars(
1925 self.body.source_info(location).span,
1926 BoundRegionConversionTime::HigherRankedType,
1927 binder_ty.into(),
1928 );
1929 self.relate_types(
1930 ty,
1931 context.ambient_variance(),
1932 found_ty,
1933 location.to_locations(),
1934 ConstraintCategory::Boring,
1935 )
1936 .unwrap();
1937 }
1938 }
1939 }
1940}
1941
1942impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
1943 fn check_call_dest(
1944 &mut self,
1945 term: &Terminator<'tcx>,
1946 sig: &ty::FnSig<'tcx>,
1947 destination: Place<'tcx>,
1948 is_diverging: bool,
1949 term_location: Location,
1950 ) {
1951 let tcx = self.tcx();
1952 if is_diverging {
1953 let output_ty = self.tcx().erase_and_anonymize_regions(sig.output());
1956 if !output_ty
1957 .is_privately_uninhabited(self.tcx(), self.infcx.typing_env(self.infcx.param_env))
1958 {
1959 {
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);
1960 }
1961 } else {
1962 let dest_ty = destination.ty(self.body, tcx).ty;
1963 let dest_ty = self.normalize(ty::Unnormalized::new_wip(dest_ty), term_location);
1964 let category = match destination.as_local() {
1965 Some(RETURN_PLACE) => {
1966 if let DefiningTy::Const(def_id, _) | DefiningTy::InlineConst(def_id, _) =
1967 self.universal_regions.defining_ty
1968 {
1969 if tcx.is_static(def_id) {
1970 ConstraintCategory::UseAsStatic
1971 } else {
1972 ConstraintCategory::UseAsConst
1973 }
1974 } else {
1975 ConstraintCategory::Return(ReturnConstraint::Normal)
1976 }
1977 }
1978 Some(l) if !self.body.local_decls[l].is_user_variable() => {
1979 ConstraintCategory::Boring
1980 }
1981 _ => ConstraintCategory::Assignment,
1983 };
1984
1985 let locations = term_location.to_locations();
1986
1987 if let Err(terr) = self.sub_types(sig.output(), dest_ty, locations, category) {
1988 {
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!(
1989 self,
1990 term,
1991 "call dest mismatch ({:?} <- {:?}): {:?}",
1992 dest_ty,
1993 sig.output(),
1994 terr
1995 );
1996 }
1997
1998 if self.tcx().features().unsized_fn_params() {
2001 let span = term.source_info.span;
2002 self.ensure_place_sized(dest_ty, span);
2003 }
2004 }
2005 }
2006
2007 #[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(2007u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
::tracing_core::field::FieldSet::new(&["sig", "args"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&sig)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = 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:2043",
"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(2043u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
::tracing_core::field::FieldSet::new(&["func_ty"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&func_ty) as
&dyn 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))]
2008 fn check_call_inputs(
2009 &mut self,
2010 term: &Terminator<'tcx>,
2011 func: &Operand<'tcx>,
2012 sig: &ty::FnSig<'tcx>,
2013 args: &[Spanned<Operand<'tcx>>],
2014 term_location: Location,
2015 call_source: CallSource,
2016 ) {
2017 if args.len() < sig.inputs().len() || (args.len() > sig.inputs().len() && !sig.c_variadic())
2018 {
2019 span_mirbug!(self, term, "call to {:?} with wrong # of args", sig);
2020 }
2021
2022 let func_ty = func.ty(self.body, self.infcx.tcx);
2023 if let ty::FnDef(def_id, _) = *func_ty.kind() {
2024 if let Some(name @ (sym::simd_shuffle | sym::simd_insert | sym::simd_extract)) =
2028 self.tcx().intrinsic(def_id).map(|i| i.name)
2029 {
2030 let idx = match name {
2031 sym::simd_shuffle => 2,
2032 _ => 1,
2033 };
2034 if !matches!(args[idx], Spanned { node: Operand::Constant(_), .. }) {
2035 self.tcx().dcx().emit_err(SimdIntrinsicArgConst {
2036 span: term.source_info.span,
2037 arg: idx + 1,
2038 intrinsic: name.to_string(),
2039 });
2040 }
2041 }
2042 }
2043 debug!(?func_ty);
2044
2045 for (n, (fn_arg, op_arg)) in iter::zip(sig.inputs(), args).enumerate() {
2046 let op_arg_ty = op_arg.node.ty(self.body, self.tcx());
2047
2048 let op_arg_ty = self.normalize(ty::Unnormalized::new_wip(op_arg_ty), term_location);
2049 let category = if call_source.from_hir_call() {
2050 ConstraintCategory::CallArgument(Some(
2051 self.infcx.tcx.erase_and_anonymize_regions(func_ty),
2052 ))
2053 } else {
2054 ConstraintCategory::Boring
2055 };
2056 if let Err(terr) =
2057 self.sub_types(op_arg_ty, *fn_arg, term_location.to_locations(), category)
2058 {
2059 span_mirbug!(
2060 self,
2061 term,
2062 "bad arg #{:?} ({:?} <- {:?}): {:?}",
2063 n,
2064 fn_arg,
2065 op_arg_ty,
2066 terr
2067 );
2068 }
2069 }
2070 }
2071
2072 fn check_iscleanup(&mut self, block_data: &BasicBlockData<'tcx>) {
2073 let is_cleanup = block_data.is_cleanup;
2074 match block_data.terminator().kind {
2075 TerminatorKind::Goto { target } => {
2076 self.assert_iscleanup(block_data, target, is_cleanup)
2077 }
2078 TerminatorKind::SwitchInt { ref targets, .. } => {
2079 for target in targets.all_targets() {
2080 self.assert_iscleanup(block_data, *target, is_cleanup);
2081 }
2082 }
2083 TerminatorKind::UnwindResume => {
2084 if !is_cleanup {
2085 {
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!")
2086 }
2087 }
2088 TerminatorKind::UnwindTerminate(_) => {
2089 if !is_cleanup {
2090 {
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!")
2091 }
2092 }
2093 TerminatorKind::Return => {
2094 if is_cleanup {
2095 {
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")
2096 }
2097 }
2098 TerminatorKind::TailCall { .. } => {
2099 if is_cleanup {
2100 {
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")
2101 }
2102 }
2103 TerminatorKind::CoroutineDrop { .. } => {
2104 if is_cleanup {
2105 {
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")
2106 }
2107 }
2108 TerminatorKind::Yield { resume, drop, .. } => {
2109 if is_cleanup {
2110 {
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")
2111 }
2112 self.assert_iscleanup(block_data, resume, is_cleanup);
2113 if let Some(drop) = drop {
2114 self.assert_iscleanup(block_data, drop, is_cleanup);
2115 }
2116 }
2117 TerminatorKind::Unreachable => {}
2118 TerminatorKind::Drop { target, unwind, drop, .. } => {
2119 self.assert_iscleanup(block_data, target, is_cleanup);
2120 self.assert_iscleanup_unwind(block_data, unwind, is_cleanup);
2121 if let Some(drop) = drop {
2122 self.assert_iscleanup(block_data, drop, is_cleanup);
2123 }
2124 }
2125 TerminatorKind::Assert { target, unwind, .. } => {
2126 self.assert_iscleanup(block_data, target, is_cleanup);
2127 self.assert_iscleanup_unwind(block_data, unwind, is_cleanup);
2128 }
2129 TerminatorKind::Call { ref target, unwind, .. } => {
2130 if let &Some(target) = target {
2131 self.assert_iscleanup(block_data, target, is_cleanup);
2132 }
2133 self.assert_iscleanup_unwind(block_data, unwind, is_cleanup);
2134 }
2135 TerminatorKind::FalseEdge { real_target, imaginary_target } => {
2136 self.assert_iscleanup(block_data, real_target, is_cleanup);
2137 self.assert_iscleanup(block_data, imaginary_target, is_cleanup);
2138 }
2139 TerminatorKind::FalseUnwind { real_target, unwind } => {
2140 self.assert_iscleanup(block_data, real_target, is_cleanup);
2141 self.assert_iscleanup_unwind(block_data, unwind, is_cleanup);
2142 }
2143 TerminatorKind::InlineAsm { ref targets, unwind, .. } => {
2144 for &target in targets {
2145 self.assert_iscleanup(block_data, target, is_cleanup);
2146 }
2147 self.assert_iscleanup_unwind(block_data, unwind, is_cleanup);
2148 }
2149 }
2150 }
2151
2152 fn assert_iscleanup(&mut self, ctxt: &dyn fmt::Debug, bb: BasicBlock, iscleanuppad: bool) {
2153 if self.body[bb].is_cleanup != iscleanuppad {
2154 {
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);
2155 }
2156 }
2157
2158 fn assert_iscleanup_unwind(
2159 &mut self,
2160 ctxt: &dyn fmt::Debug,
2161 unwind: UnwindAction,
2162 is_cleanup: bool,
2163 ) {
2164 match unwind {
2165 UnwindAction::Cleanup(unwind) => {
2166 if is_cleanup {
2167 {
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")
2168 }
2169 self.assert_iscleanup(ctxt, unwind, true);
2170 }
2171 UnwindAction::Continue => {
2172 if is_cleanup {
2173 {
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")
2174 }
2175 }
2176 UnwindAction::Unreachable | UnwindAction::Terminate(_) => (),
2177 }
2178 }
2179
2180 fn ensure_place_sized(&mut self, ty: Ty<'tcx>, span: Span) {
2181 let tcx = self.tcx();
2182
2183 let erased_ty = tcx.erase_and_anonymize_regions(ty);
2187 if !erased_ty.is_sized(tcx, self.infcx.typing_env(self.infcx.param_env)) {
2189 if self.reported_errors.replace((ty, span)).is_none() {
2194 self.tcx().dcx().emit_err(MoveUnsized { ty, span });
2198 }
2199 }
2200 }
2201
2202 fn aggregate_field_ty(
2203 &mut self,
2204 ak: &AggregateKind<'tcx>,
2205 field_index: FieldIdx,
2206 location: Location,
2207 ) -> Result<Ty<'tcx>, FieldAccessError> {
2208 let tcx = self.tcx();
2209
2210 match *ak {
2211 AggregateKind::Adt(adt_did, variant_index, args, _, active_field_index) => {
2212 let def = tcx.adt_def(adt_did);
2213 let variant = &def.variant(variant_index);
2214 let adj_field_index = active_field_index.unwrap_or(field_index);
2215 if let Some(field) = variant.fields.get(adj_field_index) {
2216 Ok(self.normalize(field.ty(tcx, args), location))
2217 } else {
2218 Err(FieldAccessError::OutOfRange { field_count: variant.fields.len() })
2219 }
2220 }
2221 AggregateKind::Closure(_, args) => {
2222 match args.as_closure().upvar_tys().get(field_index.as_usize()) {
2223 Some(ty) => Ok(*ty),
2224 None => Err(FieldAccessError::OutOfRange {
2225 field_count: args.as_closure().upvar_tys().len(),
2226 }),
2227 }
2228 }
2229 AggregateKind::Coroutine(_, args) => {
2230 match args.as_coroutine().prefix_tys().get(field_index.as_usize()) {
2234 Some(ty) => Ok(*ty),
2235 None => Err(FieldAccessError::OutOfRange {
2236 field_count: args.as_coroutine().prefix_tys().len(),
2237 }),
2238 }
2239 }
2240 AggregateKind::CoroutineClosure(_, args) => {
2241 match args.as_coroutine_closure().upvar_tys().get(field_index.as_usize()) {
2242 Some(ty) => Ok(*ty),
2243 None => Err(FieldAccessError::OutOfRange {
2244 field_count: args.as_coroutine_closure().upvar_tys().len(),
2245 }),
2246 }
2247 }
2248 AggregateKind::Array(ty) => Ok(ty),
2249 AggregateKind::Tuple | AggregateKind::RawPtr(..) => {
2250 {
::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");
2251 }
2252 }
2253 }
2254
2255 fn rvalue_user_ty(&self, rvalue: &Rvalue<'tcx>) -> Option<UserTypeAnnotationIndex> {
2259 match rvalue {
2260 Rvalue::Use(..)
2261 | Rvalue::ThreadLocalRef(..)
2262 | Rvalue::Repeat(..)
2263 | Rvalue::Ref(..)
2264 | Rvalue::Reborrow(..)
2265 | Rvalue::RawPtr(..)
2266 | Rvalue::Cast(..)
2267 | Rvalue::BinaryOp(..)
2268 | Rvalue::CopyForDeref(..)
2269 | Rvalue::UnaryOp(..)
2270 | Rvalue::Discriminant(..)
2271 | Rvalue::WrapUnsafeBinder(..) => None,
2272
2273 Rvalue::Aggregate(aggregate, _) => match **aggregate {
2274 AggregateKind::Adt(_, _, _, user_ty, _) => user_ty,
2275 AggregateKind::Array(_) => None,
2276 AggregateKind::Tuple => None,
2277 AggregateKind::Closure(_, _) => None,
2278 AggregateKind::Coroutine(_, _) => None,
2279 AggregateKind::CoroutineClosure(_, _) => None,
2280 AggregateKind::RawPtr(_, _) => None,
2281 },
2282 }
2283 }
2284
2285 fn check_aggregate_rvalue(
2286 &mut self,
2287 rvalue: &Rvalue<'tcx>,
2288 aggregate_kind: &AggregateKind<'tcx>,
2289 operands: &IndexSlice<FieldIdx, Operand<'tcx>>,
2290 location: Location,
2291 ) {
2292 let tcx = self.tcx();
2293
2294 self.prove_aggregate_predicates(aggregate_kind, location);
2295
2296 if *aggregate_kind == AggregateKind::Tuple {
2297 return;
2299 }
2300
2301 if let AggregateKind::RawPtr(..) = aggregate_kind {
2302 ::rustc_middle::util::bug::bug_fmt(format_args!("RawPtr should only be in runtime MIR"));bug!("RawPtr should only be in runtime MIR");
2303 }
2304
2305 for (i, operand) in operands.iter_enumerated() {
2306 let field_ty = match self.aggregate_field_ty(aggregate_kind, i, location) {
2307 Ok(field_ty) => field_ty,
2308 Err(FieldAccessError::OutOfRange { field_count }) => {
2309 {
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!(
2310 self,
2311 rvalue,
2312 "accessed field #{} but variant only has {}",
2313 i.as_u32(),
2314 field_count,
2315 );
2316 continue;
2317 }
2318 };
2319 let operand_ty = operand.ty(self.body, tcx);
2320 let operand_ty = self.normalize(ty::Unnormalized::new_wip(operand_ty), location);
2321
2322 if let Err(terr) = self.sub_types(
2323 operand_ty,
2324 field_ty,
2325 location.to_locations(),
2326 ConstraintCategory::Boring,
2327 ) {
2328 {
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!(
2329 self,
2330 rvalue,
2331 "{:?} is not a subtype of {:?}: {:?}",
2332 operand_ty,
2333 field_ty,
2334 terr
2335 );
2336 }
2337 }
2338 }
2339
2340 fn add_reborrow_constraint(
2348 &mut self,
2349 location: Location,
2350 borrow_region: ty::Region<'tcx>,
2351 borrowed_place: &Place<'tcx>,
2352 ) {
2353 let Self { borrow_set, location_table, polonius_facts, constraints, .. } = self;
2355
2356 if let Some(polonius_facts) = polonius_facts {
2362 let _prof_timer = self.infcx.tcx.prof.generic_activity("polonius_fact_generation");
2363 if let Some(borrow_index) = borrow_set.get_index_of(&location) {
2364 let region_vid = borrow_region.as_var();
2365 polonius_facts.loan_issued_at.push((
2366 region_vid.into(),
2367 borrow_index,
2368 location_table.mid_index(location),
2369 ));
2370 }
2371 }
2372
2373 {
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:2378",
"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(2378u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("add_reborrow_constraint({0:?}, {1:?}, {2:?})",
location, borrow_region, borrowed_place) as &dyn Value))])
});
} else { ; }
};debug!(
2379 "add_reborrow_constraint({:?}, {:?}, {:?})",
2380 location, borrow_region, borrowed_place
2381 );
2382
2383 let tcx = self.infcx.tcx;
2384 let def = self.body.source.def_id().expect_local();
2385 let upvars = tcx.closure_captures(def);
2386 let field =
2387 path_utils::is_upvar_field_projection(tcx, upvars, borrowed_place.as_ref(), self.body);
2388 let category = if let Some(field) = field {
2389 ConstraintCategory::ClosureUpvar(field)
2390 } else {
2391 ConstraintCategory::Boring
2392 };
2393
2394 for (base, elem) in borrowed_place.as_ref().iter_projections().rev() {
2395 {
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:2395",
"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(2395u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("add_reborrow_constraint - iteration {0:?}",
elem) as &dyn Value))])
});
} else { ; }
};debug!("add_reborrow_constraint - iteration {:?}", elem);
2396
2397 match elem {
2398 ProjectionElem::Deref => {
2399 let base_ty = base.ty(self.body, tcx).ty;
2400
2401 {
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:2401",
"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(2401u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("add_reborrow_constraint - base_ty = {0:?}",
base_ty) as &dyn Value))])
});
} else { ; }
};debug!("add_reborrow_constraint - base_ty = {:?}", base_ty);
2402 match base_ty.kind() {
2403 ty::Ref(ref_region, _, mutbl) => {
2404 constraints.outlives_constraints.push(OutlivesConstraint {
2405 sup: ref_region.as_var(),
2406 sub: borrow_region.as_var(),
2407 locations: location.to_locations(),
2408 span: location.to_locations().span(self.body),
2409 category,
2410 variance_info: ty::VarianceDiagInfo::default(),
2411 from_closure: false,
2412 });
2413
2414 match mutbl {
2415 hir::Mutability::Not => {
2416 break;
2420 }
2421 hir::Mutability::Mut => {
2422 }
2444 }
2445 }
2446 ty::RawPtr(..) => {
2447 break;
2449 }
2450 ty::Adt(def, _) if def.is_box() => {
2451 }
2453 _ => ::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),
2454 }
2455 }
2456 ProjectionElem::Field(..)
2457 | ProjectionElem::Downcast(..)
2458 | ProjectionElem::OpaqueCast(..)
2459 | ProjectionElem::Index(..)
2460 | ProjectionElem::ConstantIndex { .. }
2461 | ProjectionElem::Subslice { .. }
2462 | ProjectionElem::UnwrapUnsafeBinder(_) => {
2463 }
2465 }
2466 }
2467 }
2468
2469 fn add_generic_reborrow_constraint(
2470 &mut self,
2471 mutability: Mutability,
2472 location: Location,
2473 borrowed_place: &Place<'tcx>,
2474 dest_ty: Ty<'tcx>,
2475 ) {
2476 let Self { borrow_set, location_table, polonius_facts, constraints, infcx, body, .. } =
2477 self;
2478
2479 {
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:2479",
"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(2479u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("add_generic_reborrow_constraint({0:?}, {1:?}, {2:?}, {3:?})",
mutability, location, borrowed_place, dest_ty) as
&dyn Value))])
});
} else { ; }
};debug!(
2480 "add_generic_reborrow_constraint({:?}, {:?}, {:?}, {:?})",
2481 mutability, location, borrowed_place, dest_ty
2482 );
2483
2484 let tcx = infcx.tcx;
2485 let def = body.source.def_id().expect_local();
2486 let upvars = tcx.closure_captures(def);
2487 let field =
2488 path_utils::is_upvar_field_projection(tcx, upvars, borrowed_place.as_ref(), body);
2489 let category = if let Some(field) = field {
2490 ConstraintCategory::ClosureUpvar(field)
2491 } else {
2492 ConstraintCategory::Boring
2493 };
2494
2495 let borrowed_ty = borrowed_place.ty(self.body, tcx).ty;
2496
2497 let ty::Adt(dest_adt, dest_args) = dest_ty.kind() else { ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"))bug!() };
2498 let [dest_arg, ..] = ***dest_args else { ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"))bug!() };
2499 let ty::GenericArgKind::Lifetime(dest_region) = dest_arg.kind() else { ::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"))bug!() };
2500 constraints.liveness_constraints.add_location(dest_region.as_var(), location);
2501
2502 if let Some(polonius_facts) = polonius_facts {
2505 let _prof_timer = infcx.tcx.prof.generic_activity("polonius_fact_generation");
2506 if let Some(borrow_index) = borrow_set.get_index_of(&location) {
2507 let region_vid = dest_region.as_var();
2508 polonius_facts.loan_issued_at.push((
2509 region_vid.into(),
2510 borrow_index,
2511 location_table.mid_index(location),
2512 ));
2513 }
2514 }
2515
2516 if mutability.is_not() {
2517 let ty::Adt(borrowed_adt, borrowed_args) = borrowed_ty.kind() else { ::core::panicking::panic("internal error: entered unreachable code")unreachable!() };
2524 let borrowed_fields = borrowed_adt.all_fields().collect::<Vec<_>>();
2525 for dest_field in dest_adt.all_fields() {
2526 let Some(borrowed_field) =
2527 borrowed_fields.iter().find(|f| f.name == dest_field.name)
2528 else {
2529 continue;
2530 };
2531 let dest_ty = dest_field.ty(tcx, dest_args).skip_norm_wip();
2532 let borrowed_ty = borrowed_field.ty(tcx, borrowed_args).skip_norm_wip();
2533 if let (
2534 ty::Ref(borrow_region, _, Mutability::Mut),
2535 ty::Ref(ref_region, _, Mutability::Not),
2536 ) = (borrowed_ty.kind(), dest_ty.kind())
2537 {
2538 self.relate_types(
2539 borrowed_ty.peel_refs(),
2540 ty::Variance::Covariant,
2541 dest_ty.peel_refs(),
2542 location.to_locations(),
2543 category,
2544 )
2545 .unwrap();
2546 self.constraints.outlives_constraints.push(OutlivesConstraint {
2547 sup: ref_region.as_var(),
2548 sub: borrow_region.as_var(),
2549 locations: location.to_locations(),
2550 span: location.to_locations().span(self.body),
2551 category,
2552 variance_info: ty::VarianceDiagInfo::default(),
2553 from_closure: false,
2554 });
2555 } else {
2556 self.relate_types(
2557 borrowed_ty,
2558 ty::Variance::Covariant,
2559 dest_ty,
2560 location.to_locations(),
2561 category,
2562 )
2563 .unwrap();
2564 }
2565 }
2566 } else {
2567 self.relate_types(
2569 borrowed_ty,
2570 ty::Variance::Covariant,
2571 dest_ty,
2572 location.to_locations(),
2573 category,
2574 )
2575 .unwrap();
2576 }
2577 }
2578
2579 fn prove_aggregate_predicates(
2580 &mut self,
2581 aggregate_kind: &AggregateKind<'tcx>,
2582 location: Location,
2583 ) {
2584 let tcx = self.tcx();
2585
2586 {
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:2586",
"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(2586u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("prove_aggregate_predicates(aggregate_kind={0:?}, location={1:?})",
aggregate_kind, location) as &dyn Value))])
});
} else { ; }
};debug!(
2587 "prove_aggregate_predicates(aggregate_kind={:?}, location={:?})",
2588 aggregate_kind, location
2589 );
2590
2591 let (def_id, instantiated_predicates) = match *aggregate_kind {
2592 AggregateKind::Adt(adt_did, _, args, _, _) => {
2593 (adt_did, tcx.predicates_of(adt_did).instantiate(tcx, args))
2594 }
2595
2596 AggregateKind::Closure(def_id, args)
2616 | AggregateKind::CoroutineClosure(def_id, args)
2617 | AggregateKind::Coroutine(def_id, args) => {
2618 (def_id, self.prove_closure_bounds(tcx, def_id.expect_local(), args, location))
2619 }
2620
2621 AggregateKind::Array(_) | AggregateKind::Tuple | AggregateKind::RawPtr(..) => {
2622 (CRATE_DEF_ID.to_def_id(), ty::InstantiatedPredicates::empty())
2623 }
2624 };
2625
2626 self.normalize_and_prove_instantiated_predicates(
2627 def_id,
2628 instantiated_predicates,
2629 location.to_locations(),
2630 );
2631 }
2632
2633 fn prove_closure_bounds(
2634 &mut self,
2635 tcx: TyCtxt<'tcx>,
2636 def_id: LocalDefId,
2637 args: GenericArgsRef<'tcx>,
2638 location: Location,
2639 ) -> ty::InstantiatedPredicates<'tcx> {
2640 let root_def_id = self.root_cx.root_def_id();
2641 self.deferred_closure_requirements.push((def_id, args, location.to_locations()));
2644
2645 let typeck_root_args = ty::GenericArgs::identity_for_item(tcx, root_def_id);
2647
2648 let parent_args = match tcx.def_kind(def_id) {
2649 DefKind::Closure => {
2653 &args[..typeck_root_args.len()]
2657 }
2658 DefKind::InlineConst => args.as_inline_const().parent_args(),
2659 other => ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected item {0:?}",
other))bug!("unexpected item {:?}", other),
2660 };
2661 let parent_args = tcx.mk_args(parent_args);
2662
2663 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());
2664 if let Err(_) = self.eq_args(
2665 typeck_root_args,
2666 parent_args,
2667 location.to_locations(),
2668 ConstraintCategory::BoringNoLocation,
2669 ) {
2670 {
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!(
2671 self,
2672 def_id,
2673 "could not relate closure to parent {:?} != {:?}",
2674 typeck_root_args,
2675 parent_args
2676 );
2677 }
2678
2679 tcx.predicates_of(def_id).instantiate(tcx, args)
2680 }
2681}
2682
2683trait NormalizeLocation: fmt::Debug + Copy {
2684 fn to_locations(self) -> Locations;
2685}
2686
2687impl NormalizeLocation for Locations {
2688 fn to_locations(self) -> Locations {
2689 self
2690 }
2691}
2692
2693impl NormalizeLocation for Location {
2694 fn to_locations(self) -> Locations {
2695 Locations::Single(self)
2696 }
2697}
2698
2699#[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)]
2703pub(super) struct InstantiateOpaqueType<'tcx> {
2704 pub base_universe: Option<ty::UniverseIndex>,
2705 pub region_constraints: Option<RegionConstraintData<'tcx>>,
2706 pub obligations: PredicateObligations<'tcx>,
2707}
2708
2709impl<'tcx> TypeOp<'tcx> for InstantiateOpaqueType<'tcx> {
2710 type Output = ();
2711 type ErrorInfo = InstantiateOpaqueType<'tcx>;
2717
2718 fn fully_perform(
2719 mut self,
2720 infcx: &InferCtxt<'tcx>,
2721 root_def_id: LocalDefId,
2722 span: Span,
2723 ) -> Result<TypeOpOutput<'tcx, Self>, ErrorGuaranteed> {
2724 let (mut output, region_constraints) =
2725 scrape_region_constraints(infcx, root_def_id, "InstantiateOpaqueType", span, |ocx| {
2726 ocx.register_obligations(self.obligations.clone());
2727 Ok(())
2728 })?;
2729 self.region_constraints = Some(region_constraints);
2730 output.error_info = Some(self);
2731 Ok(output)
2732 }
2733}