1use std::rc::Rc;
4use std::{fmt, iter, mem};
5
6use rustc_abi::FieldIdx;
7use rustc_data_structures::frozen::Frozen;
8use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
9use rustc_errors::ErrorGuaranteed;
10use rustc_hir as hir;
11use rustc_hir::def::DefKind;
12use rustc_hir::def_id::LocalDefId;
13use rustc_hir::lang_items::LangItem;
14use rustc_index::{IndexSlice, IndexVec};
15use rustc_infer::infer::canonical::QueryRegionConstraints;
16use rustc_infer::infer::outlives::env::RegionBoundPairs;
17use rustc_infer::infer::region_constraints::RegionConstraintData;
18use rustc_infer::infer::{
19 BoundRegionConversionTime, InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin,
20};
21use rustc_infer::traits::PredicateObligations;
22use rustc_middle::bug;
23use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor};
24use rustc_middle::mir::*;
25use rustc_middle::traits::query::NoSolution;
26use rustc_middle::ty::adjustment::PointerCoercion;
27use rustc_middle::ty::cast::CastTy;
28use rustc_middle::ty::{
29 self, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, CoroutineArgsExt,
30 GenericArgsRef, Ty, TyCtxt, TypeVisitableExt, UserArgs, UserTypeAnnotationIndex, fold_regions,
31};
32use rustc_mir_dataflow::move_paths::MoveData;
33use rustc_mir_dataflow::points::DenseLocationMap;
34use rustc_span::def_id::CRATE_DEF_ID;
35use rustc_span::{Span, Spanned, sym};
36use rustc_trait_selection::infer::InferCtxtExt;
37use rustc_trait_selection::traits::query::type_op::custom::scrape_region_constraints;
38use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput};
39use tracing::{debug, instrument, trace};
40
41use crate::borrow_set::BorrowSet;
42use crate::constraints::{OutlivesConstraint, OutlivesConstraintSet};
43use crate::diagnostics::UniverseInfo;
44use crate::polonius::PoloniusContext;
45use crate::polonius::legacy::{PoloniusFacts, PoloniusLocationTable};
46use crate::region_infer::TypeTest;
47use crate::region_infer::values::{LivenessValues, PlaceholderIndex, PlaceholderIndices};
48use crate::session_diagnostics::{MoveUnsized, SimdIntrinsicArgConst};
49use crate::type_check::free_region_relations::{CreateResult, UniversalRegionRelations};
50use crate::universal_regions::{DefiningTy, UniversalRegions};
51use crate::{BorrowCheckRootCtxt, BorrowckInferCtxt, DeferredClosureRequirements, path_utils};
52
53macro_rules! span_mirbug {
54 ($context:expr, $elem:expr, $($message:tt)*) => ({
55 $crate::type_check::mirbug(
56 $context.tcx(),
57 $context.last_span,
58 format!(
59 "broken MIR in {:?} ({:?}): {}",
60 $context.body().source.def_id(),
61 $elem,
62 format_args!($($message)*),
63 ),
64 )
65 })
66}
67
68pub(crate) mod canonical;
69pub(crate) mod constraint_conversion;
70pub(crate) mod free_region_relations;
71mod input_output;
72pub(crate) mod liveness;
73mod relate_tys;
74
75pub(crate) fn type_check<'tcx>(
98 root_cx: &mut BorrowCheckRootCtxt<'tcx>,
99 infcx: &BorrowckInferCtxt<'tcx>,
100 body: &Body<'tcx>,
101 promoted: &IndexSlice<Promoted, Body<'tcx>>,
102 universal_regions: UniversalRegions<'tcx>,
103 location_table: &PoloniusLocationTable,
104 borrow_set: &BorrowSet<'tcx>,
105 polonius_facts: &mut Option<PoloniusFacts>,
106 move_data: &MoveData<'tcx>,
107 location_map: Rc<DenseLocationMap>,
108) -> MirTypeckResults<'tcx> {
109 let mut constraints = MirTypeckRegionConstraints {
110 placeholder_indices: PlaceholderIndices::default(),
111 placeholder_index_to_region: IndexVec::default(),
112 liveness_constraints: LivenessValues::with_specific_points(Rc::clone(&location_map)),
113 outlives_constraints: OutlivesConstraintSet::default(),
114 type_tests: Vec::default(),
115 universe_causes: FxIndexMap::default(),
116 };
117
118 let CreateResult {
119 universal_region_relations,
120 region_bound_pairs,
121 normalized_inputs_and_output,
122 known_type_outlives_obligations,
123 } = free_region_relations::create(infcx, universal_regions, &mut constraints);
124
125 {
126 let pre_obligations = infcx.take_registered_region_obligations();
128 if !pre_obligations.is_empty() {
{
::core::panicking::panic_fmt(format_args!("there should be no incoming region obligations = {0:#?}",
pre_obligations));
}
};assert!(
129 pre_obligations.is_empty(),
130 "there should be no incoming region obligations = {pre_obligations:#?}",
131 );
132 let pre_assumptions = infcx.take_registered_region_assumptions();
133 if !pre_assumptions.is_empty() {
{
::core::panicking::panic_fmt(format_args!("there should be no incoming region assumptions = {0:#?}",
pre_assumptions));
}
};assert!(
134 pre_assumptions.is_empty(),
135 "there should be no incoming region assumptions = {pre_assumptions:#?}",
136 );
137 }
138
139 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/type_check/mod.rs:139",
"rustc_borrowck::type_check", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/type_check/mod.rs"),
::tracing_core::__macro_support::Option::Some(139u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
::tracing_core::field::FieldSet::new(&["normalized_inputs_and_output"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&normalized_inputs_and_output)
as &dyn Value))])
});
} else { ; }
};debug!(?normalized_inputs_and_output);
140
141 let polonius_context = if infcx.tcx.sess.opts.unstable_opts.polonius.is_next_enabled() {
142 Some(PoloniusContext::default())
143 } else {
144 None
145 };
146
147 let mut deferred_closure_requirements = Default::default();
148 let mut typeck = TypeChecker {
149 root_cx,
150 infcx,
151 last_span: body.span,
152 body,
153 promoted,
154 user_type_annotations: &body.user_type_annotations,
155 region_bound_pairs: ®ion_bound_pairs,
156 known_type_outlives_obligations: &known_type_outlives_obligations,
157 reported_errors: Default::default(),
158 universal_regions: &universal_region_relations.universal_regions,
159 location_table,
160 polonius_facts,
161 borrow_set,
162 constraints: &mut constraints,
163 deferred_closure_requirements: &mut deferred_closure_requirements,
164 polonius_context,
165 };
166
167 typeck.check_user_type_annotations();
168 typeck.visit_body(body);
169 typeck.equate_inputs_and_outputs(&normalized_inputs_and_output);
170 typeck.check_signature_annotation();
171
172 liveness::generate(&mut typeck, &location_map, move_data);
173
174 let polonius_context = typeck.polonius_context;
175
176 if let Some(guar) = universal_region_relations.universal_regions.encountered_re_error() {
179 {
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:179",
"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(179u32),
::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!");
180 constraints.outlives_constraints = Default::default();
181 constraints.type_tests = Default::default();
182 root_cx.set_tainted_by_errors(guar);
183 infcx.set_tainted_by_errors(guar);
184 }
185
186 MirTypeckResults {
187 constraints,
188 universal_region_relations,
189 region_bound_pairs,
190 known_type_outlives_obligations,
191 deferred_closure_requirements,
192 polonius_context,
193 }
194}
195
196#[track_caller]
197fn mirbug(tcx: TyCtxt<'_>, span: Span, msg: String) {
198 tcx.dcx().span_delayed_bug(span, msg);
202}
203
204enum FieldAccessError {
205 OutOfRange { field_count: usize },
206}
207
208struct TypeChecker<'a, 'tcx> {
213 root_cx: &'a mut BorrowCheckRootCtxt<'tcx>,
214 infcx: &'a BorrowckInferCtxt<'tcx>,
215 last_span: Span,
216 body: &'a Body<'tcx>,
217 promoted: &'a IndexSlice<Promoted, Body<'tcx>>,
220 user_type_annotations: &'a CanonicalUserTypeAnnotations<'tcx>,
223 region_bound_pairs: &'a RegionBoundPairs<'tcx>,
224 known_type_outlives_obligations: &'a [ty::PolyTypeOutlivesPredicate<'tcx>],
225 reported_errors: FxIndexSet<(Ty<'tcx>, Span)>,
226 universal_regions: &'a UniversalRegions<'tcx>,
227 location_table: &'a PoloniusLocationTable,
228 polonius_facts: &'a mut Option<PoloniusFacts>,
229 borrow_set: &'a BorrowSet<'tcx>,
230 constraints: &'a mut MirTypeckRegionConstraints<'tcx>,
231 deferred_closure_requirements: &'a mut DeferredClosureRequirements<'tcx>,
232 polonius_context: Option<PoloniusContext>,
234}
235
236pub(crate) struct MirTypeckResults<'tcx> {
239 pub(crate) constraints: MirTypeckRegionConstraints<'tcx>,
240 pub(crate) universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
241 pub(crate) region_bound_pairs: Frozen<RegionBoundPairs<'tcx>>,
242 pub(crate) known_type_outlives_obligations: Frozen<Vec<ty::PolyTypeOutlivesPredicate<'tcx>>>,
243 pub(crate) deferred_closure_requirements: DeferredClosureRequirements<'tcx>,
244 pub(crate) polonius_context: Option<PoloniusContext>,
245}
246
247#[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> {
251 pub(crate) placeholder_indices: PlaceholderIndices<'tcx>,
257
258 pub(crate) placeholder_index_to_region: IndexVec<PlaceholderIndex, ty::Region<'tcx>>,
264
265 pub(crate) liveness_constraints: LivenessValues,
273
274 pub(crate) outlives_constraints: OutlivesConstraintSet<'tcx>,
275
276 pub(crate) universe_causes: FxIndexMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
277
278 pub(crate) type_tests: Vec<TypeTest<'tcx>>,
279}
280
281impl<'tcx> MirTypeckRegionConstraints<'tcx> {
282 pub(crate) fn placeholder_region(
285 &mut self,
286 infcx: &InferCtxt<'tcx>,
287 placeholder: ty::PlaceholderRegion<'tcx>,
288 ) -> ty::Region<'tcx> {
289 let placeholder_index = self.placeholder_indices.insert(placeholder);
290 match self.placeholder_index_to_region.get(placeholder_index) {
291 Some(&v) => v,
292 None => {
293 let origin = NllRegionVariableOrigin::Placeholder(placeholder);
294 let region = infcx.next_nll_region_var_in_universe(origin, placeholder.universe);
295 self.placeholder_index_to_region.push(region);
296 region
297 }
298 }
299 }
300}
301
302#[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> {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
match (self, other) {
(Locations::All(__self_0), Locations::All(__arg1_0)) =>
::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0),
(Locations::Single(__self_0), Locations::Single(__arg1_0)) =>
::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0),
_ =>
::core::cmp::PartialOrd::partial_cmp(&__self_discr,
&__arg1_discr),
}
}
}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)]
307pub enum Locations {
308 All(Span),
344
345 Single(Location),
349}
350
351impl Locations {
352 pub fn from_location(&self) -> Option<Location> {
353 match self {
354 Locations::All(_) => None,
355 Locations::Single(from_location) => Some(*from_location),
356 }
357 }
358
359 pub fn span(&self, body: &Body<'_>) -> Span {
361 match self {
362 Locations::All(span) => *span,
363 Locations::Single(l) => body.source_info(*l).span,
364 }
365 }
366}
367
368impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
369 fn tcx(&self) -> TyCtxt<'tcx> {
370 self.infcx.tcx
371 }
372
373 fn body(&self) -> &Body<'tcx> {
374 self.body
375 }
376
377 #[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(378u32),
::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:380",
"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(380u32),
::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")]
379 fn check_user_type_annotations(&mut self) {
380 debug!(?self.user_type_annotations);
381 for user_annotation in self.user_type_annotations {
382 let CanonicalUserTypeAnnotation { span, ref user_ty, inferred_ty } = *user_annotation;
383 let annotation = self.instantiate_canonical(span, user_ty);
384 self.ascribe_user_type(inferred_ty, annotation, span);
385 }
386 }
387
388 #[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(388u32),
::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:395",
"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(395u32),
::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")]
389 fn push_region_constraints(
390 &mut self,
391 locations: Locations,
392 category: ConstraintCategory<'tcx>,
393 data: &QueryRegionConstraints<'tcx>,
394 ) {
395 debug!("constraints generated: {:#?}", data);
396
397 constraint_conversion::ConstraintConversion::new(
398 self.infcx,
399 self.universal_regions,
400 self.region_bound_pairs,
401 self.known_type_outlives_obligations,
402 locations,
403 locations.span(self.body),
404 category,
405 self.constraints,
406 )
407 .convert_all(data);
408 }
409
410 fn sub_types(
412 &mut self,
413 sub: Ty<'tcx>,
414 sup: Ty<'tcx>,
415 locations: Locations,
416 category: ConstraintCategory<'tcx>,
417 ) -> Result<(), NoSolution> {
418 self.relate_types(sup, ty::Contravariant, sub, locations, category)
421 }
422
423 #[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(423u32),
::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")]
424 fn eq_types(
425 &mut self,
426 expected: Ty<'tcx>,
427 found: Ty<'tcx>,
428 locations: Locations,
429 category: ConstraintCategory<'tcx>,
430 ) -> Result<(), NoSolution> {
431 self.relate_types(expected, ty::Invariant, found, locations, category)
432 }
433
434 #[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(434u32),
::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:444",
"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(444u32),
::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, locations),
|ty, variant_index, field, ()|
PlaceTy::field_ty(tcx, ty, variant_index, field),
|_|
::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:470",
"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(470u32),
::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 a = self.normalize(a, locations);
let ty = self.normalize(curr_projected_ty.ty, locations);
self.relate_types(ty, v.xform(ty::Contravariant), a, locations,
category)?;
Ok(())
}
}
}#[instrument(skip(self), level = "debug")]
435 fn relate_type_and_user_type(
436 &mut self,
437 a: Ty<'tcx>,
438 v: ty::Variance,
439 user_ty: &UserTypeProjection,
440 locations: Locations,
441 category: ConstraintCategory<'tcx>,
442 ) -> Result<(), NoSolution> {
443 let annotated_type = self.user_type_annotations[user_ty.base].inferred_ty;
444 trace!(?annotated_type);
445 let mut curr_projected_ty = PlaceTy::from_ty(annotated_type);
446
447 let tcx = self.infcx.tcx;
448
449 for proj in &user_ty.projs {
450 if !self.infcx.next_trait_solver()
453 && let ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) =
454 curr_projected_ty.ty.kind()
455 {
456 return Ok(());
460 }
461 let projected_ty = curr_projected_ty.projection_ty_core(
462 tcx,
463 proj,
464 |ty| self.normalize(ty, locations),
465 |ty, variant_index, field, ()| PlaceTy::field_ty(tcx, ty, variant_index, field),
466 |_| unreachable!(),
467 );
468 curr_projected_ty = projected_ty;
469 }
470 trace!(?curr_projected_ty);
471
472 let a = self.normalize(a, locations);
475 let ty = self.normalize(curr_projected_ty.ty, locations);
476 self.relate_types(ty, v.xform(ty::Contravariant), a, locations, category)?;
477
478 Ok(())
479 }
480
481 fn check_promoted(&mut self, promoted_body: &'a Body<'tcx>, location: Location) {
482 let parent_body = mem::replace(&mut self.body, promoted_body);
487
488 let polonius_facts = &mut None;
491 let mut constraints = Default::default();
492 let mut liveness_constraints =
493 LivenessValues::without_specific_points(Rc::new(DenseLocationMap::new(promoted_body)));
494 let mut deferred_closure_requirements = Default::default();
495
496 let mut swap_constraints = |this: &mut Self| {
499 mem::swap(this.polonius_facts, polonius_facts);
500 mem::swap(&mut this.constraints.outlives_constraints, &mut constraints);
501 mem::swap(&mut this.constraints.liveness_constraints, &mut liveness_constraints);
502 mem::swap(this.deferred_closure_requirements, &mut deferred_closure_requirements);
503 };
504
505 swap_constraints(self);
506
507 self.visit_body(promoted_body);
508
509 self.body = parent_body;
510
511 swap_constraints(self);
513 let locations = location.to_locations();
514 for constraint in constraints.outlives().iter() {
515 let mut constraint = *constraint;
516 constraint.locations = locations;
517 if let ConstraintCategory::Return(_)
518 | ConstraintCategory::UseAsConst
519 | ConstraintCategory::UseAsStatic = constraint.category
520 {
521 constraint.category = ConstraintCategory::Boring;
524 }
525 self.constraints.outlives_constraints.push(constraint)
526 }
527
528 for (closure_def_id, args, _locations) in deferred_closure_requirements {
535 self.deferred_closure_requirements.push((closure_def_id, args, locations));
536 }
537
538 #[allow(rustc::potential_query_instability)]
545 for region in liveness_constraints.live_regions_unordered() {
546 self.constraints.liveness_constraints.add_location(region, location);
547 }
548 }
549}
550
551impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
552 fn visit_span(&mut self, span: Span) {
553 if !span.is_dummy() {
554 {
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:554",
"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(554u32),
::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);
555 self.last_span = span;
556 }
557 }
558
559 #[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(559u32),
::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")]
560 fn visit_body(&mut self, body: &Body<'tcx>) {
561 debug_assert!(std::ptr::eq(self.body, body));
562
563 for (local, local_decl) in body.local_decls.iter_enumerated() {
564 self.visit_local_decl(local, local_decl);
565 }
566
567 for (block, block_data) in body.basic_blocks.iter_enumerated() {
568 let mut location = Location { block, statement_index: 0 };
569 for stmt in &block_data.statements {
570 self.visit_statement(stmt, location);
571 location.statement_index += 1;
572 }
573
574 self.visit_terminator(block_data.terminator(), location);
575 self.check_iscleanup(block_data);
576 }
577 }
578
579 #[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(579u32),
::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(box (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:615",
"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(615u32),
::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:622",
"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(622u32),
::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(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:624",
"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(624u32),
::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:626",
"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(626u32),
::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(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:628",
"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(628u32),
::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(box (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(box NonDivergingIntrinsic::Assume(..))
| StatementKind::FakeRead(..) |
StatementKind::StorageLive(..) |
StatementKind::StorageDead(..) | StatementKind::Coverage(..)
| StatementKind::ConstEvalCounter |
StatementKind::PlaceMention(..) |
StatementKind::BackwardIncompatibleDropHint { .. } |
StatementKind::Nop => {}
StatementKind::Intrinsic(box NonDivergingIntrinsic::CopyNonOverlapping(..))
| StatementKind::SetDiscriminant { .. } => {
::rustc_middle::util::bug::bug_fmt(format_args!("Statement not allowed in this MIR phase"))
}
}
}
}
}#[instrument(skip(self), level = "debug")]
580 fn visit_statement(&mut self, stmt: &Statement<'tcx>, location: Location) {
581 self.super_statement(stmt, location);
582 let tcx = self.tcx();
583 match &stmt.kind {
584 StatementKind::Assign(box (place, rv)) => {
585 let category = match place.as_local() {
590 Some(RETURN_PLACE) => {
591 let defining_ty = &self.universal_regions.defining_ty;
592 if defining_ty.is_const() {
593 if tcx.is_static(defining_ty.def_id()) {
594 ConstraintCategory::UseAsStatic
595 } else {
596 ConstraintCategory::UseAsConst
597 }
598 } else {
599 ConstraintCategory::Return(ReturnConstraint::Normal)
600 }
601 }
602 Some(l)
603 if matches!(
604 self.body.local_decls[l].local_info(),
605 LocalInfo::AggregateTemp
606 ) =>
607 {
608 ConstraintCategory::Usage
609 }
610 Some(l) if !self.body.local_decls[l].is_user_variable() => {
611 ConstraintCategory::Boring
612 }
613 _ => ConstraintCategory::Assignment,
614 };
615 debug!(
616 "assignment category: {:?} {:?}",
617 category,
618 place.as_local().map(|l| &self.body.local_decls[l])
619 );
620
621 let place_ty = place.ty(self.body, tcx).ty;
622 debug!(?place_ty);
623 let place_ty = self.normalize(place_ty, location);
624 debug!("place_ty normalized: {:?}", place_ty);
625 let rv_ty = rv.ty(self.body, tcx);
626 debug!(?rv_ty);
627 let rv_ty = self.normalize(rv_ty, location);
628 debug!("normalized rv_ty: {:?}", rv_ty);
629 if let Err(terr) =
630 self.sub_types(rv_ty, place_ty, location.to_locations(), category)
631 {
632 span_mirbug!(
633 self,
634 stmt,
635 "bad assignment ({:?} = {:?}): {:?}",
636 place_ty,
637 rv_ty,
638 terr
639 );
640 }
641
642 if let Some(annotation_index) = self.rvalue_user_ty(rv)
643 && let Err(terr) = self.relate_type_and_user_type(
644 rv_ty,
645 ty::Invariant,
646 &UserTypeProjection { base: annotation_index, projs: vec![] },
647 location.to_locations(),
648 ConstraintCategory::TypeAnnotation(AnnotationSource::GenericArg),
649 )
650 {
651 let annotation = &self.user_type_annotations[annotation_index];
652 span_mirbug!(
653 self,
654 stmt,
655 "bad user type on rvalue ({:?} = {:?}): {:?}",
656 annotation,
657 rv_ty,
658 terr
659 );
660 }
661
662 if !self.tcx().features().unsized_fn_params() {
663 let trait_ref = ty::TraitRef::new(
664 tcx,
665 tcx.require_lang_item(LangItem::Sized, self.last_span),
666 [place_ty],
667 );
668 self.prove_trait_ref(
669 trait_ref,
670 location.to_locations(),
671 ConstraintCategory::SizedBound,
672 );
673 }
674 }
675 StatementKind::AscribeUserType(box (place, projection), variance) => {
676 let place_ty = place.ty(self.body, tcx).ty;
677 if let Err(terr) = self.relate_type_and_user_type(
678 place_ty,
679 *variance,
680 projection,
681 Locations::All(stmt.source_info.span),
682 ConstraintCategory::TypeAnnotation(AnnotationSource::Ascription),
683 ) {
684 let annotation = &self.user_type_annotations[projection.base];
685 span_mirbug!(
686 self,
687 stmt,
688 "bad type assert ({:?} <: {:?} with projections {:?}): {:?}",
689 place_ty,
690 annotation,
691 projection.projs,
692 terr
693 );
694 }
695 }
696 StatementKind::Intrinsic(box NonDivergingIntrinsic::Assume(..))
697 | StatementKind::FakeRead(..)
698 | StatementKind::StorageLive(..)
699 | StatementKind::StorageDead(..)
700 | StatementKind::Coverage(..)
701 | StatementKind::ConstEvalCounter
702 | StatementKind::PlaceMention(..)
703 | StatementKind::BackwardIncompatibleDropHint { .. }
704 | StatementKind::Nop => {}
705 StatementKind::Intrinsic(box NonDivergingIntrinsic::CopyNonOverlapping(..))
706 | StatementKind::SetDiscriminant { .. } => {
707 bug!("Statement not allowed in this MIR phase")
708 }
709 }
710 }
711
712 #[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(712u32),
::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:716",
"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(716u32),
::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:751",
"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(751u32),
::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:785",
"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(785u32),
::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")]
713 fn visit_terminator(&mut self, term: &Terminator<'tcx>, term_location: Location) {
714 self.super_terminator(term, term_location);
715 let tcx = self.tcx();
716 debug!("terminator kind: {:?}", term.kind);
717 match &term.kind {
718 TerminatorKind::Goto { .. }
719 | TerminatorKind::UnwindResume
720 | TerminatorKind::UnwindTerminate(_)
721 | TerminatorKind::Return
722 | TerminatorKind::CoroutineDrop
723 | TerminatorKind::Unreachable
724 | TerminatorKind::Drop { .. }
725 | TerminatorKind::FalseEdge { .. }
726 | TerminatorKind::FalseUnwind { .. }
727 | TerminatorKind::InlineAsm { .. } => {
728 }
730
731 TerminatorKind::SwitchInt { discr, .. } => {
732 let switch_ty = discr.ty(self.body, tcx);
733 if !switch_ty.is_integral() && !switch_ty.is_char() && !switch_ty.is_bool() {
734 span_mirbug!(self, term, "bad SwitchInt discr ty {:?}", switch_ty);
735 }
736 }
738 TerminatorKind::Call { func, args, .. }
739 | TerminatorKind::TailCall { func, args, .. } => {
740 let (call_source, destination, is_diverging) = match term.kind {
741 TerminatorKind::Call { call_source, destination, target, .. } => {
742 (call_source, destination, target.is_none())
743 }
744 TerminatorKind::TailCall { .. } => {
745 (CallSource::Normal, RETURN_PLACE.into(), false)
746 }
747 _ => unreachable!(),
748 };
749
750 let func_ty = func.ty(self.body, tcx);
751 debug!("func_ty.kind: {:?}", func_ty.kind());
752
753 let sig = match func_ty.kind() {
754 ty::FnDef(..) | ty::FnPtr(..) => func_ty.fn_sig(tcx),
755 _ => {
756 span_mirbug!(self, term, "call to non-function {:?}", func_ty);
757 return;
758 }
759 };
760 let (unnormalized_sig, map) = tcx.instantiate_bound_regions(sig, |br| {
761 use crate::renumber::RegionCtxt;
762
763 let region_ctxt_fn = || {
764 let reg_info = match br.kind {
765 ty::BoundRegionKind::Anon => sym::anon,
766 ty::BoundRegionKind::Named(def_id) => tcx.item_name(def_id),
767 ty::BoundRegionKind::ClosureEnv => sym::env,
768 ty::BoundRegionKind::NamedForPrinting(_) => {
769 bug!("only used for pretty printing")
770 }
771 };
772
773 RegionCtxt::LateBound(reg_info)
774 };
775
776 self.infcx.next_region_var(
777 RegionVariableOrigin::BoundRegion(
778 term.source_info.span,
779 br.kind,
780 BoundRegionConversionTime::FnCall,
781 ),
782 region_ctxt_fn,
783 )
784 });
785 debug!(?unnormalized_sig);
786 self.prove_predicates(
795 unnormalized_sig.inputs_and_output.iter().map(|ty| {
796 ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(
797 ty.into(),
798 )))
799 }),
800 term_location.to_locations(),
801 ConstraintCategory::Boring,
802 );
803
804 let sig = self.deeply_normalize(unnormalized_sig, term_location);
805 if sig != unnormalized_sig {
809 self.prove_predicates(
810 sig.inputs_and_output.iter().map(|ty| {
811 ty::Binder::dummy(ty::PredicateKind::Clause(
812 ty::ClauseKind::WellFormed(ty.into()),
813 ))
814 }),
815 term_location.to_locations(),
816 ConstraintCategory::Boring,
817 );
818 }
819
820 self.check_call_dest(term, &sig, destination, is_diverging, term_location);
821
822 for &late_bound_region in map.values() {
830 let region_vid = self.universal_regions.to_region_vid(late_bound_region);
831 self.constraints.liveness_constraints.add_location(region_vid, term_location);
832 }
833
834 self.check_call_inputs(term, func, &sig, args, term_location, call_source);
835 }
836 TerminatorKind::Assert { cond, msg, .. } => {
837 let cond_ty = cond.ty(self.body, tcx);
838 if cond_ty != tcx.types.bool {
839 span_mirbug!(self, term, "bad Assert ({:?}, not bool", cond_ty);
840 }
841
842 if let AssertKind::BoundsCheck { len, index } = &**msg {
843 if len.ty(self.body, tcx) != tcx.types.usize {
844 span_mirbug!(self, len, "bounds-check length non-usize {:?}", len)
845 }
846 if index.ty(self.body, tcx) != tcx.types.usize {
847 span_mirbug!(self, index, "bounds-check index non-usize {:?}", index)
848 }
849 }
850 }
851 TerminatorKind::Yield { value, resume_arg, .. } => {
852 match self.body.yield_ty() {
853 None => span_mirbug!(self, term, "yield in non-coroutine"),
854 Some(ty) => {
855 let value_ty = value.ty(self.body, tcx);
856 if let Err(terr) = self.sub_types(
857 value_ty,
858 ty,
859 term_location.to_locations(),
860 ConstraintCategory::Yield,
861 ) {
862 span_mirbug!(
863 self,
864 term,
865 "type of yield value is {:?}, but the yield type is {:?}: {:?}",
866 value_ty,
867 ty,
868 terr
869 );
870 }
871 }
872 }
873
874 match self.body.resume_ty() {
875 None => span_mirbug!(self, term, "yield in non-coroutine"),
876 Some(ty) => {
877 let resume_ty = resume_arg.ty(self.body, tcx);
878 if let Err(terr) = self.sub_types(
879 ty,
880 resume_ty.ty,
881 term_location.to_locations(),
882 ConstraintCategory::Yield,
883 ) {
884 span_mirbug!(
885 self,
886 term,
887 "type of resume place is {:?}, but the resume type is {:?}: {:?}",
888 resume_ty,
889 ty,
890 terr
891 );
892 }
893 }
894 }
895 }
896 }
897 }
898
899 fn visit_local_decl(&mut self, local: Local, local_decl: &LocalDecl<'tcx>) {
900 self.super_local_decl(local, local_decl);
901
902 for user_ty in
903 local_decl.user_ty.as_deref().into_iter().flat_map(UserTypeProjections::projections)
904 {
905 let span = self.user_type_annotations[user_ty.base].span;
906
907 let ty = if local_decl.is_nonref_binding() {
908 local_decl.ty
909 } else if let &ty::Ref(_, rty, _) = local_decl.ty.kind() {
910 rty
914 } else {
915 ::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);
916 };
917
918 if let Err(terr) = self.relate_type_and_user_type(
919 ty,
920 ty::Invariant,
921 user_ty,
922 Locations::All(span),
923 ConstraintCategory::TypeAnnotation(AnnotationSource::Declaration),
924 ) {
925 {
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!(
926 self,
927 local,
928 "bad user type on variable {:?}: {:?} != {:?} ({:?})",
929 local,
930 local_decl.ty,
931 local_decl.user_ty,
932 terr,
933 );
934 }
935 }
936
937 if !self.tcx().features().unsized_fn_params() {
941 match self.body.local_kind(local) {
942 LocalKind::ReturnPointer | LocalKind::Arg => {
943 return;
950 }
951 LocalKind::Temp => {
952 let span = local_decl.source_info.span;
953 let ty = local_decl.ty;
954 self.ensure_place_sized(ty, span);
955 }
956 }
957 }
958 }
959
960 #[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(960u32),
::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(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(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(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:1506",
"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(1506u32),
::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::BinaryOp(BinOp::Eq | BinOp::Ne | BinOp::Lt | BinOp::Le
| BinOp::Gt | BinOp::Ge, box (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")]
961 fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
962 self.super_rvalue(rvalue, location);
963 let tcx = self.tcx();
964 let span = self.body.source_info(location).span;
965 match rvalue {
966 Rvalue::Aggregate(ak, ops) => self.check_aggregate_rvalue(rvalue, ak, ops, location),
967
968 Rvalue::Repeat(operand, len) => {
969 let array_ty = rvalue.ty(self.body.local_decls(), tcx);
970 self.prove_predicate(
971 ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(array_ty.into())),
972 Locations::Single(location),
973 ConstraintCategory::Boring,
974 );
975
976 if len.try_to_target_usize(tcx).is_none_or(|len| len > 1) {
981 match operand {
982 Operand::Copy(..) | Operand::Constant(..) | Operand::RuntimeChecks(_) => {
983 }
986 Operand::Move(place) => {
987 let ty = place.ty(self.body, tcx).ty;
989 let trait_ref = ty::TraitRef::new(
990 tcx,
991 tcx.require_lang_item(LangItem::Copy, span),
992 [ty],
993 );
994
995 self.prove_trait_ref(
996 trait_ref,
997 Locations::Single(location),
998 ConstraintCategory::CopyBound,
999 );
1000 }
1001 }
1002 }
1003 }
1004
1005 Rvalue::Cast(cast_kind, op, ty) => {
1006 match *cast_kind {
1007 CastKind::PointerCoercion(
1008 PointerCoercion::ReifyFnPointer(target_safety),
1009 coercion_source,
1010 ) => {
1011 let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
1012 let src_ty = op.ty(self.body, tcx);
1013 let mut src_sig = src_ty.fn_sig(tcx);
1014 if let ty::FnDef(def_id, _) = *src_ty.kind()
1015 && let ty::FnPtr(_, target_hdr) = *ty.kind()
1016 && tcx.codegen_fn_attrs(def_id).safe_target_features
1017 && target_hdr.safety().is_safe()
1018 && let Some(safe_sig) = tcx.adjust_target_feature_sig(
1019 def_id,
1020 src_sig,
1021 self.body.source.def_id(),
1022 )
1023 {
1024 src_sig = safe_sig;
1025 }
1026
1027 if src_sig.safety().is_safe() && target_safety.is_unsafe() {
1028 src_sig = tcx.safe_to_unsafe_sig(src_sig);
1029 }
1030
1031 if src_sig.has_bound_regions()
1046 && let ty::FnPtr(target_fn_tys, target_hdr) = *ty.kind()
1047 && let target_sig = target_fn_tys.with(target_hdr)
1048 && let Some(target_sig) = target_sig.no_bound_vars()
1049 {
1050 let src_sig = self.infcx.instantiate_binder_with_fresh_vars(
1051 span,
1052 BoundRegionConversionTime::HigherRankedType,
1053 src_sig,
1054 );
1055 let src_ty = Ty::new_fn_ptr(self.tcx(), ty::Binder::dummy(src_sig));
1056 self.prove_predicate(
1057 ty::ClauseKind::WellFormed(src_ty.into()),
1058 location.to_locations(),
1059 ConstraintCategory::Cast {
1060 is_raw_ptr_dyn_type_cast: false,
1061 is_implicit_coercion,
1062 unsize_to: None,
1063 },
1064 );
1065
1066 let src_ty = self.normalize(src_ty, location);
1067 if let Err(terr) = self.sub_types(
1068 src_ty,
1069 *ty,
1070 location.to_locations(),
1071 ConstraintCategory::Cast {
1072 is_raw_ptr_dyn_type_cast: false,
1073 is_implicit_coercion,
1074 unsize_to: None,
1075 },
1076 ) {
1077 span_mirbug!(
1078 self,
1079 rvalue,
1080 "equating {:?} with {:?} yields {:?}",
1081 target_sig,
1082 src_sig,
1083 terr
1084 );
1085 };
1086 }
1087
1088 let src_ty = Ty::new_fn_ptr(tcx, src_sig);
1089 self.prove_predicate(
1094 ty::ClauseKind::WellFormed(src_ty.into()),
1095 location.to_locations(),
1096 ConstraintCategory::Cast {
1097 is_raw_ptr_dyn_type_cast: false,
1098 is_implicit_coercion,
1099 unsize_to: None,
1100 },
1101 );
1102
1103 let src_ty = self.normalize(src_ty, location);
1109 if let Err(terr) = self.sub_types(
1110 src_ty,
1111 *ty,
1112 location.to_locations(),
1113 ConstraintCategory::Cast {
1114 is_raw_ptr_dyn_type_cast: false,
1115 is_implicit_coercion,
1116 unsize_to: None,
1117 },
1118 ) {
1119 span_mirbug!(
1120 self,
1121 rvalue,
1122 "equating {:?} with {:?} yields {:?}",
1123 src_ty,
1124 ty,
1125 terr
1126 );
1127 }
1128 }
1129
1130 CastKind::PointerCoercion(
1131 PointerCoercion::ClosureFnPointer(safety),
1132 coercion_source,
1133 ) => {
1134 let sig = match op.ty(self.body, tcx).kind() {
1135 ty::Closure(_, args) => args.as_closure().sig(),
1136 _ => bug!(),
1137 };
1138 let ty_fn_ptr_from =
1139 Ty::new_fn_ptr(tcx, tcx.signature_unclosure(sig, safety));
1140
1141 let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
1142 if let Err(terr) = self.sub_types(
1143 ty_fn_ptr_from,
1144 *ty,
1145 location.to_locations(),
1146 ConstraintCategory::Cast {
1147 is_raw_ptr_dyn_type_cast: false,
1148 is_implicit_coercion,
1149 unsize_to: None,
1150 },
1151 ) {
1152 span_mirbug!(
1153 self,
1154 rvalue,
1155 "equating {:?} with {:?} yields {:?}",
1156 ty_fn_ptr_from,
1157 ty,
1158 terr
1159 );
1160 }
1161 }
1162
1163 CastKind::PointerCoercion(
1164 PointerCoercion::UnsafeFnPointer,
1165 coercion_source,
1166 ) => {
1167 let fn_sig = op.ty(self.body, tcx).fn_sig(tcx);
1168
1169 let fn_sig = self.normalize(fn_sig, location);
1175
1176 let ty_fn_ptr_from = tcx.safe_to_unsafe_fn_ty(fn_sig);
1177
1178 let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
1179 if let Err(terr) = self.sub_types(
1180 ty_fn_ptr_from,
1181 *ty,
1182 location.to_locations(),
1183 ConstraintCategory::Cast {
1184 is_raw_ptr_dyn_type_cast: false,
1185 is_implicit_coercion,
1186 unsize_to: None,
1187 },
1188 ) {
1189 span_mirbug!(
1190 self,
1191 rvalue,
1192 "equating {:?} with {:?} yields {:?}",
1193 ty_fn_ptr_from,
1194 ty,
1195 terr
1196 );
1197 }
1198 }
1199
1200 CastKind::PointerCoercion(PointerCoercion::Unsize, coercion_source) => {
1201 let &ty = ty;
1202 let trait_ref = ty::TraitRef::new(
1203 tcx,
1204 tcx.require_lang_item(LangItem::CoerceUnsized, span),
1205 [op.ty(self.body, tcx), ty],
1206 );
1207
1208 let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
1209 let unsize_to = fold_regions(tcx, ty, |r, _| {
1210 if let ty::ReVar(_) = r.kind() { tcx.lifetimes.re_erased } else { r }
1211 });
1212 self.prove_trait_ref(
1213 trait_ref,
1214 location.to_locations(),
1215 ConstraintCategory::Cast {
1216 is_raw_ptr_dyn_type_cast: false,
1217 is_implicit_coercion,
1218 unsize_to: Some(unsize_to),
1219 },
1220 );
1221 }
1222
1223 CastKind::PointerCoercion(
1224 PointerCoercion::MutToConstPointer,
1225 coercion_source,
1226 ) => {
1227 let ty::RawPtr(ty_from, hir::Mutability::Mut) =
1228 op.ty(self.body, tcx).kind()
1229 else {
1230 span_mirbug!(self, rvalue, "unexpected base type for cast {:?}", ty,);
1231 return;
1232 };
1233 let ty::RawPtr(ty_to, hir::Mutability::Not) = ty.kind() else {
1234 span_mirbug!(self, rvalue, "unexpected target type for cast {:?}", ty,);
1235 return;
1236 };
1237 let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
1238 if let Err(terr) = self.sub_types(
1239 *ty_from,
1240 *ty_to,
1241 location.to_locations(),
1242 ConstraintCategory::Cast {
1243 is_raw_ptr_dyn_type_cast: false,
1244 is_implicit_coercion,
1245 unsize_to: None,
1246 },
1247 ) {
1248 span_mirbug!(
1249 self,
1250 rvalue,
1251 "relating {:?} with {:?} yields {:?}",
1252 ty_from,
1253 ty_to,
1254 terr
1255 );
1256 }
1257 }
1258
1259 CastKind::PointerCoercion(PointerCoercion::ArrayToPointer, coercion_source) => {
1260 let ty_from = op.ty(self.body, tcx);
1261
1262 let opt_ty_elem_mut = match ty_from.kind() {
1263 ty::RawPtr(array_ty, array_mut) => match array_ty.kind() {
1264 ty::Array(ty_elem, _) => Some((ty_elem, *array_mut)),
1265 _ => None,
1266 },
1267 _ => None,
1268 };
1269
1270 let Some((ty_elem, ty_mut)) = opt_ty_elem_mut else {
1271 span_mirbug!(
1272 self,
1273 rvalue,
1274 "ArrayToPointer cast from unexpected type {:?}",
1275 ty_from,
1276 );
1277 return;
1278 };
1279
1280 let (ty_to, ty_to_mut) = match ty.kind() {
1281 ty::RawPtr(ty_to, ty_to_mut) => (ty_to, *ty_to_mut),
1282 _ => {
1283 span_mirbug!(
1284 self,
1285 rvalue,
1286 "ArrayToPointer cast to unexpected type {:?}",
1287 ty,
1288 );
1289 return;
1290 }
1291 };
1292
1293 if ty_to_mut.is_mut() && ty_mut.is_not() {
1294 span_mirbug!(
1295 self,
1296 rvalue,
1297 "ArrayToPointer cast from const {:?} to mut {:?}",
1298 ty,
1299 ty_to
1300 );
1301 return;
1302 }
1303
1304 let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
1305 if let Err(terr) = self.sub_types(
1306 *ty_elem,
1307 *ty_to,
1308 location.to_locations(),
1309 ConstraintCategory::Cast {
1310 is_raw_ptr_dyn_type_cast: false,
1311 is_implicit_coercion,
1312 unsize_to: None,
1313 },
1314 ) {
1315 span_mirbug!(
1316 self,
1317 rvalue,
1318 "relating {:?} with {:?} yields {:?}",
1319 ty_elem,
1320 ty_to,
1321 terr
1322 )
1323 }
1324 }
1325
1326 CastKind::PointerExposeProvenance => {
1327 let ty_from = op.ty(self.body, tcx);
1328 let cast_ty_from = CastTy::from_ty(ty_from);
1329 let cast_ty_to = CastTy::from_ty(*ty);
1330 match (cast_ty_from, cast_ty_to) {
1331 (Some(CastTy::Ptr(_) | CastTy::FnPtr), Some(CastTy::Int(_))) => (),
1332 _ => {
1333 span_mirbug!(
1334 self,
1335 rvalue,
1336 "Invalid PointerExposeProvenance cast {:?} -> {:?}",
1337 ty_from,
1338 ty
1339 )
1340 }
1341 }
1342 }
1343
1344 CastKind::PointerWithExposedProvenance => {
1345 let ty_from = op.ty(self.body, tcx);
1346 let cast_ty_from = CastTy::from_ty(ty_from);
1347 let cast_ty_to = CastTy::from_ty(*ty);
1348 match (cast_ty_from, cast_ty_to) {
1349 (Some(CastTy::Int(_)), Some(CastTy::Ptr(_))) => (),
1350 _ => {
1351 span_mirbug!(
1352 self,
1353 rvalue,
1354 "Invalid PointerWithExposedProvenance cast {:?} -> {:?}",
1355 ty_from,
1356 ty
1357 )
1358 }
1359 }
1360 }
1361 CastKind::IntToInt => {
1362 let ty_from = op.ty(self.body, tcx);
1363 let cast_ty_from = CastTy::from_ty(ty_from);
1364 let cast_ty_to = CastTy::from_ty(*ty);
1365 match (cast_ty_from, cast_ty_to) {
1366 (Some(CastTy::Int(_)), Some(CastTy::Int(_))) => (),
1367 _ => {
1368 span_mirbug!(
1369 self,
1370 rvalue,
1371 "Invalid IntToInt cast {:?} -> {:?}",
1372 ty_from,
1373 ty
1374 )
1375 }
1376 }
1377 }
1378 CastKind::IntToFloat => {
1379 let ty_from = op.ty(self.body, tcx);
1380 let cast_ty_from = CastTy::from_ty(ty_from);
1381 let cast_ty_to = CastTy::from_ty(*ty);
1382 match (cast_ty_from, cast_ty_to) {
1383 (Some(CastTy::Int(_)), Some(CastTy::Float)) => (),
1384 _ => {
1385 span_mirbug!(
1386 self,
1387 rvalue,
1388 "Invalid IntToFloat cast {:?} -> {:?}",
1389 ty_from,
1390 ty
1391 )
1392 }
1393 }
1394 }
1395 CastKind::FloatToInt => {
1396 let ty_from = op.ty(self.body, tcx);
1397 let cast_ty_from = CastTy::from_ty(ty_from);
1398 let cast_ty_to = CastTy::from_ty(*ty);
1399 match (cast_ty_from, cast_ty_to) {
1400 (Some(CastTy::Float), Some(CastTy::Int(_))) => (),
1401 _ => {
1402 span_mirbug!(
1403 self,
1404 rvalue,
1405 "Invalid FloatToInt cast {:?} -> {:?}",
1406 ty_from,
1407 ty
1408 )
1409 }
1410 }
1411 }
1412 CastKind::FloatToFloat => {
1413 let ty_from = op.ty(self.body, tcx);
1414 let cast_ty_from = CastTy::from_ty(ty_from);
1415 let cast_ty_to = CastTy::from_ty(*ty);
1416 match (cast_ty_from, cast_ty_to) {
1417 (Some(CastTy::Float), Some(CastTy::Float)) => (),
1418 _ => {
1419 span_mirbug!(
1420 self,
1421 rvalue,
1422 "Invalid FloatToFloat cast {:?} -> {:?}",
1423 ty_from,
1424 ty
1425 )
1426 }
1427 }
1428 }
1429 CastKind::FnPtrToPtr => {
1430 let ty_from = op.ty(self.body, tcx);
1431 let cast_ty_from = CastTy::from_ty(ty_from);
1432 let cast_ty_to = CastTy::from_ty(*ty);
1433 match (cast_ty_from, cast_ty_to) {
1434 (Some(CastTy::FnPtr), Some(CastTy::Ptr(_))) => (),
1435 _ => {
1436 span_mirbug!(
1437 self,
1438 rvalue,
1439 "Invalid FnPtrToPtr cast {:?} -> {:?}",
1440 ty_from,
1441 ty
1442 )
1443 }
1444 }
1445 }
1446 CastKind::PtrToPtr => {
1447 let ty_from = op.ty(self.body, tcx);
1448 let Some(CastTy::Ptr(src)) = CastTy::from_ty(ty_from) else {
1449 unreachable!();
1450 };
1451 let Some(CastTy::Ptr(dst)) = CastTy::from_ty(*ty) else {
1452 unreachable!();
1453 };
1454
1455 if self.infcx.type_is_sized_modulo_regions(self.infcx.param_env, dst.ty) {
1456 let trait_ref = ty::TraitRef::new(
1462 tcx,
1463 tcx.require_lang_item(LangItem::Sized, self.last_span),
1464 [dst.ty],
1465 );
1466 self.prove_trait_ref(
1467 trait_ref,
1468 location.to_locations(),
1469 ConstraintCategory::Cast {
1470 is_raw_ptr_dyn_type_cast: false,
1471 is_implicit_coercion: true,
1472 unsize_to: None,
1473 },
1474 );
1475 } else if let ty::Dynamic(src_tty, src_lt) =
1476 *self.struct_tail(src.ty, location).kind()
1477 && let ty::Dynamic(dst_tty, dst_lt) =
1478 *self.struct_tail(dst.ty, location).kind()
1479 {
1480 match (src_tty.principal(), dst_tty.principal()) {
1481 (Some(_), Some(_)) => {
1482 let src_obj = Ty::new_dynamic(
1492 tcx,
1493 tcx.mk_poly_existential_predicates(
1494 &src_tty.without_auto_traits().collect::<Vec<_>>(),
1495 ),
1496 src_lt,
1497 );
1498 let dst_obj = Ty::new_dynamic(
1499 tcx,
1500 tcx.mk_poly_existential_predicates(
1501 &dst_tty.without_auto_traits().collect::<Vec<_>>(),
1502 ),
1503 dst_lt,
1504 );
1505
1506 debug!(?src_tty, ?dst_tty, ?src_obj, ?dst_obj);
1507
1508 self.sub_types(
1517 src_obj,
1518 dst_obj,
1519 location.to_locations(),
1520 ConstraintCategory::Cast {
1521 is_raw_ptr_dyn_type_cast: true,
1522 is_implicit_coercion: false,
1523 unsize_to: None,
1524 },
1525 )
1526 .unwrap();
1527 }
1528 (None, None) => {
1529 let src_lt = self.universal_regions.to_region_vid(src_lt);
1533 let dst_lt = self.universal_regions.to_region_vid(dst_lt);
1534
1535 self.constraints.outlives_constraints.push(
1538 OutlivesConstraint {
1539 sup: src_lt,
1540 sub: dst_lt,
1541 locations: location.to_locations(),
1542 span: location.to_locations().span(self.body),
1543 category: ConstraintCategory::Cast {
1544 is_raw_ptr_dyn_type_cast: true,
1545 is_implicit_coercion: false,
1546 unsize_to: None,
1547 },
1548 variance_info: ty::VarianceDiagInfo::default(),
1549 from_closure: false,
1550 },
1551 );
1552 }
1553 (None, Some(_)) => bug!(
1554 "introducing a principal should have errored in HIR typeck"
1555 ),
1556 (Some(_), None) => {
1557 bug!("dropping the principal should have been an unsizing cast")
1558 }
1559 }
1560 }
1561 }
1562 CastKind::Transmute => {
1563 let ty_from = op.ty(self.body, tcx);
1564 match ty_from.kind() {
1565 ty::Pat(base, _) if base == ty => {}
1566 _ => span_mirbug!(
1567 self,
1568 rvalue,
1569 "Unexpected CastKind::Transmute {ty_from:?} -> {ty:?}, which is not permitted in Analysis MIR",
1570 ),
1571 }
1572 }
1573 CastKind::Subtype => {
1574 bug!("CastKind::Subtype shouldn't exist in borrowck")
1575 }
1576 }
1577 }
1578
1579 Rvalue::Ref(region, _borrow_kind, borrowed_place) => {
1580 self.add_reborrow_constraint(location, *region, borrowed_place);
1581 }
1582
1583 Rvalue::BinaryOp(
1584 BinOp::Eq | BinOp::Ne | BinOp::Lt | BinOp::Le | BinOp::Gt | BinOp::Ge,
1585 box (left, right),
1586 ) => {
1587 let ty_left = left.ty(self.body, tcx);
1588 match ty_left.kind() {
1589 ty::RawPtr(_, _) | ty::FnPtr(..) => {
1591 let ty_right = right.ty(self.body, tcx);
1592 let common_ty =
1593 self.infcx.next_ty_var(self.body.source_info(location).span);
1594 self.sub_types(
1595 ty_left,
1596 common_ty,
1597 location.to_locations(),
1598 ConstraintCategory::CallArgument(None),
1599 )
1600 .unwrap_or_else(|err| {
1601 bug!("Could not equate type variable with {:?}: {:?}", ty_left, err)
1602 });
1603 if let Err(terr) = self.sub_types(
1604 ty_right,
1605 common_ty,
1606 location.to_locations(),
1607 ConstraintCategory::CallArgument(None),
1608 ) {
1609 span_mirbug!(
1610 self,
1611 rvalue,
1612 "unexpected comparison types {:?} and {:?} yields {:?}",
1613 ty_left,
1614 ty_right,
1615 terr
1616 )
1617 }
1618 }
1619 ty::Int(_) | ty::Uint(_) | ty::Bool | ty::Char | ty::Float(_)
1622 if ty_left == right.ty(self.body, tcx) => {}
1623 _ => span_mirbug!(
1626 self,
1627 rvalue,
1628 "unexpected comparison types {:?} and {:?}",
1629 ty_left,
1630 right.ty(self.body, tcx)
1631 ),
1632 }
1633 }
1634
1635 Rvalue::WrapUnsafeBinder(op, ty) => {
1636 let operand_ty = op.ty(self.body, self.tcx());
1637 let ty::UnsafeBinder(binder_ty) = *ty.kind() else {
1638 unreachable!();
1639 };
1640 let expected_ty = self.infcx.instantiate_binder_with_fresh_vars(
1641 self.body().source_info(location).span,
1642 BoundRegionConversionTime::HigherRankedType,
1643 binder_ty.into(),
1644 );
1645 self.sub_types(
1646 operand_ty,
1647 expected_ty,
1648 location.to_locations(),
1649 ConstraintCategory::Boring,
1650 )
1651 .unwrap();
1652 }
1653
1654 Rvalue::Use(_, _)
1655 | Rvalue::UnaryOp(_, _)
1656 | Rvalue::CopyForDeref(_)
1657 | Rvalue::BinaryOp(..)
1658 | Rvalue::RawPtr(..)
1659 | Rvalue::ThreadLocalRef(..)
1660 | Rvalue::Discriminant(..) => {}
1661 }
1662 }
1663
1664 #[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(1664u32),
::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))]
1665 fn visit_operand(&mut self, op: &Operand<'tcx>, location: Location) {
1666 self.super_operand(op, location);
1667 if let Operand::Constant(constant) = op {
1668 let maybe_uneval = match constant.const_ {
1669 Const::Val(..) | Const::Ty(_, _) => None,
1670 Const::Unevaluated(uv, _) => Some(uv),
1671 };
1672
1673 if let Some(uv) = maybe_uneval {
1674 if uv.promoted.is_none() {
1675 let tcx = self.tcx();
1676 let def_id = uv.def;
1677 if tcx.def_kind(def_id) == DefKind::InlineConst {
1678 let def_id = def_id.expect_local();
1679 let predicates = self.prove_closure_bounds(tcx, def_id, uv.args, location);
1680 self.normalize_and_prove_instantiated_predicates(
1681 def_id.to_def_id(),
1682 predicates,
1683 location.to_locations(),
1684 );
1685 }
1686 }
1687 }
1688 }
1689 }
1690
1691 #[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(1691u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::type_check"),
::tracing_core::field::FieldSet::new(&["constant",
"location"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&constant)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&location)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
self.super_const_operand(constant, location);
let ty = constant.const_.ty();
self.infcx.tcx.for_each_free_region(&ty,
|live_region|
{
let live_region_vid =
self.universal_regions.to_region_vid(live_region);
self.constraints.liveness_constraints.add_location(live_region_vid,
location);
});
let locations = location.to_locations();
if let Some(annotation_index) = constant.user_ty {
if let Err(terr) =
self.relate_type_and_user_type(constant.const_.ty(),
ty::Invariant,
&UserTypeProjection {
base: annotation_index,
projs: ::alloc::vec::Vec::new(),
}, locations,
ConstraintCategory::TypeAnnotation(AnnotationSource::GenericArg))
{
let annotation =
&self.user_type_annotations[annotation_index];
{
crate::type_check::mirbug(self.tcx(), self.last_span,
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
self.body().source.def_id(), constant,
format_args!("bad constant user type {0:?} vs {1:?}: {2:?}",
annotation, constant.const_.ty(), terr)))
}))
};
}
} else {
let tcx = self.tcx();
let maybe_uneval =
match constant.const_ {
Const::Ty(_, ct) =>
match ct.kind() {
ty::ConstKind::Unevaluated(uv) => {
Some(UnevaluatedConst {
def: uv.def,
args: uv.args,
promoted: None,
})
}
_ => None,
},
Const::Unevaluated(uv, _) => Some(uv),
_ => None,
};
if let Some(uv) = maybe_uneval {
if let Some(promoted) = uv.promoted {
let promoted_body = &self.promoted[promoted];
self.check_promoted(promoted_body, location);
let promoted_ty = promoted_body.return_ty();
if let Err(terr) =
self.eq_types(ty, promoted_ty, locations,
ConstraintCategory::Boring) {
{
crate::type_check::mirbug(self.tcx(), self.last_span,
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("broken MIR in {0:?} ({1:?}): {2}",
self.body().source.def_id(), promoted,
format_args!("bad promoted type ({0:?}: {1:?}): {2:?}", ty,
promoted_ty, terr)))
}))
};
};
} else {
self.ascribe_user_type(constant.const_.ty(),
ty::UserType::new(ty::UserTypeKind::TypeOf(uv.def,
UserArgs { args: uv.args, user_self_ty: None })),
locations.span(self.body));
}
} else if let Some(static_def_id) =
constant.check_static_ptr(tcx) {
let unnormalized_ty =
tcx.type_of(static_def_id).instantiate_identity().skip_norm_wip();
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))]
1692 fn visit_const_operand(&mut self, constant: &ConstOperand<'tcx>, location: Location) {
1693 self.super_const_operand(constant, location);
1694 let ty = constant.const_.ty();
1695
1696 self.infcx.tcx.for_each_free_region(&ty, |live_region| {
1697 let live_region_vid = self.universal_regions.to_region_vid(live_region);
1698 self.constraints.liveness_constraints.add_location(live_region_vid, location);
1699 });
1700
1701 let locations = location.to_locations();
1702 if let Some(annotation_index) = constant.user_ty {
1703 if let Err(terr) = self.relate_type_and_user_type(
1704 constant.const_.ty(),
1705 ty::Invariant,
1706 &UserTypeProjection { base: annotation_index, projs: vec![] },
1707 locations,
1708 ConstraintCategory::TypeAnnotation(AnnotationSource::GenericArg),
1709 ) {
1710 let annotation = &self.user_type_annotations[annotation_index];
1711 span_mirbug!(
1712 self,
1713 constant,
1714 "bad constant user type {:?} vs {:?}: {:?}",
1715 annotation,
1716 constant.const_.ty(),
1717 terr,
1718 );
1719 }
1720 } else {
1721 let tcx = self.tcx();
1722 let maybe_uneval = match constant.const_ {
1723 Const::Ty(_, ct) => match ct.kind() {
1724 ty::ConstKind::Unevaluated(uv) => {
1725 Some(UnevaluatedConst { def: uv.def, args: uv.args, promoted: None })
1726 }
1727 _ => None,
1728 },
1729 Const::Unevaluated(uv, _) => Some(uv),
1730 _ => None,
1731 };
1732
1733 if let Some(uv) = maybe_uneval {
1734 if let Some(promoted) = uv.promoted {
1735 let promoted_body = &self.promoted[promoted];
1736 self.check_promoted(promoted_body, location);
1737 let promoted_ty = promoted_body.return_ty();
1738 if let Err(terr) =
1739 self.eq_types(ty, promoted_ty, locations, ConstraintCategory::Boring)
1740 {
1741 span_mirbug!(
1742 self,
1743 promoted,
1744 "bad promoted type ({:?}: {:?}): {:?}",
1745 ty,
1746 promoted_ty,
1747 terr
1748 );
1749 };
1750 } else {
1751 self.ascribe_user_type(
1752 constant.const_.ty(),
1753 ty::UserType::new(ty::UserTypeKind::TypeOf(
1754 uv.def,
1755 UserArgs { args: uv.args, user_self_ty: None },
1756 )),
1757 locations.span(self.body),
1758 );
1759 }
1760 } else if let Some(static_def_id) = constant.check_static_ptr(tcx) {
1761 let unnormalized_ty =
1762 tcx.type_of(static_def_id).instantiate_identity().skip_norm_wip();
1763 let normalized_ty = self.normalize(unnormalized_ty, locations);
1764 let literal_ty = constant.const_.ty().builtin_deref(true).unwrap();
1765
1766 if let Err(terr) =
1767 self.eq_types(literal_ty, normalized_ty, locations, ConstraintCategory::Boring)
1768 {
1769 span_mirbug!(self, constant, "bad static type {:?} ({:?})", constant, terr);
1770 }
1771 } else if let Const::Ty(_, ct) = constant.const_
1772 && let ty::ConstKind::Param(p) = ct.kind()
1773 {
1774 let body_def_id = self.universal_regions.defining_ty.def_id();
1775 let const_param = tcx.generics_of(body_def_id).const_param(p, tcx);
1776 self.ascribe_user_type(
1777 constant.const_.ty(),
1778 ty::UserType::new(ty::UserTypeKind::TypeOf(
1779 const_param.def_id,
1780 UserArgs {
1781 args: self.universal_regions.defining_ty.args(),
1782 user_self_ty: None,
1783 },
1784 )),
1785 locations.span(self.body),
1786 );
1787 }
1788
1789 if let ty::FnDef(def_id, args) = *constant.const_.ty().kind() {
1790 let instantiated_predicates = tcx.predicates_of(def_id).instantiate(tcx, args);
1791 self.normalize_and_prove_instantiated_predicates(
1792 def_id,
1793 instantiated_predicates,
1794 locations,
1795 );
1796
1797 assert_eq!(tcx.trait_impl_of_assoc(def_id), None);
1798 self.prove_predicates(
1799 args.types().map(|ty| ty::ClauseKind::WellFormed(ty.into())),
1800 locations,
1801 ConstraintCategory::Boring,
1802 );
1803 }
1804 }
1805 }
1806
1807 fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, location: Location) {
1808 self.super_place(place, context, location);
1809 let tcx = self.tcx();
1810 let place_ty = place.ty(self.body, tcx);
1811 if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context {
1812 let trait_ref = ty::TraitRef::new(
1813 tcx,
1814 tcx.require_lang_item(LangItem::Copy, self.last_span),
1815 [place_ty.ty],
1816 );
1817
1818 self.prove_trait_ref(trait_ref, location.to_locations(), ConstraintCategory::CopyBound);
1830 }
1831 }
1832
1833 fn visit_projection_elem(
1834 &mut self,
1835 place: PlaceRef<'tcx>,
1836 elem: PlaceElem<'tcx>,
1837 context: PlaceContext,
1838 location: Location,
1839 ) {
1840 let tcx = self.tcx();
1841 let base_ty = place.ty(self.body(), tcx);
1842 match elem {
1843 ProjectionElem::Deref
1846 | ProjectionElem::Index(_)
1847 | ProjectionElem::ConstantIndex { .. }
1848 | ProjectionElem::Subslice { .. }
1849 | ProjectionElem::Downcast(..) => {}
1850 ProjectionElem::Field(field, fty) => {
1851 let fty = self.normalize(fty, location);
1852 let ty = PlaceTy::field_ty(tcx, base_ty.ty, base_ty.variant_index, field);
1853 let ty = self.normalize(ty, location);
1854 {
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:1854",
"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(1854u32),
::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);
1855
1856 if let Err(terr) = self.relate_types(
1857 ty,
1858 context.ambient_variance(),
1859 fty,
1860 location.to_locations(),
1861 ConstraintCategory::Boring,
1862 ) {
1863 {
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);
1864 }
1865 }
1866 ProjectionElem::OpaqueCast(ty) => {
1867 let ty = self.normalize(ty, location);
1868 self.relate_types(
1869 ty,
1870 context.ambient_variance(),
1871 base_ty.ty,
1872 location.to_locations(),
1873 ConstraintCategory::TypeAnnotation(AnnotationSource::OpaqueCast),
1874 )
1875 .unwrap();
1876 }
1877 ProjectionElem::UnwrapUnsafeBinder(ty) => {
1878 let ty::UnsafeBinder(binder_ty) = *base_ty.ty.kind() else {
1879 ::core::panicking::panic("internal error: entered unreachable code");unreachable!();
1880 };
1881 let found_ty = self.infcx.instantiate_binder_with_fresh_vars(
1882 self.body.source_info(location).span,
1883 BoundRegionConversionTime::HigherRankedType,
1884 binder_ty.into(),
1885 );
1886 self.relate_types(
1887 ty,
1888 context.ambient_variance(),
1889 found_ty,
1890 location.to_locations(),
1891 ConstraintCategory::Boring,
1892 )
1893 .unwrap();
1894 }
1895 }
1896 }
1897}
1898
1899impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
1900 fn check_call_dest(
1901 &mut self,
1902 term: &Terminator<'tcx>,
1903 sig: &ty::FnSig<'tcx>,
1904 destination: Place<'tcx>,
1905 is_diverging: bool,
1906 term_location: Location,
1907 ) {
1908 let tcx = self.tcx();
1909 if is_diverging {
1910 let output_ty = self.tcx().erase_and_anonymize_regions(sig.output());
1913 if !output_ty
1914 .is_privately_uninhabited(self.tcx(), self.infcx.typing_env(self.infcx.param_env))
1915 {
1916 {
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);
1917 }
1918 } else {
1919 let dest_ty = destination.ty(self.body, tcx).ty;
1920 let dest_ty = self.normalize(dest_ty, term_location);
1921 let category = match destination.as_local() {
1922 Some(RETURN_PLACE) => {
1923 if let DefiningTy::Const(def_id, _) | DefiningTy::InlineConst(def_id, _) =
1924 self.universal_regions.defining_ty
1925 {
1926 if tcx.is_static(def_id) {
1927 ConstraintCategory::UseAsStatic
1928 } else {
1929 ConstraintCategory::UseAsConst
1930 }
1931 } else {
1932 ConstraintCategory::Return(ReturnConstraint::Normal)
1933 }
1934 }
1935 Some(l) if !self.body.local_decls[l].is_user_variable() => {
1936 ConstraintCategory::Boring
1937 }
1938 _ => ConstraintCategory::Assignment,
1940 };
1941
1942 let locations = term_location.to_locations();
1943
1944 if let Err(terr) = self.sub_types(sig.output(), dest_ty, locations, category) {
1945 {
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!(
1946 self,
1947 term,
1948 "call dest mismatch ({:?} <- {:?}): {:?}",
1949 dest_ty,
1950 sig.output(),
1951 terr
1952 );
1953 }
1954
1955 if self.tcx().features().unsized_fn_params() {
1958 let span = term.source_info.span;
1959 self.ensure_place_sized(dest_ty, span);
1960 }
1961 }
1962 }
1963
1964 #[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(1964u32),
::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:2000",
"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(2000u32),
::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(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))]
1965 fn check_call_inputs(
1966 &mut self,
1967 term: &Terminator<'tcx>,
1968 func: &Operand<'tcx>,
1969 sig: &ty::FnSig<'tcx>,
1970 args: &[Spanned<Operand<'tcx>>],
1971 term_location: Location,
1972 call_source: CallSource,
1973 ) {
1974 if args.len() < sig.inputs().len() || (args.len() > sig.inputs().len() && !sig.c_variadic())
1975 {
1976 span_mirbug!(self, term, "call to {:?} with wrong # of args", sig);
1977 }
1978
1979 let func_ty = func.ty(self.body, self.infcx.tcx);
1980 if let ty::FnDef(def_id, _) = *func_ty.kind() {
1981 if let Some(name @ (sym::simd_shuffle | sym::simd_insert | sym::simd_extract)) =
1985 self.tcx().intrinsic(def_id).map(|i| i.name)
1986 {
1987 let idx = match name {
1988 sym::simd_shuffle => 2,
1989 _ => 1,
1990 };
1991 if !matches!(args[idx], Spanned { node: Operand::Constant(_), .. }) {
1992 self.tcx().dcx().emit_err(SimdIntrinsicArgConst {
1993 span: term.source_info.span,
1994 arg: idx + 1,
1995 intrinsic: name.to_string(),
1996 });
1997 }
1998 }
1999 }
2000 debug!(?func_ty);
2001
2002 for (n, (fn_arg, op_arg)) in iter::zip(sig.inputs(), args).enumerate() {
2003 let op_arg_ty = op_arg.node.ty(self.body, self.tcx());
2004
2005 let op_arg_ty = self.normalize(op_arg_ty, term_location);
2006 let category = if call_source.from_hir_call() {
2007 ConstraintCategory::CallArgument(Some(
2008 self.infcx.tcx.erase_and_anonymize_regions(func_ty),
2009 ))
2010 } else {
2011 ConstraintCategory::Boring
2012 };
2013 if let Err(terr) =
2014 self.sub_types(op_arg_ty, *fn_arg, term_location.to_locations(), category)
2015 {
2016 span_mirbug!(
2017 self,
2018 term,
2019 "bad arg #{:?} ({:?} <- {:?}): {:?}",
2020 n,
2021 fn_arg,
2022 op_arg_ty,
2023 terr
2024 );
2025 }
2026 }
2027 }
2028
2029 fn check_iscleanup(&mut self, block_data: &BasicBlockData<'tcx>) {
2030 let is_cleanup = block_data.is_cleanup;
2031 match block_data.terminator().kind {
2032 TerminatorKind::Goto { target } => {
2033 self.assert_iscleanup(block_data, target, is_cleanup)
2034 }
2035 TerminatorKind::SwitchInt { ref targets, .. } => {
2036 for target in targets.all_targets() {
2037 self.assert_iscleanup(block_data, *target, is_cleanup);
2038 }
2039 }
2040 TerminatorKind::UnwindResume => {
2041 if !is_cleanup {
2042 {
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!")
2043 }
2044 }
2045 TerminatorKind::UnwindTerminate(_) => {
2046 if !is_cleanup {
2047 {
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!")
2048 }
2049 }
2050 TerminatorKind::Return => {
2051 if is_cleanup {
2052 {
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")
2053 }
2054 }
2055 TerminatorKind::TailCall { .. } => {
2056 if is_cleanup {
2057 {
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")
2058 }
2059 }
2060 TerminatorKind::CoroutineDrop { .. } => {
2061 if is_cleanup {
2062 {
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")
2063 }
2064 }
2065 TerminatorKind::Yield { resume, drop, .. } => {
2066 if is_cleanup {
2067 {
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")
2068 }
2069 self.assert_iscleanup(block_data, resume, is_cleanup);
2070 if let Some(drop) = drop {
2071 self.assert_iscleanup(block_data, drop, is_cleanup);
2072 }
2073 }
2074 TerminatorKind::Unreachable => {}
2075 TerminatorKind::Drop { target, unwind, drop, .. } => {
2076 self.assert_iscleanup(block_data, target, is_cleanup);
2077 self.assert_iscleanup_unwind(block_data, unwind, is_cleanup);
2078 if let Some(drop) = drop {
2079 self.assert_iscleanup(block_data, drop, is_cleanup);
2080 }
2081 }
2082 TerminatorKind::Assert { target, unwind, .. } => {
2083 self.assert_iscleanup(block_data, target, is_cleanup);
2084 self.assert_iscleanup_unwind(block_data, unwind, is_cleanup);
2085 }
2086 TerminatorKind::Call { ref target, unwind, .. } => {
2087 if let &Some(target) = target {
2088 self.assert_iscleanup(block_data, target, is_cleanup);
2089 }
2090 self.assert_iscleanup_unwind(block_data, unwind, is_cleanup);
2091 }
2092 TerminatorKind::FalseEdge { real_target, imaginary_target } => {
2093 self.assert_iscleanup(block_data, real_target, is_cleanup);
2094 self.assert_iscleanup(block_data, imaginary_target, is_cleanup);
2095 }
2096 TerminatorKind::FalseUnwind { real_target, unwind } => {
2097 self.assert_iscleanup(block_data, real_target, is_cleanup);
2098 self.assert_iscleanup_unwind(block_data, unwind, is_cleanup);
2099 }
2100 TerminatorKind::InlineAsm { ref targets, unwind, .. } => {
2101 for &target in targets {
2102 self.assert_iscleanup(block_data, target, is_cleanup);
2103 }
2104 self.assert_iscleanup_unwind(block_data, unwind, is_cleanup);
2105 }
2106 }
2107 }
2108
2109 fn assert_iscleanup(&mut self, ctxt: &dyn fmt::Debug, bb: BasicBlock, iscleanuppad: bool) {
2110 if self.body[bb].is_cleanup != iscleanuppad {
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(), ctxt,
format_args!("cleanuppad mismatch: {0:?} should be {1:?}",
bb, iscleanuppad)))
}))
};span_mirbug!(self, ctxt, "cleanuppad mismatch: {:?} should be {:?}", bb, iscleanuppad);
2112 }
2113 }
2114
2115 fn assert_iscleanup_unwind(
2116 &mut self,
2117 ctxt: &dyn fmt::Debug,
2118 unwind: UnwindAction,
2119 is_cleanup: bool,
2120 ) {
2121 match unwind {
2122 UnwindAction::Cleanup(unwind) => {
2123 if is_cleanup {
2124 {
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")
2125 }
2126 self.assert_iscleanup(ctxt, unwind, true);
2127 }
2128 UnwindAction::Continue => {
2129 if is_cleanup {
2130 {
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")
2131 }
2132 }
2133 UnwindAction::Unreachable | UnwindAction::Terminate(_) => (),
2134 }
2135 }
2136
2137 fn ensure_place_sized(&mut self, ty: Ty<'tcx>, span: Span) {
2138 let tcx = self.tcx();
2139
2140 let erased_ty = tcx.erase_and_anonymize_regions(ty);
2144 if !erased_ty.is_sized(tcx, self.infcx.typing_env(self.infcx.param_env)) {
2146 if self.reported_errors.replace((ty, span)).is_none() {
2151 self.tcx().dcx().emit_err(MoveUnsized { ty, span });
2155 }
2156 }
2157 }
2158
2159 fn aggregate_field_ty(
2160 &mut self,
2161 ak: &AggregateKind<'tcx>,
2162 field_index: FieldIdx,
2163 location: Location,
2164 ) -> Result<Ty<'tcx>, FieldAccessError> {
2165 let tcx = self.tcx();
2166
2167 match *ak {
2168 AggregateKind::Adt(adt_did, variant_index, args, _, active_field_index) => {
2169 let def = tcx.adt_def(adt_did);
2170 let variant = &def.variant(variant_index);
2171 let adj_field_index = active_field_index.unwrap_or(field_index);
2172 if let Some(field) = variant.fields.get(adj_field_index) {
2173 Ok(self.normalize(field.ty(tcx, args), location))
2174 } else {
2175 Err(FieldAccessError::OutOfRange { field_count: variant.fields.len() })
2176 }
2177 }
2178 AggregateKind::Closure(_, args) => {
2179 match args.as_closure().upvar_tys().get(field_index.as_usize()) {
2180 Some(ty) => Ok(*ty),
2181 None => Err(FieldAccessError::OutOfRange {
2182 field_count: args.as_closure().upvar_tys().len(),
2183 }),
2184 }
2185 }
2186 AggregateKind::Coroutine(_, args) => {
2187 match args.as_coroutine().prefix_tys().get(field_index.as_usize()) {
2191 Some(ty) => Ok(*ty),
2192 None => Err(FieldAccessError::OutOfRange {
2193 field_count: args.as_coroutine().prefix_tys().len(),
2194 }),
2195 }
2196 }
2197 AggregateKind::CoroutineClosure(_, args) => {
2198 match args.as_coroutine_closure().upvar_tys().get(field_index.as_usize()) {
2199 Some(ty) => Ok(*ty),
2200 None => Err(FieldAccessError::OutOfRange {
2201 field_count: args.as_coroutine_closure().upvar_tys().len(),
2202 }),
2203 }
2204 }
2205 AggregateKind::Array(ty) => Ok(ty),
2206 AggregateKind::Tuple | AggregateKind::RawPtr(..) => {
2207 {
::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");
2208 }
2209 }
2210 }
2211
2212 fn rvalue_user_ty(&self, rvalue: &Rvalue<'tcx>) -> Option<UserTypeAnnotationIndex> {
2216 match rvalue {
2217 Rvalue::Use(..)
2218 | Rvalue::ThreadLocalRef(..)
2219 | Rvalue::Repeat(..)
2220 | Rvalue::Ref(..)
2221 | Rvalue::RawPtr(..)
2222 | Rvalue::Cast(..)
2223 | Rvalue::BinaryOp(..)
2224 | Rvalue::CopyForDeref(..)
2225 | Rvalue::UnaryOp(..)
2226 | Rvalue::Discriminant(..)
2227 | Rvalue::WrapUnsafeBinder(..) => None,
2228
2229 Rvalue::Aggregate(aggregate, _) => match **aggregate {
2230 AggregateKind::Adt(_, _, _, user_ty, _) => user_ty,
2231 AggregateKind::Array(_) => None,
2232 AggregateKind::Tuple => None,
2233 AggregateKind::Closure(_, _) => None,
2234 AggregateKind::Coroutine(_, _) => None,
2235 AggregateKind::CoroutineClosure(_, _) => None,
2236 AggregateKind::RawPtr(_, _) => None,
2237 },
2238 }
2239 }
2240
2241 fn check_aggregate_rvalue(
2242 &mut self,
2243 rvalue: &Rvalue<'tcx>,
2244 aggregate_kind: &AggregateKind<'tcx>,
2245 operands: &IndexSlice<FieldIdx, Operand<'tcx>>,
2246 location: Location,
2247 ) {
2248 let tcx = self.tcx();
2249
2250 self.prove_aggregate_predicates(aggregate_kind, location);
2251
2252 if *aggregate_kind == AggregateKind::Tuple {
2253 return;
2255 }
2256
2257 if let AggregateKind::RawPtr(..) = aggregate_kind {
2258 ::rustc_middle::util::bug::bug_fmt(format_args!("RawPtr should only be in runtime MIR"));bug!("RawPtr should only be in runtime MIR");
2259 }
2260
2261 for (i, operand) in operands.iter_enumerated() {
2262 let field_ty = match self.aggregate_field_ty(aggregate_kind, i, location) {
2263 Ok(field_ty) => field_ty,
2264 Err(FieldAccessError::OutOfRange { field_count }) => {
2265 {
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!(
2266 self,
2267 rvalue,
2268 "accessed field #{} but variant only has {}",
2269 i.as_u32(),
2270 field_count,
2271 );
2272 continue;
2273 }
2274 };
2275 let operand_ty = operand.ty(self.body, tcx);
2276 let operand_ty = self.normalize(operand_ty, location);
2277
2278 if let Err(terr) = self.sub_types(
2279 operand_ty,
2280 field_ty,
2281 location.to_locations(),
2282 ConstraintCategory::Boring,
2283 ) {
2284 {
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!(
2285 self,
2286 rvalue,
2287 "{:?} is not a subtype of {:?}: {:?}",
2288 operand_ty,
2289 field_ty,
2290 terr
2291 );
2292 }
2293 }
2294 }
2295
2296 fn add_reborrow_constraint(
2304 &mut self,
2305 location: Location,
2306 borrow_region: ty::Region<'tcx>,
2307 borrowed_place: &Place<'tcx>,
2308 ) {
2309 let Self { borrow_set, location_table, polonius_facts, constraints, .. } = self;
2311
2312 if let Some(polonius_facts) = polonius_facts {
2318 let _prof_timer = self.infcx.tcx.prof.generic_activity("polonius_fact_generation");
2319 if let Some(borrow_index) = borrow_set.get_index_of(&location) {
2320 let region_vid = borrow_region.as_var();
2321 polonius_facts.loan_issued_at.push((
2322 region_vid.into(),
2323 borrow_index,
2324 location_table.mid_index(location),
2325 ));
2326 }
2327 }
2328
2329 {
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:2334",
"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(2334u32),
::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!(
2335 "add_reborrow_constraint({:?}, {:?}, {:?})",
2336 location, borrow_region, borrowed_place
2337 );
2338
2339 let tcx = self.infcx.tcx;
2340 let def = self.body.source.def_id().expect_local();
2341 let upvars = tcx.closure_captures(def);
2342 let field =
2343 path_utils::is_upvar_field_projection(tcx, upvars, borrowed_place.as_ref(), self.body);
2344 let category = if let Some(field) = field {
2345 ConstraintCategory::ClosureUpvar(field)
2346 } else {
2347 ConstraintCategory::Boring
2348 };
2349
2350 for (base, elem) in borrowed_place.as_ref().iter_projections().rev() {
2351 {
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:2351",
"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(2351u32),
::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);
2352
2353 match elem {
2354 ProjectionElem::Deref => {
2355 let base_ty = base.ty(self.body, tcx).ty;
2356
2357 {
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:2357",
"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(2357u32),
::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);
2358 match base_ty.kind() {
2359 ty::Ref(ref_region, _, mutbl) => {
2360 constraints.outlives_constraints.push(OutlivesConstraint {
2361 sup: ref_region.as_var(),
2362 sub: borrow_region.as_var(),
2363 locations: location.to_locations(),
2364 span: location.to_locations().span(self.body),
2365 category,
2366 variance_info: ty::VarianceDiagInfo::default(),
2367 from_closure: false,
2368 });
2369
2370 match mutbl {
2371 hir::Mutability::Not => {
2372 break;
2376 }
2377 hir::Mutability::Mut => {
2378 }
2400 }
2401 }
2402 ty::RawPtr(..) => {
2403 break;
2405 }
2406 ty::Adt(def, _) if def.is_box() => {
2407 }
2409 _ => ::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),
2410 }
2411 }
2412 ProjectionElem::Field(..)
2413 | ProjectionElem::Downcast(..)
2414 | ProjectionElem::OpaqueCast(..)
2415 | ProjectionElem::Index(..)
2416 | ProjectionElem::ConstantIndex { .. }
2417 | ProjectionElem::Subslice { .. }
2418 | ProjectionElem::UnwrapUnsafeBinder(_) => {
2419 }
2421 }
2422 }
2423 }
2424
2425 fn prove_aggregate_predicates(
2426 &mut self,
2427 aggregate_kind: &AggregateKind<'tcx>,
2428 location: Location,
2429 ) {
2430 let tcx = self.tcx();
2431
2432 {
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:2432",
"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(2432u32),
::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!(
2433 "prove_aggregate_predicates(aggregate_kind={:?}, location={:?})",
2434 aggregate_kind, location
2435 );
2436
2437 let (def_id, instantiated_predicates) = match *aggregate_kind {
2438 AggregateKind::Adt(adt_did, _, args, _, _) => {
2439 (adt_did, tcx.predicates_of(adt_did).instantiate(tcx, args))
2440 }
2441
2442 AggregateKind::Closure(def_id, args)
2462 | AggregateKind::CoroutineClosure(def_id, args)
2463 | AggregateKind::Coroutine(def_id, args) => {
2464 (def_id, self.prove_closure_bounds(tcx, def_id.expect_local(), args, location))
2465 }
2466
2467 AggregateKind::Array(_) | AggregateKind::Tuple | AggregateKind::RawPtr(..) => {
2468 (CRATE_DEF_ID.to_def_id(), ty::InstantiatedPredicates::empty())
2469 }
2470 };
2471
2472 self.normalize_and_prove_instantiated_predicates(
2473 def_id,
2474 instantiated_predicates,
2475 location.to_locations(),
2476 );
2477 }
2478
2479 fn prove_closure_bounds(
2480 &mut self,
2481 tcx: TyCtxt<'tcx>,
2482 def_id: LocalDefId,
2483 args: GenericArgsRef<'tcx>,
2484 location: Location,
2485 ) -> ty::InstantiatedPredicates<'tcx> {
2486 let root_def_id = self.root_cx.root_def_id();
2487 self.deferred_closure_requirements.push((def_id, args, location.to_locations()));
2490
2491 let typeck_root_args = ty::GenericArgs::identity_for_item(tcx, root_def_id);
2493
2494 let parent_args = match tcx.def_kind(def_id) {
2495 DefKind::Closure => {
2499 &args[..typeck_root_args.len()]
2503 }
2504 DefKind::InlineConst => args.as_inline_const().parent_args(),
2505 other => ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected item {0:?}",
other))bug!("unexpected item {:?}", other),
2506 };
2507 let parent_args = tcx.mk_args(parent_args);
2508
2509 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());
2510 if let Err(_) = self.eq_args(
2511 typeck_root_args,
2512 parent_args,
2513 location.to_locations(),
2514 ConstraintCategory::BoringNoLocation,
2515 ) {
2516 {
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!(
2517 self,
2518 def_id,
2519 "could not relate closure to parent {:?} != {:?}",
2520 typeck_root_args,
2521 parent_args
2522 );
2523 }
2524
2525 tcx.predicates_of(def_id).instantiate(tcx, args)
2526 }
2527}
2528
2529trait NormalizeLocation: fmt::Debug + Copy {
2530 fn to_locations(self) -> Locations;
2531}
2532
2533impl NormalizeLocation for Locations {
2534 fn to_locations(self) -> Locations {
2535 self
2536 }
2537}
2538
2539impl NormalizeLocation for Location {
2540 fn to_locations(self) -> Locations {
2541 Locations::Single(self)
2542 }
2543}
2544
2545#[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)]
2549pub(super) struct InstantiateOpaqueType<'tcx> {
2550 pub base_universe: Option<ty::UniverseIndex>,
2551 pub region_constraints: Option<RegionConstraintData<'tcx>>,
2552 pub obligations: PredicateObligations<'tcx>,
2553}
2554
2555impl<'tcx> TypeOp<'tcx> for InstantiateOpaqueType<'tcx> {
2556 type Output = ();
2557 type ErrorInfo = InstantiateOpaqueType<'tcx>;
2563
2564 fn fully_perform(
2565 mut self,
2566 infcx: &InferCtxt<'tcx>,
2567 root_def_id: LocalDefId,
2568 span: Span,
2569 ) -> Result<TypeOpOutput<'tcx, Self>, ErrorGuaranteed> {
2570 let (mut output, region_constraints) =
2571 scrape_region_constraints(infcx, root_def_id, "InstantiateOpaqueType", span, |ocx| {
2572 ocx.register_obligations(self.obligations.clone());
2573 Ok(())
2574 })?;
2575 self.region_constraints = Some(region_constraints);
2576 output.error_info = Some(self);
2577 Ok(output)
2578 }
2579}