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