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