1//! Code that handles "type-outlives" constraints like `T: 'a`. This
2//! is based on the `push_outlives_components` function defined in rustc_infer,
3//! but it adds a bit of heuristics on top, in particular to deal with
4//! associated types and projections.
5//!
6//! When we process a given `T: 'a` obligation, we may produce two
7//! kinds of constraints for the region inferencer:
8//!
9//! - Relationships between inference variables and other regions.
10//! For example, if we have `&'?0 u32: 'a`, then we would produce
11//! a constraint that `'a <= '?0`.
12//! - "Verifys" that must be checked after inferencing is done.
13//! For example, if we know that, for some type parameter `T`,
14//! `T: 'a + 'b`, and we have a requirement that `T: '?1`,
15//! then we add a "verify" that checks that `'?1 <= 'a || '?1 <= 'b`.
16//! - Note the difference with the previous case: here, the region
17//! variable must be less than something else, so this doesn't
18//! affect how inference works (it finds the smallest region that
19//! will do); it's just a post-condition that we have to check.
20//!
21//! **The key point is that once this function is done, we have
22//! reduced all of our "type-region outlives" obligations into relationships
23//! between individual regions.**
24//!
25//! One key input to this function is the set of "region-bound pairs".
26//! These are basically the relationships between type parameters and
27//! regions that are in scope at the point where the outlives
28//! obligation was incurred. **When type-checking a function,
29//! particularly in the face of closures, this is not known until
30//! regionck runs!** This is because some of those bounds come
31//! from things we have yet to infer.
32//!
33//! Consider:
34//!
35//! ```
36//! fn bar<T>(a: T, b: impl for<'a> Fn(&'a T)) {}
37//! fn foo<T>(x: T) {
38//! bar(x, |y| { /* ... */})
39//! // ^ closure arg
40//! }
41//! ```
42//!
43//! Here, the type of `y` may involve inference variables and the
44//! like, and it may also contain implied bounds that are needed to
45//! type-check the closure body (e.g., here it informs us that `T`
46//! outlives the late-bound region `'a`).
47//!
48//! Note that by delaying the gathering of implied bounds until all
49//! inference information is known, we may find relationships between
50//! bound regions and other regions in the environment. For example,
51//! when we first check a closure like the one expected as argument
52//! to `foo`:
53//!
54//! ```
55//! fn foo<U, F: for<'a> FnMut(&'a U)>(_f: F) {}
56//! ```
57//!
58//! the type of the closure's first argument would be `&'a ?U`. We
59//! might later infer `?U` to something like `&'b u32`, which would
60//! imply that `'b: 'a`.
6162use rustc_data_structures::undo_log::UndoLogs;
63use rustc_middle::bug;
64use rustc_middle::mir::ConstraintCategory;
65use rustc_middle::traits::query::NoSolution;
66use rustc_middle::ty::outlives::{Component, push_outlives_components};
67use rustc_middle::ty::{
68self, GenericArgKind, GenericArgsRef, PolyTypeOutlivesPredicate, Region, Ty, TyCtxt,
69TypeFoldableas _, TypeVisitableExt,
70};
71use smallvec::smallvec;
72use tracing::{debug, instrument};
7374use super::env::OutlivesEnvironment;
75use crate::infer::outlives::env::RegionBoundPairs;
76use crate::infer::outlives::verify::VerifyBoundCx;
77use crate::infer::resolve::OpportunisticRegionResolver;
78use crate::infer::snapshot::undo_log::UndoLog;
79use crate::infer::{
80self, GenericKind, InferCtxt, SubregionOrigin, TypeOutlivesConstraint, VerifyBound,
81};
82use crate::traits::{ObligationCause, ObligationCauseCode};
8384impl<'tcx> InferCtxt<'tcx> {
85pub fn register_outlives_constraint(
86&self,
87 ty::OutlivesPredicate(arg, r2): ty::ArgOutlivesPredicate<'tcx>,
88 vis: ty::VisibleForLeakCheck,
89 cause: &ObligationCause<'tcx>,
90 ) {
91match arg.kind() {
92 ty::GenericArgKind::Lifetime(r1) => {
93self.register_region_outlives_constraint(ty::OutlivesPredicate(r1, r2), vis, cause);
94 }
95 ty::GenericArgKind::Type(ty1) => {
96self.register_type_outlives_constraint(ty1, r2, cause);
97 }
98 ty::GenericArgKind::Const(_) => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
99 }
100 }
101102pub fn register_region_eq_constraint(
103&self,
104 ty::RegionEqPredicate(r_a, r_b): ty::RegionEqPredicate<'tcx>,
105 vis: ty::VisibleForLeakCheck,
106 cause: &ObligationCause<'tcx>,
107 ) {
108let origin = SubregionOrigin::from_obligation_cause(cause, || {
109 SubregionOrigin::RelateRegionParamBound(cause.span, None)
110 });
111self.equate_regions(origin, r_a, r_b, vis);
112 }
113114pub fn register_region_outlives_constraint(
115&self,
116 ty::OutlivesPredicate(r_a, r_b): ty::RegionOutlivesPredicate<'tcx>,
117 vis: ty::VisibleForLeakCheck,
118 cause: &ObligationCause<'tcx>,
119 ) {
120let origin = SubregionOrigin::from_obligation_cause(cause, || {
121 SubregionOrigin::RelateRegionParamBound(cause.span, None)
122 });
123// `'a: 'b` ==> `'b <= 'a`
124self.sub_regions(origin, r_b, r_a, vis);
125 }
126127/// Registers that the given region obligation must be resolved
128 /// from within the scope of `body_id`. These regions are enqueued
129 /// and later processed by regionck, when full type information is
130 /// available (see `region_obligations` field for more
131 /// information).
132#[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("register_type_outlives_constraint_inner",
"rustc_infer::infer::outlives::obligations",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
::tracing_core::__macro_support::Option::Some(132u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
::tracing_core::field::FieldSet::new(&["obligation"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&obligation)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let mut inner = self.inner.borrow_mut();
inner.undo_log.push(UndoLog::PushTypeOutlivesConstraint);
inner.region_obligations.push(obligation);
}
}
}#[instrument(level = "debug", skip(self))]133pub fn register_type_outlives_constraint_inner(
134&self,
135 obligation: TypeOutlivesConstraint<'tcx>,
136 ) {
137let mut inner = self.inner.borrow_mut();
138 inner.undo_log.push(UndoLog::PushTypeOutlivesConstraint);
139 inner.region_obligations.push(obligation);
140 }
141142pub fn register_type_outlives_constraint(
143&self,
144 sup_type: Ty<'tcx>,
145 sub_region: Region<'tcx>,
146 cause: &ObligationCause<'tcx>,
147 ) {
148// `is_global` means the type has no params, infer, placeholder, or non-`'static`
149 // free regions. If the type has none of these things, then we can skip registering
150 // this outlives obligation since it has no components which affect lifetime
151 // checking in an interesting way.
152if sup_type.is_global() {
153return;
154 }
155156{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/outlives/obligations.rs:156",
"rustc_infer::infer::outlives::obligations",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
::tracing_core::__macro_support::Option::Some(156u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
::tracing_core::field::FieldSet::new(&["sup_type",
"sub_region", "cause"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&sup_type)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&sub_region)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&cause) as
&dyn Value))])
});
} else { ; }
};debug!(?sup_type, ?sub_region, ?cause);
157let origin = SubregionOrigin::from_obligation_cause(cause, || {
158 SubregionOrigin::RelateParamBound(
159cause.span,
160sup_type,
161match cause.code().peel_derives() {
162 ObligationCauseCode::WhereClause(_, span)
163 | ObligationCauseCode::WhereClauseInExpr(_, span, ..)
164 | ObligationCauseCode::OpaqueTypeBound(span, _)
165if !span.is_dummy() =>
166 {
167Some(*span)
168 }
169_ => None,
170 },
171 )
172 });
173174self.register_type_outlives_constraint_inner(TypeOutlivesConstraint {
175sup_type,
176sub_region,
177origin,
178 });
179 }
180181/// Trait queries just want to pass back type obligations "as is"
182pub fn take_registered_region_obligations(&self) -> Vec<TypeOutlivesConstraint<'tcx>> {
183if !!self.in_snapshot() {
{
::core::panicking::panic_fmt(format_args!("cannot take registered region obligations in a snapshot"));
}
};assert!(!self.in_snapshot(), "cannot take registered region obligations in a snapshot");
184 std::mem::take(&mut self.inner.borrow_mut().region_obligations)
185 }
186187pub fn clone_registered_region_obligations(&self) -> Vec<TypeOutlivesConstraint<'tcx>> {
188self.inner.borrow().region_obligations.clone()
189 }
190191pub fn register_region_assumption(&self, assumption: ty::ArgOutlivesPredicate<'tcx>) {
192let mut inner = self.inner.borrow_mut();
193inner.undo_log.push(UndoLog::PushRegionAssumption);
194inner.region_assumptions.push(assumption);
195 }
196197pub fn take_registered_region_assumptions(&self) -> Vec<ty::ArgOutlivesPredicate<'tcx>> {
198if !!self.in_snapshot() {
{
::core::panicking::panic_fmt(format_args!("cannot take registered region assumptions in a snapshot"));
}
};assert!(!self.in_snapshot(), "cannot take registered region assumptions in a snapshot");
199 std::mem::take(&mut self.inner.borrow_mut().region_assumptions)
200 }
201202/// Process the region obligations that must be proven (during
203 /// `regionck`) for the given `body_id`, given information about
204 /// the region bounds in scope and so forth.
205 ///
206 /// See the `region_obligations` field of `InferCtxt` for some
207 /// comments about how this function fits into the overall expected
208 /// flow of the inferencer. The key point is that it is
209 /// invoked after all type-inference variables have been bound --
210 /// right before lexical region resolution.
211#[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("process_registered_region_obligations",
"rustc_infer::infer::outlives::obligations",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
::tracing_core::__macro_support::Option::Some(211u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
::tracing_core::field::FieldSet::new(&[],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{ meta.fields().value_set(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
Result<(),
(PolyTypeOutlivesPredicate<'tcx>, SubregionOrigin<'tcx>)> =
loop {};
return __tracing_attr_fake_return;
}
{
if !!self.in_snapshot() {
{
::core::panicking::panic_fmt(format_args!("cannot process registered region obligations in a snapshot"));
}
};
for iteration in 0.. {
let my_region_obligations =
self.take_registered_region_obligations();
if my_region_obligations.is_empty() { break; }
if !self.tcx.recursion_limit().value_within_limit(iteration) {
::rustc_middle::util::bug::bug_fmt(format_args!("unexpected overflowed when processing region obligations: {0:#?}",
my_region_obligations));
}
for TypeOutlivesConstraint { sup_type, sub_region, origin } in
my_region_obligations {
let outlives =
ty::Binder::dummy(ty::OutlivesPredicate(sup_type,
sub_region));
let ty::OutlivesPredicate(sup_type, sub_region) =
deeply_normalize_ty(outlives,
origin.clone()).map_err(|NoSolution|
(outlives,
origin.clone()))?.no_bound_vars().expect("started with no bound vars, should end with no bound vars");
let (sup_type, sub_region) =
(sup_type,
sub_region).fold_with(&mut OpportunisticRegionResolver::new(self));
if self.tcx.sess.opts.unstable_opts.higher_ranked_assumptions
&&
outlives_env.higher_ranked_assumptions().contains(&ty::OutlivesPredicate(sup_type.into(),
sub_region)) {
continue;
}
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/outlives/obligations.rs:260",
"rustc_infer::infer::outlives::obligations",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
::tracing_core::__macro_support::Option::Some(260u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
::tracing_core::field::FieldSet::new(&["sup_type",
"sub_region", "origin"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&sup_type)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&sub_region)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&origin) as
&dyn Value))])
});
} else { ; }
};
let outlives =
&mut TypeOutlives::new(self, self.tcx,
outlives_env.region_bound_pairs(), None,
outlives_env.known_type_outlives());
let category = origin.to_constraint_category();
outlives.type_must_outlive(origin, sup_type, sub_region,
category);
}
}
Ok(())
}
}
}#[instrument(level = "debug", skip(self, outlives_env, deeply_normalize_ty))]212pub fn process_registered_region_obligations(
213&self,
214 outlives_env: &OutlivesEnvironment<'tcx>,
215mut deeply_normalize_ty: impl FnMut(
216PolyTypeOutlivesPredicate<'tcx>,
217SubregionOrigin<'tcx>,
218 )
219 -> Result<PolyTypeOutlivesPredicate<'tcx>, NoSolution>,
220 ) -> Result<(), (PolyTypeOutlivesPredicate<'tcx>, SubregionOrigin<'tcx>)> {
221assert!(!self.in_snapshot(), "cannot process registered region obligations in a snapshot");
222223// Must loop since the process of normalizing may itself register region obligations.
224for iteration in 0.. {
225let my_region_obligations = self.take_registered_region_obligations();
226if my_region_obligations.is_empty() {
227break;
228 }
229230if !self.tcx.recursion_limit().value_within_limit(iteration) {
231// This may actually be reachable. If so, we should convert
232 // this to a proper error/consider whether we should detect
233 // this somewhere else.
234bug!(
235"unexpected overflowed when processing region obligations: {my_region_obligations:#?}"
236);
237 }
238239for TypeOutlivesConstraint { sup_type, sub_region, origin } in my_region_obligations {
240let outlives = ty::Binder::dummy(ty::OutlivesPredicate(sup_type, sub_region));
241let ty::OutlivesPredicate(sup_type, sub_region) =
242 deeply_normalize_ty(outlives, origin.clone())
243 .map_err(|NoSolution| (outlives, origin.clone()))?
244.no_bound_vars()
245 .expect("started with no bound vars, should end with no bound vars");
246// `TypeOutlives` is structural, so we should try to opportunistically resolve all
247 // region vids before processing regions, so we have a better chance to match clauses
248 // in our param-env.
249let (sup_type, sub_region) =
250 (sup_type, sub_region).fold_with(&mut OpportunisticRegionResolver::new(self));
251252if self.tcx.sess.opts.unstable_opts.higher_ranked_assumptions
253 && outlives_env
254 .higher_ranked_assumptions()
255 .contains(&ty::OutlivesPredicate(sup_type.into(), sub_region))
256 {
257continue;
258 }
259260debug!(?sup_type, ?sub_region, ?origin);
261262let outlives = &mut TypeOutlives::new(
263self,
264self.tcx,
265 outlives_env.region_bound_pairs(),
266None,
267 outlives_env.known_type_outlives(),
268 );
269let category = origin.to_constraint_category();
270 outlives.type_must_outlive(origin, sup_type, sub_region, category);
271 }
272 }
273274Ok(())
275 }
276}
277278/// The `TypeOutlives` struct has the job of "lowering" a `T: 'a`
279/// obligation into a series of `'a: 'b` constraints and "verify"s, as
280/// described on the module comment. The final constraints are emitted
281/// via a "delegate" of type `D` -- this is usually the `infcx`, which
282/// accrues them into the `region_obligations` code, but for NLL we
283/// use something else.
284pub struct TypeOutlives<'cx, 'tcx, D>
285where
286D: TypeOutlivesDelegate<'tcx>,
287{
288// See the comments on `process_registered_region_obligations` for the meaning
289 // of these fields.
290delegate: D,
291 tcx: TyCtxt<'tcx>,
292 verify_bound: VerifyBoundCx<'cx, 'tcx>,
293}
294295pub trait TypeOutlivesDelegate<'tcx> {
296fn push_sub_region_constraint(
297&mut self,
298 origin: SubregionOrigin<'tcx>,
299 a: ty::Region<'tcx>,
300 b: ty::Region<'tcx>,
301 constraint_category: ConstraintCategory<'tcx>,
302 );
303304fn push_verify(
305&mut self,
306 origin: SubregionOrigin<'tcx>,
307 kind: GenericKind<'tcx>,
308 a: ty::Region<'tcx>,
309 bound: VerifyBound<'tcx>,
310 );
311}
312313impl<'cx, 'tcx, D> TypeOutlives<'cx, 'tcx, D>
314where
315D: TypeOutlivesDelegate<'tcx>,
316{
317pub fn new(
318 delegate: D,
319 tcx: TyCtxt<'tcx>,
320 region_bound_pairs: &'cx RegionBoundPairs<'tcx>,
321 implicit_region_bound: Option<ty::Region<'tcx>>,
322 caller_bounds: &'cx [ty::PolyTypeOutlivesPredicate<'tcx>],
323 ) -> Self {
324Self {
325delegate,
326tcx,
327 verify_bound: VerifyBoundCx::new(
328tcx,
329region_bound_pairs,
330implicit_region_bound,
331caller_bounds,
332 ),
333 }
334 }
335336/// Adds constraints to inference such that `T: 'a` holds (or
337 /// reports an error if it cannot).
338 ///
339 /// # Parameters
340 ///
341 /// - `origin`, the reason we need this constraint
342 /// - `ty`, the type `T`
343 /// - `region`, the region `'a`
344#[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("type_must_outlive",
"rustc_infer::infer::outlives::obligations",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
::tracing_core::__macro_support::Option::Some(344u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
::tracing_core::field::FieldSet::new(&["origin", "ty",
"region", "category"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&origin)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ty)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(®ion)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&category)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
if !!ty.has_escaping_bound_vars() {
::core::panicking::panic("assertion failed: !ty.has_escaping_bound_vars()")
};
let mut components = ::smallvec::SmallVec::new();
push_outlives_components(self.tcx, ty, &mut components);
self.components_must_outlive(origin, &components, region,
category);
}
}
}#[instrument(level = "debug", skip(self))]345pub fn type_must_outlive(
346&mut self,
347 origin: infer::SubregionOrigin<'tcx>,
348 ty: Ty<'tcx>,
349 region: ty::Region<'tcx>,
350 category: ConstraintCategory<'tcx>,
351 ) {
352assert!(!ty.has_escaping_bound_vars());
353354let mut components = smallvec![];
355 push_outlives_components(self.tcx, ty, &mut components);
356self.components_must_outlive(origin, &components, region, category);
357 }
358359fn components_must_outlive(
360&mut self,
361 origin: infer::SubregionOrigin<'tcx>,
362 components: &[Component<TyCtxt<'tcx>>],
363 region: ty::Region<'tcx>,
364 category: ConstraintCategory<'tcx>,
365 ) {
366for component in components.iter() {
367let origin = origin.clone();
368match component {
369 Component::Region(region1) => {
370self.delegate.push_sub_region_constraint(origin, region, *region1, category);
371 }
372 Component::Param(param_ty) => {
373self.param_ty_must_outlive(origin, region, *param_ty);
374 }
375 Component::Placeholder(placeholder_ty) => {
376self.placeholder_ty_must_outlive(origin, region, *placeholder_ty);
377 }
378 Component::Alias(alias_ty) => self.alias_ty_must_outlive(origin, region, *alias_ty),
379 Component::EscapingAlias(subcomponents) => {
380self.components_must_outlive(origin, subcomponents, region, category);
381 }
382 Component::UnresolvedInferenceVariable(v) => {
383// Ignore this, we presume it will yield an error later,
384 // since if a type variable is not resolved by this point
385 // it never will be.
386self.tcx.dcx().span_delayed_bug(
387 origin.span(),
388::alloc::__export::must_use({
::alloc::fmt::format(format_args!("unresolved inference variable in outlives: {0:?}",
v))
})format!("unresolved inference variable in outlives: {v:?}"),
389 );
390 }
391 }
392 }
393 }
394395#[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("param_ty_must_outlive",
"rustc_infer::infer::outlives::obligations",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
::tracing_core::__macro_support::Option::Some(395u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
::tracing_core::field::FieldSet::new(&["origin", "region",
"param_ty"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&origin)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(®ion)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(¶m_ty)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let verify_bound =
self.verify_bound.param_or_placeholder_bound(param_ty.to_ty(self.tcx));
self.delegate.push_verify(origin, GenericKind::Param(param_ty),
region, verify_bound);
}
}
}#[instrument(level = "debug", skip(self))]396fn param_ty_must_outlive(
397&mut self,
398 origin: infer::SubregionOrigin<'tcx>,
399 region: ty::Region<'tcx>,
400 param_ty: ty::ParamTy,
401 ) {
402let verify_bound = self.verify_bound.param_or_placeholder_bound(param_ty.to_ty(self.tcx));
403self.delegate.push_verify(origin, GenericKind::Param(param_ty), region, verify_bound);
404 }
405406#[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("placeholder_ty_must_outlive",
"rustc_infer::infer::outlives::obligations",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
::tracing_core::__macro_support::Option::Some(406u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
::tracing_core::field::FieldSet::new(&["origin", "region",
"placeholder_ty"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&origin)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(®ion)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&placeholder_ty)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let verify_bound =
self.verify_bound.param_or_placeholder_bound(Ty::new_placeholder(self.tcx,
placeholder_ty));
self.delegate.push_verify(origin,
GenericKind::Placeholder(placeholder_ty), region,
verify_bound);
}
}
}#[instrument(level = "debug", skip(self))]407fn placeholder_ty_must_outlive(
408&mut self,
409 origin: infer::SubregionOrigin<'tcx>,
410 region: ty::Region<'tcx>,
411 placeholder_ty: ty::PlaceholderType<'tcx>,
412 ) {
413let verify_bound = self
414.verify_bound
415 .param_or_placeholder_bound(Ty::new_placeholder(self.tcx, placeholder_ty));
416self.delegate.push_verify(
417 origin,
418 GenericKind::Placeholder(placeholder_ty),
419 region,
420 verify_bound,
421 );
422 }
423424#[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("alias_ty_must_outlive",
"rustc_infer::infer::outlives::obligations",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
::tracing_core::__macro_support::Option::Some(424u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
::tracing_core::field::FieldSet::new(&["origin", "region",
"alias_ty"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&origin)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(®ion)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&alias_ty)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
if alias_ty.args.is_empty() { return; }
if alias_ty.has_non_region_infer() {
self.tcx.dcx().span_delayed_bug(origin.span(),
"an alias has infers during region solving");
return;
}
let trait_bounds: Vec<_> =
self.verify_bound.declared_bounds_from_definition(alias_ty).collect();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/outlives/obligations.rs:463",
"rustc_infer::infer::outlives::obligations",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
::tracing_core::__macro_support::Option::Some(463u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
::tracing_core::field::FieldSet::new(&["trait_bounds"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&trait_bounds)
as &dyn Value))])
});
} else { ; }
};
let approx_env_bounds =
self.verify_bound.approx_declared_bounds_from_env(alias_ty);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/outlives/obligations.rs:469",
"rustc_infer::infer::outlives::obligations",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
::tracing_core::__macro_support::Option::Some(469u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
::tracing_core::field::FieldSet::new(&["approx_env_bounds"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&approx_env_bounds)
as &dyn Value))])
});
} else { ; }
};
let kind = alias_ty.kind;
if approx_env_bounds.is_empty() && trait_bounds.is_empty() &&
(alias_ty.has_infer_regions() ||
#[allow(non_exhaustive_omitted_patterns)] match kind {
ty::Opaque { .. } => true,
_ => false,
}) {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/outlives/obligations.rs:490",
"rustc_infer::infer::outlives::obligations",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
::tracing_core::__macro_support::Option::Some(490u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("no declared bounds")
as &dyn Value))])
});
} else { ; }
};
let opt_variances = self.tcx.opt_alias_variances(kind);
self.args_must_outlive(alias_ty.args, origin, region,
opt_variances);
return;
}
if !trait_bounds.is_empty() &&
trait_bounds[1..].iter().map(|r|
Some(*r)).chain(approx_env_bounds.iter().map(|b|
b.map_bound(|b|
b.1).no_bound_vars())).all(|b| b == Some(trait_bounds[0])) {
let unique_bound = trait_bounds[0];
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/outlives/obligations.rs:521",
"rustc_infer::infer::outlives::obligations",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
::tracing_core::__macro_support::Option::Some(521u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
::tracing_core::field::FieldSet::new(&["unique_bound"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&unique_bound)
as &dyn Value))])
});
} else { ; }
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/outlives/obligations.rs:522",
"rustc_infer::infer::outlives::obligations",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
::tracing_core::__macro_support::Option::Some(522u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("unique declared bound appears in trait ref")
as &dyn Value))])
});
} else { ; }
};
let category = origin.to_constraint_category();
self.delegate.push_sub_region_constraint(origin, region,
unique_bound, category);
return;
}
let verify_bound = self.verify_bound.alias_bound(alias_ty);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_infer/src/infer/outlives/obligations.rs:534",
"rustc_infer::infer::outlives::obligations",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
::tracing_core::__macro_support::Option::Some(534u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("alias_must_outlive: pushing {0:?}",
verify_bound) as &dyn Value))])
});
} else { ; }
};
self.delegate.push_verify(origin, GenericKind::Alias(alias_ty),
region, verify_bound);
}
}
}#[instrument(level = "debug", skip(self))]425fn alias_ty_must_outlive(
426&mut self,
427 origin: infer::SubregionOrigin<'tcx>,
428 region: ty::Region<'tcx>,
429 alias_ty: ty::AliasTy<'tcx>,
430 ) {
431// An optimization for a common case with opaque types.
432if alias_ty.args.is_empty() {
433return;
434 }
435436if alias_ty.has_non_region_infer() {
437self.tcx
438 .dcx()
439 .span_delayed_bug(origin.span(), "an alias has infers during region solving");
440return;
441 }
442443// This case is thorny for inference. The fundamental problem is
444 // that there are many cases where we have choice, and inference
445 // doesn't like choice (the current region inference in
446 // particular). :) First off, we have to choose between using the
447 // OutlivesProjectionEnv, OutlivesProjectionTraitDef, and
448 // OutlivesProjectionComponent rules, any one of which is
449 // sufficient. If there are no inference variables involved, it's
450 // not hard to pick the right rule, but if there are, we're in a
451 // bit of a catch 22: if we picked which rule we were going to
452 // use, we could add constraints to the region inference graph
453 // that make it apply, but if we don't add those constraints, the
454 // rule might not apply (but another rule might). For now, we err
455 // on the side of adding too few edges into the graph.
456457 // Compute the bounds we can derive from the trait definition.
458 // These are guaranteed to apply, no matter the inference
459 // results.
460let trait_bounds: Vec<_> =
461self.verify_bound.declared_bounds_from_definition(alias_ty).collect();
462463debug!(?trait_bounds);
464465// Compute the bounds we can derive from the environment. This
466 // is an "approximate" match -- in some cases, these bounds
467 // may not apply.
468let approx_env_bounds = self.verify_bound.approx_declared_bounds_from_env(alias_ty);
469debug!(?approx_env_bounds);
470471// If declared bounds list is empty, the only applicable rule is
472 // OutlivesProjectionComponent. If there are inference variables,
473 // then, we can break down the outlives into more primitive
474 // components without adding unnecessary edges.
475 //
476 // If there are *no* inference variables, however, we COULD do
477 // this, but we choose not to, because the error messages are less
478 // good. For example, a requirement like `T::Item: 'r` would be
479 // translated to a requirement that `T: 'r`; when this is reported
480 // to the user, it will thus say "T: 'r must hold so that T::Item:
481 // 'r holds". But that makes it sound like the only way to fix
482 // the problem is to add `T: 'r`, which isn't true. So, if there are no
483 // inference variables, we use a verify constraint instead of adding
484 // edges, which winds up enforcing the same condition.
485let kind = alias_ty.kind;
486if approx_env_bounds.is_empty()
487 && trait_bounds.is_empty()
488 && (alias_ty.has_infer_regions() || matches!(kind, ty::Opaque { .. }))
489 {
490debug!("no declared bounds");
491let opt_variances = self.tcx.opt_alias_variances(kind);
492self.args_must_outlive(alias_ty.args, origin, region, opt_variances);
493return;
494 }
495496// If we found a unique bound `'b` from the trait, and we
497 // found nothing else from the environment, then the best
498 // action is to require that `'b: 'r`, so do that.
499 //
500 // This is best no matter what rule we use:
501 //
502 // - OutlivesProjectionEnv: these would translate to the requirement that `'b:'r`
503 // - OutlivesProjectionTraitDef: these would translate to the requirement that `'b:'r`
504 // - OutlivesProjectionComponent: this would require `'b:'r`
505 // in addition to other conditions
506if !trait_bounds.is_empty()
507 && trait_bounds[1..]
508 .iter()
509 .map(|r| Some(*r))
510 .chain(
511// NB: The environment may contain `for<'a> T: 'a` style bounds.
512 // In that case, we don't know if they are equal to the trait bound
513 // or not (since we don't *know* whether the environment bound even applies),
514 // so just map to `None` here if there are bound vars, ensuring that
515 // the call to `all` will fail below.
516approx_env_bounds.iter().map(|b| b.map_bound(|b| b.1).no_bound_vars()),
517 )
518 .all(|b| b == Some(trait_bounds[0]))
519 {
520let unique_bound = trait_bounds[0];
521debug!(?unique_bound);
522debug!("unique declared bound appears in trait ref");
523let category = origin.to_constraint_category();
524self.delegate.push_sub_region_constraint(origin, region, unique_bound, category);
525return;
526 }
527528// Fallback to verifying after the fact that there exists a
529 // declared bound, or that all the components appearing in the
530 // projection outlive; in some cases, this may add insufficient
531 // edges into the inference graph, leading to inference failures
532 // even though a satisfactory solution exists.
533let verify_bound = self.verify_bound.alias_bound(alias_ty);
534debug!("alias_must_outlive: pushing {:?}", verify_bound);
535self.delegate.push_verify(origin, GenericKind::Alias(alias_ty), region, verify_bound);
536 }
537538#[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("args_must_outlive",
"rustc_infer::infer::outlives::obligations",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/obligations.rs"),
::tracing_core::__macro_support::Option::Some(538u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::obligations"),
::tracing_core::field::FieldSet::new(&["args", "origin",
"region", "opt_variances"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&origin)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(®ion)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&opt_variances)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let constraint = origin.to_constraint_category();
for (index, arg) in args.iter().enumerate() {
match arg.kind() {
GenericArgKind::Lifetime(lt) => {
let variance =
if let Some(variances) = opt_variances {
variances[index]
} else { ty::Invariant };
if variance == ty::Invariant {
self.delegate.push_sub_region_constraint(origin.clone(),
region, lt, constraint);
}
}
GenericArgKind::Type(ty) => {
self.type_must_outlive(origin.clone(), ty, region,
constraint);
}
GenericArgKind::Const(_) => {}
}
}
}
}
}#[instrument(level = "debug", skip(self))]539fn args_must_outlive(
540&mut self,
541 args: GenericArgsRef<'tcx>,
542 origin: infer::SubregionOrigin<'tcx>,
543 region: ty::Region<'tcx>,
544 opt_variances: Option<&[ty::Variance]>,
545 ) {
546let constraint = origin.to_constraint_category();
547for (index, arg) in args.iter().enumerate() {
548match arg.kind() {
549 GenericArgKind::Lifetime(lt) => {
550let variance = if let Some(variances) = opt_variances {
551 variances[index]
552 } else {
553 ty::Invariant
554 };
555if variance == ty::Invariant {
556self.delegate.push_sub_region_constraint(
557 origin.clone(),
558 region,
559 lt,
560 constraint,
561 );
562 }
563 }
564 GenericArgKind::Type(ty) => {
565self.type_must_outlive(origin.clone(), ty, region, constraint);
566 }
567 GenericArgKind::Const(_) => {
568// Const parameters don't impose constraints.
569}
570 }
571 }
572 }
573}
574575impl<'cx, 'tcx> TypeOutlivesDelegate<'tcx> for &'cx InferCtxt<'tcx> {
576fn push_sub_region_constraint(
577&mut self,
578 origin: SubregionOrigin<'tcx>,
579 a: ty::Region<'tcx>,
580 b: ty::Region<'tcx>,
581 _constraint_category: ConstraintCategory<'tcx>,
582 ) {
583// We don't do leak check in lexical region resolution
584self.sub_regions(origin, a, b, ty::VisibleForLeakCheck::Unreachable)
585 }
586587fn push_verify(
588&mut self,
589 origin: SubregionOrigin<'tcx>,
590 kind: GenericKind<'tcx>,
591 a: ty::Region<'tcx>,
592 bound: VerifyBound<'tcx>,
593 ) {
594self.verify_generic_bound(origin, kind, a, bound)
595 }
596}