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