1use std::assert_matches;
23use rustc_middle::ty::outlives::{Component, compute_alias_components_recursive};
4use rustc_middle::ty::{self, OutlivesPredicate, Ty, TyCtxt};
5use smallvec::smallvec;
6use tracing::{debug, instrument};
78use crate::infer::outlives::env::RegionBoundPairs;
9use crate::infer::region_constraints::VerifyIfEq;
10use crate::infer::{GenericKind, VerifyBound};
1112/// The `TypeOutlives` struct has the job of "lowering" a `T: 'a`
13/// obligation into a series of `'a: 'b` constraints and "verifys", as
14/// described on the module comment. The final constraints are emitted
15/// via a "delegate" of type `D` -- this is usually the `infcx`, which
16/// accrues them into the `region_obligations` code, but for NLL we
17/// use something else.
18pub(crate) struct VerifyBoundCx<'cx, 'tcx> {
19 tcx: TyCtxt<'tcx>,
20 region_bound_pairs: &'cx RegionBoundPairs<'tcx>,
21/// During borrowck, if there are no outlives bounds on a generic
22 /// parameter `T`, we assume that `T: 'in_fn_body` holds.
23 ///
24 /// Outside of borrowck the only way to prove `T: '?0` is by
25 /// setting `'?0` to `'empty`.
26implicit_region_bound: Option<ty::Region<'tcx>>,
27 caller_bounds: &'cx [ty::PolyTypeOutlivesPredicate<'tcx>],
28}
2930impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
31pub(crate) fn new(
32 tcx: TyCtxt<'tcx>,
33 region_bound_pairs: &'cx RegionBoundPairs<'tcx>,
34 implicit_region_bound: Option<ty::Region<'tcx>>,
35 caller_bounds: &'cx [ty::PolyTypeOutlivesPredicate<'tcx>],
36 ) -> Self {
37Self { tcx, region_bound_pairs, implicit_region_bound, caller_bounds }
38 }
3940#[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_or_placeholder_bound",
"rustc_infer::infer::outlives::verify",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/verify.rs"),
::tracing_core::__macro_support::Option::Some(40u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::verify"),
::tracing_core::field::FieldSet::new(&[{
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::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(&ty)
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: VerifyBound<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let declared_bounds_from_env =
self.declared_generic_bounds_from_env(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/verify.rs:46",
"rustc_infer::infer::outlives::verify",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/verify.rs"),
::tracing_core::__macro_support::Option::Some(46u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::verify"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("declared_bounds_from_env")
}> =
::tracing::__macro_support::FieldName::new("declared_bounds_from_env");
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(&declared_bounds_from_env)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let mut param_bounds = ::alloc::vec::Vec::new();
for declared_bound in declared_bounds_from_env {
let bound_region =
declared_bound.map_bound(|outlives| outlives.1);
if let Some(region) = bound_region.no_bound_vars() {
param_bounds.push(VerifyBound::OutlivedBy(region));
} 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/verify.rs:55",
"rustc_infer::infer::outlives::verify",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/verify.rs"),
::tracing_core::__macro_support::Option::Some(55u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::verify"),
::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!("found that {0:?} outlives any lifetime, returning empty vector",
ty) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
return VerifyBound::AllBounds(::alloc::vec::Vec::new());
}
}
if let Some(r) = self.implicit_region_bound {
{
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/verify.rs:63",
"rustc_infer::infer::outlives::verify",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/verify.rs"),
::tracing_core::__macro_support::Option::Some(63u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::verify"),
::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!("adding implicit region bound of {0:?}",
r) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
param_bounds.push(VerifyBound::OutlivedBy(r));
}
if param_bounds.is_empty() {
VerifyBound::IsEmpty
} else if param_bounds.len() == 1 {
param_bounds.pop().unwrap()
} else { VerifyBound::AnyBound(param_bounds) }
}
}
}#[instrument(level = "debug", skip(self))]41pub(crate) fn param_or_placeholder_bound(&self, ty: Ty<'tcx>) -> VerifyBound<'tcx> {
42// Start with anything like `T: 'a` we can scrape from the
43 // environment. If the environment contains something like
44 // `for<'a> T: 'a`, then we know that `T` outlives everything.
45let declared_bounds_from_env = self.declared_generic_bounds_from_env(ty);
46debug!(?declared_bounds_from_env);
47let mut param_bounds = vec![];
48for declared_bound in declared_bounds_from_env {
49let bound_region = declared_bound.map_bound(|outlives| outlives.1);
50if let Some(region) = bound_region.no_bound_vars() {
51// This is `T: 'a` for some free region `'a`.
52param_bounds.push(VerifyBound::OutlivedBy(region));
53 } else {
54// This is `for<'a> T: 'a`. This means that `T` outlives everything! All done here.
55debug!("found that {ty:?} outlives any lifetime, returning empty vector");
56return VerifyBound::AllBounds(vec![]);
57 }
58 }
5960// Add in the default bound of fn body that applies to all in
61 // scope type parameters:
62if let Some(r) = self.implicit_region_bound {
63debug!("adding implicit region bound of {r:?}");
64 param_bounds.push(VerifyBound::OutlivedBy(r));
65 }
6667if param_bounds.is_empty() {
68// We know that all types `T` outlive `'empty`, so if we
69 // can find no other bound, then check that the region
70 // being tested is `'empty`.
71VerifyBound::IsEmpty
72 } else if param_bounds.len() == 1 {
73// Micro-opt: no need to store the vector if it's just len 1
74param_bounds.pop().unwrap()
75 } else {
76// If we can find any other bound `R` such that `T: R`, then
77 // we don't need to check for `'empty`, because `R: 'empty`.
78VerifyBound::AnyBound(param_bounds)
79 }
80 }
8182/// Given a projection like `T::Item`, searches the environment
83 /// for where-clauses like `T::Item: 'a`. Returns the set of
84 /// regions `'a` that it finds.
85 ///
86 /// This is an "approximate" check -- it may not find all
87 /// applicable bounds, and not all the bounds it returns can be
88 /// relied upon. In particular, this check ignores region
89 /// identity. So, for example, if we have `<T as
90 /// Trait<'0>>::Item` where `'0` is a region variable, and the
91 /// user has `<T as Trait<'a>>::Item: 'b` in the environment, then
92 /// the clause from the environment only applies if `'0 = 'a`,
93 /// which we don't know yet. But we would still include `'b` in
94 /// this list.
95pub(crate) fn approx_declared_bounds_from_env(
96&self,
97 alias_ty: ty::AliasTy<'tcx>,
98 ) -> Vec<ty::PolyTypeOutlivesPredicate<'tcx>> {
99let erased_alias_ty = self.tcx.erase_and_anonymize_regions(
100alias_ty.to_ty(self.tcx, ty::IsRigid::yes_if_next_solver(self.tcx)),
101 );
102self.declared_generic_bounds_from_env_for_erased_ty(erased_alias_ty)
103 }
104105#[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_bound",
"rustc_infer::infer::outlives::verify",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/verify.rs"),
::tracing_core::__macro_support::Option::Some(105u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::verify"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("alias_ty")
}> =
::tracing::__macro_support::FieldName::new("alias_ty");
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(&alias_ty)
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: VerifyBound<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let env_bounds =
self.approx_declared_bounds_from_env(alias_ty).into_iter().map(|binder|
{
if let Some(ty::OutlivesPredicate(ty, r)) =
binder.no_bound_vars() &&
let ty::Alias(_, alias_ty_from_bound) = *ty.kind() &&
alias_ty_from_bound == alias_ty {
VerifyBound::OutlivedBy(r)
} else {
let verify_if_eq_b =
binder.map_bound(|ty::OutlivesPredicate(ty, bound)|
VerifyIfEq { ty, bound });
VerifyBound::IfEq(verify_if_eq_b)
}
});
let definition_bounds =
rustc_type_ir::outlives::declared_bounds_from_definition(self.tcx,
alias_ty).map(|r| VerifyBound::OutlivedBy(r));
let recursive_bound =
{
let mut components = ::smallvec::SmallVec::new();
compute_alias_components_recursive(self.tcx, alias_ty,
&mut components);
self.bound_from_components(&components)
};
VerifyBound::AnyBound(env_bounds.chain(definition_bounds).collect()).or(recursive_bound)
}
}
}#[instrument(level = "debug", skip(self))]106pub(crate) fn alias_bound(&self, alias_ty: ty::AliasTy<'tcx>) -> VerifyBound<'tcx> {
107// Search the env for where clauses like `P: 'a`.
108let env_bounds = self.approx_declared_bounds_from_env(alias_ty).into_iter().map(|binder| {
109// FIXME(#155345): We probably want to assert the alias is rigid here.
110if let Some(ty::OutlivesPredicate(ty, r)) = binder.no_bound_vars()
111 && let ty::Alias(_, alias_ty_from_bound) = *ty.kind()
112 && alias_ty_from_bound == alias_ty
113 {
114// Micro-optimize if this is an exact match (this
115 // occurs often when there are no region variables
116 // involved).
117VerifyBound::OutlivedBy(r)
118 } else {
119let verify_if_eq_b =
120 binder.map_bound(|ty::OutlivesPredicate(ty, bound)| VerifyIfEq { ty, bound });
121 VerifyBound::IfEq(verify_if_eq_b)
122 }
123 });
124125// Extend with bounds that we can find from the definition.
126let definition_bounds =
127 rustc_type_ir::outlives::declared_bounds_from_definition(self.tcx, alias_ty)
128 .map(|r| VerifyBound::OutlivedBy(r));
129130// see the extensive comment in projection_must_outlive
131let recursive_bound = {
132let mut components = smallvec![];
133 compute_alias_components_recursive(self.tcx, alias_ty, &mut components);
134self.bound_from_components(&components)
135 };
136137 VerifyBound::AnyBound(env_bounds.chain(definition_bounds).collect()).or(recursive_bound)
138 }
139140fn bound_from_components(&self, components: &[Component<TyCtxt<'tcx>>]) -> VerifyBound<'tcx> {
141let mut bounds = components142 .iter()
143 .map(|component| self.bound_from_single_component(component))
144// Remove bounds that must hold, since they are not interesting.
145.filter(|bound| !bound.must_hold());
146147match (bounds.next(), bounds.next()) {
148 (Some(first), None) => first,
149 (first, second) => {
150 VerifyBound::AllBounds(first.into_iter().chain(second).chain(bounds).collect())
151 }
152 }
153 }
154155fn bound_from_single_component(
156&self,
157 component: &Component<TyCtxt<'tcx>>,
158 ) -> VerifyBound<'tcx> {
159match *component {
160 Component::Region(lt) => VerifyBound::OutlivedBy(lt),
161 Component::Param(param_ty) => self.param_or_placeholder_bound(param_ty.to_ty(self.tcx)),
162 Component::Placeholder(placeholder_ty) => {
163self.param_or_placeholder_bound(Ty::new_placeholder(self.tcx, placeholder_ty))
164 }
165// `type_must_outlive` already asserted that it's rigid in the next solver.
166Component::Alias(_, alias_ty) => self.alias_bound(alias_ty),
167 Component::EscapingAlias(ref components) => self.bound_from_components(components),
168 Component::UnresolvedInferenceVariable(v) => {
169// Ignore this, we presume it will yield an error later, since
170 // if a type variable is not resolved by this point it never
171 // will be.
172self.tcx
173 .dcx()
174 .delayed_bug(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("unresolved inference variable in outlives: {0:?}",
v))
})format!("unresolved inference variable in outlives: {v:?}"));
175// Add a bound that never holds.
176 VerifyBound::AnyBound(::alloc::vec::Vec::new()vec![])
177 }
178 }
179 }
180181/// Searches the environment for where-clauses like `G: 'a` where
182 /// `G` is either some type parameter `T` or a projection like
183 /// `T::Item`. Returns a vector of the `'a` bounds it can find.
184 ///
185 /// This is a conservative check -- it may not find all applicable
186 /// bounds, but all the bounds it returns can be relied upon.
187fn declared_generic_bounds_from_env(
188&self,
189 generic_ty: Ty<'tcx>,
190 ) -> Vec<ty::PolyTypeOutlivesPredicate<'tcx>> {
191{
match generic_ty.kind() {
ty::Param(_) | ty::Placeholder(_) => {}
ref left_val => {
::core::panicking::assert_matches_failed(left_val,
"ty::Param(_) | ty::Placeholder(_)",
::core::option::Option::None);
}
}
};assert_matches!(generic_ty.kind(), ty::Param(_) | ty::Placeholder(_));
192self.declared_generic_bounds_from_env_for_erased_ty(generic_ty)
193 }
194195/// Searches the environment to find all bounds that apply to `erased_ty`.
196 /// Obviously these must be approximate -- they are in fact both *over* and
197 /// and *under* approximated:
198 ///
199 /// * Over-approximated because we don't consider equality of regions.
200 /// * Under-approximated because we look for syntactic equality and so for complex types
201 /// like `<T as Foo<fn(&u32, &u32)>>::Item` or whatever we may fail to figure out
202 /// all the subtleties.
203 ///
204 /// In some cases, such as when `erased_ty` represents a `ty::Param`, however,
205 /// the result is precise.
206#[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("declared_generic_bounds_from_env_for_erased_ty",
"rustc_infer::infer::outlives::verify",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/verify.rs"),
::tracing_core::__macro_support::Option::Some(206u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::verify"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("erased_ty")
}> =
::tracing::__macro_support::FieldName::new("erased_ty");
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(&erased_ty)
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:
Vec<ty::PolyTypeOutlivesPredicate<'tcx>> = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx;
let mut bounds = ::alloc::vec::Vec::new();
bounds.extend(self.caller_bounds.iter().copied().filter(move
|outlives_predicate|
{
super::test_type_match::can_match_erased_ty(tcx,
*outlives_predicate, erased_ty)
}));
bounds.extend(self.region_bound_pairs.iter().filter_map(|&OutlivesPredicate(p,
r)|
{
{
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/verify.rs:233",
"rustc_infer::infer::outlives::verify",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_infer/src/infer/outlives/verify.rs"),
::tracing_core::__macro_support::Option::Some(233u32),
::tracing_core::__macro_support::Option::Some("rustc_infer::infer::outlives::verify"),
::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!("declared_generic_bounds_from_env_for_erased_ty: region_bound_pair = {0:?}",
(r, p)) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
match (&p, erased_ty.kind()) {
(GenericKind::Param(p1), ty::Param(p2)) if p1 == p2 => {}
(GenericKind::Placeholder(p1), ty::Placeholder(p2)) if
p1 == p2 => {}
(GenericKind::Alias(a1), ty::Alias(is_rigid, a2)) if
a1.kind == a2.kind => {
if true {
{
match (&*is_rigid,
&ty::IsRigid::yes_if_next_solver(self.tcx)) {
(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);
}
}
}
};
};
}
_ => return None,
}
let p_ty = p.to_ty(tcx);
let erased_p_ty =
self.tcx.erase_and_anonymize_regions(p_ty);
(erased_p_ty ==
erased_ty).then_some(ty::Binder::dummy(ty::OutlivesPredicate(p_ty,
r)))
}));
bounds
}
}
}#[instrument(level = "debug", skip(self))]207fn declared_generic_bounds_from_env_for_erased_ty(
208&self,
209 erased_ty: Ty<'tcx>,
210 ) -> Vec<ty::PolyTypeOutlivesPredicate<'tcx>> {
211let tcx = self.tcx;
212let mut bounds = vec![];
213214// To start, collect bounds from user environment. Note that
215 // parameter environments are already elaborated, so we don't
216 // have to worry about that.
217bounds.extend(self.caller_bounds.iter().copied().filter(move |outlives_predicate| {
218super::test_type_match::can_match_erased_ty(tcx, *outlives_predicate, erased_ty)
219 }));
220221// Next, collect regions we scraped from the well-formedness
222 // constraints in the fn signature. To do that, we walk the list
223 // of known relations from the fn ctxt.
224 //
225 // This is crucial because otherwise code like this fails:
226 //
227 // fn foo<'a, A>(x: &'a A) { x.bar() }
228 //
229 // The problem is that the type of `x` is `&'a A`. To be
230 // well-formed, then, A must outlive `'a`, but we don't know that
231 // this holds from first principles.
232bounds.extend(self.region_bound_pairs.iter().filter_map(|&OutlivesPredicate(p, r)| {
233debug!(
234"declared_generic_bounds_from_env_for_erased_ty: region_bound_pair = {:?}",
235 (r, p)
236 );
237// Fast path for the common case.
238match (&p, erased_ty.kind()) {
239// In outlive routines, all types are expected to be fully normalized.
240 // And therefore we can safely use structural equality for alias types.
241(GenericKind::Param(p1), ty::Param(p2)) if p1 == p2 => {}
242 (GenericKind::Placeholder(p1), ty::Placeholder(p2)) if p1 == p2 => {}
243 (GenericKind::Alias(a1), ty::Alias(is_rigid, a2)) if a1.kind == a2.kind => {
244debug_assert_eq!(*is_rigid, ty::IsRigid::yes_if_next_solver(self.tcx));
245 }
246_ => return None,
247 }
248249let p_ty = p.to_ty(tcx);
250let erased_p_ty = self.tcx.erase_and_anonymize_regions(p_ty);
251 (erased_p_ty == erased_ty).then_some(ty::Binder::dummy(ty::OutlivesPredicate(p_ty, r)))
252 }));
253254 bounds
255 }
256}