1use std::collections::VecDeque;
2use std::fmt;
3use std::rc::Rc;
45use rustc_data_structures::frozen::Frozen;
6use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
7use rustc_data_structures::graph::scc::Sccs;
8use rustc_errors::Diag;
9use rustc_hir::def_id::CRATE_DEF_ID;
10use rustc_index::IndexVec;
11use rustc_infer::infer::outlives::test_type_match;
12use rustc_infer::infer::region_constraints::{GenericKind, VerifyBound, VerifyIfEq};
13use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin};
14use rustc_middle::mir::{
15AnnotationSource, BasicBlock, Body, ConstraintCategory, Local, Location, ReturnConstraint,
16TerminatorKind,
17};
18use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
19use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable, UniverseIndex, fold_regions};
20use rustc_mir_dataflow::points::DenseLocationMap;
21use rustc_span::hygiene::DesugaringKind;
22use rustc_span::{DUMMY_SP, Span, bug};
23use tracing::{Level, debug, enabled, instrument, trace};
2425use crate::constraints::graph::NormalConstraintGraph;
26use crate::constraints::{ConstraintSccIndex, OutlivesConstraint, OutlivesConstraintSet};
27use crate::dataflow::BorrowIndex;
28use crate::diagnostics::{RegionErrorKind, RegionErrors, UniverseInfo};
29use crate::handle_placeholders::{LoweredConstraints, RegionTracker};
30use crate::polonius::legacy::PoloniusOutput;
31use crate::region_infer::values::{LivenessValues, RegionElement, RegionValues};
32use crate::type_check::Locations;
33use crate::type_check::free_region_relations::UniversalRegionRelations;
34use crate::universal_regions::UniversalRegions;
35use crate::{
36BorrowckInferCtxt, ClosureOutlivesRequirement, ClosureOutlivesSubject,
37ClosureOutlivesSubjectTy, ClosureRegionRequirements,
38};
3940mod dump_mir;
41mod graphviz;
42pub(crate) mod opaque_types;
43mod reverse_sccs;
4445pub(crate) mod values;
4647/// The representative region variable for an SCC, tagged by its origin.
48/// We prefer placeholders over existentially quantified variables, otherwise
49/// it's the one with the smallest Region Variable ID. In other words,
50/// the order of this enumeration really matters!
51#[derive(#[automatically_derived]
impl ::core::marker::Copy for Representative { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for Representative {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Representative::FreeRegion(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"FreeRegion", &__self_0),
Representative::Placeholder(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Placeholder", &__self_0),
Representative::Existential(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Existential", &__self_0),
}
}
}Debug, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for Representative { }
#[automatically_derived]
impl ::core::clone::Clone for Representative {
#[inline]
fn clone(&self) -> Representative {
let _: ::core::clone::AssertParamIsClone<RegionVid>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for Representative { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Representative {
#[inline]
fn eq(&self, other: &Representative) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(Representative::FreeRegion(__self_0),
Representative::FreeRegion(__arg1_0)) =>
__self_0 == __arg1_0,
(Representative::Placeholder(__self_0),
Representative::Placeholder(__arg1_0)) =>
__self_0 == __arg1_0,
(Representative::Existential(__self_0),
Representative::Existential(__arg1_0)) =>
__self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::PartialOrd for Representative {
#[inline]
fn partial_cmp(&self, other: &Representative)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Eq for Representative {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<RegionVid>;
}
}Eq, #[automatically_derived]
impl ::core::cmp::Ord for Representative {
#[inline]
fn cmp(&self, other: &Representative) -> ::core::cmp::Ordering {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
match ::core::cmp::Ord::cmp(&__self_discr, &__arg1_discr) {
::core::cmp::Ordering::Equal =>
match (self, other) {
(Representative::FreeRegion(__self_0),
Representative::FreeRegion(__arg1_0)) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
(Representative::Placeholder(__self_0),
Representative::Placeholder(__arg1_0)) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
(Representative::Existential(__self_0),
Representative::Existential(__arg1_0)) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
_ => unsafe { ::core::intrinsics::unreachable() }
},
cmp => cmp,
}
}
}Ord)]
52pub(crate) enum Representative {
53 FreeRegion(RegionVid),
54 Placeholder(RegionVid),
55 Existential(RegionVid),
56}
5758impl Representative {
59pub(crate) fn rvid(self) -> RegionVid {
60match self {
61 Representative::FreeRegion(region_vid)
62 | Representative::Placeholder(region_vid)
63 | Representative::Existential(region_vid) => region_vid,
64 }
65 }
6667pub(crate) fn new(r: RegionVid, definition: &RegionDefinition<'_>) -> Self {
68match definition.origin {
69 NllRegionVariableOrigin::FreeRegion => Representative::FreeRegion(r),
70 NllRegionVariableOrigin::Placeholder(_) => Representative::Placeholder(r),
71 NllRegionVariableOrigin::Existential { .. } => Representative::Existential(r),
72 }
73 }
74}
7576pub(crate) type ConstraintSccs = Sccs<RegionVid, ConstraintSccIndex>;
7778pub struct RegionInferenceContext<'tcx> {
79/// Contains the definition for every region variable. Region
80 /// variables are identified by their index (`RegionVid`). The
81 /// definition contains information about where the region came
82 /// from as well as its final inferred value.
83pub(crate) definitions: Frozen<IndexVec<RegionVid, RegionDefinition<'tcx>>>,
8485/// The liveness constraints added to each region. For most
86 /// regions, these start out empty and steadily grow, though for
87 /// each universally quantified region R they start out containing
88 /// the entire CFG and `end(R)`.
89liveness_constraints: LivenessValues,
9091/// The outlives constraints computed by the type-check.
92constraints: Frozen<OutlivesConstraintSet<'tcx>>,
9394/// The constraint-set, but in graph form, making it easy to traverse
95 /// the constraints adjacent to a particular region. Used to construct
96 /// the SCC (see `constraint_sccs`) and for error reporting.
97constraint_graph: Frozen<NormalConstraintGraph>,
9899/// The SCC computed from `constraints` and the constraint
100 /// graph. We have an edge from SCC A to SCC B if `A: B`. Used to
101 /// compute the values of each region.
102constraint_sccs: ConstraintSccs,
103104 scc_annotations: IndexVec<ConstraintSccIndex, RegionTracker>,
105106/// Map universe indexes to information on why we created it.
107universe_causes: FxIndexMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
108109/// The final inferred values of the region variables; we compute
110 /// one value per SCC. To get the value for any given *region*,
111 /// you first find which scc it is a part of.
112scc_values: RegionValues<'tcx, ConstraintSccIndex>,
113114/// Type constraints that we check after solving.
115type_tests: Vec<TypeTest<'tcx>>,
116117/// Information about how the universally quantified regions in
118 /// scope on this function relate to one another.
119universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
120}
121122#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for RegionDefinition<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f,
"RegionDefinition", "origin", &self.origin, "universe",
&self.universe, "external_name", &&self.external_name)
}
}Debug)]
123pub(crate) struct RegionDefinition<'tcx> {
124/// What kind of variable is this -- a free region? existential
125 /// variable? etc. (See the `NllRegionVariableOrigin` for more
126 /// info.)
127pub(crate) origin: NllRegionVariableOrigin<'tcx>,
128129/// Which universe is this region variable defined in? This is
130 /// most often `ty::UniverseIndex::ROOT`, but when we encounter
131 /// forall-quantifiers like `for<'a> { 'a = 'b }`, we would create
132 /// the variable for `'a` in a fresh universe that extends ROOT.
133pub(crate) universe: ty::UniverseIndex,
134135/// If this is 'static or an early-bound region, then this is
136 /// `Some(X)` where `X` is the name of the region.
137pub(crate) external_name: Option<ty::Region<'tcx>>,
138}
139140/// N.B., the variants in `Cause` are intentionally ordered. Lower
141/// values are preferred when it comes to error messages. Do not
142/// reorder willy nilly.
143#[derive(#[automatically_derived]
impl ::core::marker::Copy for Cause { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for Cause { }
#[automatically_derived]
impl ::core::clone::Clone for Cause {
#[inline]
fn clone(&self) -> Cause {
let _: ::core::clone::AssertParamIsClone<Local>;
let _: ::core::clone::AssertParamIsClone<Location>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for Cause {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Cause::LiveVar(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"LiveVar", __self_0, &__self_1),
Cause::DropVar(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"DropVar", __self_0, &__self_1),
}
}
}Debug, #[automatically_derived]
impl ::core::cmp::PartialOrd for Cause {
#[inline]
fn partial_cmp(&self, other: &Cause)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for Cause {
#[inline]
fn cmp(&self, other: &Cause) -> ::core::cmp::Ordering {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
match ::core::cmp::Ord::cmp(&__self_discr, &__arg1_discr) {
::core::cmp::Ordering::Equal =>
match (self, other) {
(Cause::LiveVar(__self_0, __self_1),
Cause::LiveVar(__arg1_0, __arg1_1)) =>
match ::core::cmp::Ord::cmp(__self_0, __arg1_0) {
::core::cmp::Ordering::Equal =>
::core::cmp::Ord::cmp(__self_1, __arg1_1),
cmp => cmp,
},
(Cause::DropVar(__self_0, __self_1),
Cause::DropVar(__arg1_0, __arg1_1)) =>
match ::core::cmp::Ord::cmp(__self_0, __arg1_0) {
::core::cmp::Ordering::Equal =>
::core::cmp::Ord::cmp(__self_1, __arg1_1),
cmp => cmp,
},
_ => unsafe { ::core::intrinsics::unreachable() }
},
cmp => cmp,
}
}
}Ord, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for Cause { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Cause {
#[inline]
fn eq(&self, other: &Cause) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(Cause::LiveVar(__self_0, __self_1),
Cause::LiveVar(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(Cause::DropVar(__self_0, __self_1),
Cause::DropVar(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Cause {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Local>;
let _: ::core::cmp::AssertParamIsEq<Location>;
}
}Eq)]
144pub(crate) enum Cause {
145/// point inserted because Local was live at the given Location
146LiveVar(Local, Location),
147148/// point inserted because Local was dropped at the given Location
149DropVar(Local, Location),
150}
151152/// A "type test" corresponds to an outlives constraint between a type
153/// and a lifetime, like `T: 'x` or `<T as Foo>::Bar: 'x`. They are
154/// translated from the `Verify` region constraints in the ordinary
155/// inference context.
156///
157/// These sorts of constraints are handled differently than ordinary
158/// constraints, at least at present. During type checking, the
159/// `InferCtxt::process_registered_region_obligations` method will
160/// attempt to convert a type test like `T: 'x` into an ordinary
161/// outlives constraint when possible (for example, `&'a T: 'b` will
162/// be converted into `'a: 'b` and registered as a `Constraint`).
163///
164/// In some cases, however, there are outlives relationships that are
165/// not converted into a region constraint, but rather into one of
166/// these "type tests". The distinction is that a type test does not
167/// influence the inference result, but instead just examines the
168/// values that we ultimately inferred for each region variable and
169/// checks that they meet certain extra criteria. If not, an error
170/// can be issued.
171///
172/// One reason for this is that these type tests typically boil down
173/// to a check like `'a: 'x` where `'a` is a universally quantified
174/// region -- and therefore not one whose value is really meant to be
175/// *inferred*, precisely (this is not always the case: one can have a
176/// type test like `<Foo as Trait<'?0>>::Bar: 'x`, where `'?0` is an
177/// inference variable). Another reason is that these type tests can
178/// involve *disjunction* -- that is, they can be satisfied in more
179/// than one way.
180///
181/// For more information about this translation, see
182/// `InferCtxt::process_registered_region_obligations` and
183/// `InferCtxt::type_must_outlive` in `rustc_infer::infer::InferCtxt`.
184#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for TypeTest<'tcx> {
#[inline]
fn clone(&self) -> TypeTest<'tcx> {
TypeTest {
generic_kind: ::core::clone::Clone::clone(&self.generic_kind),
lower_bound: ::core::clone::Clone::clone(&self.lower_bound),
span: ::core::clone::Clone::clone(&self.span),
verify_bound: ::core::clone::Clone::clone(&self.verify_bound),
}
}
}Clone)]
185pub(crate) struct TypeTest<'tcx> {
186/// The type `T` that must outlive the region.
187pub generic_kind: GenericKind<'tcx>,
188189/// The region `'x` that the type must outlive.
190pub lower_bound: RegionVid,
191192/// The span to blame.
193pub span: Span,
194195/// A test which, if met by the region `'x`, proves that this type
196 /// constraint is satisfied.
197pub verify_bound: VerifyBound<'tcx>,
198}
199200impl fmt::Debugfor TypeTest<'_> {
201fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
202fn fmt_bound(
203 f: &mut fmt::Formatter<'_>,
204 generic_kind: GenericKind<'_>,
205 lower: RegionVid,
206 bound: &VerifyBound<'_>,
207 ) -> fmt::Result {
208let fmt_bounds =
209 |f: &mut fmt::Formatter<'_>, bounds: &[VerifyBound<'_>]| -> fmt::Result {
210let mut it = bounds.iter().peekable();
211while let Some(bound) = it.next() {
212 fmt_bound(f, generic_kind, lower, bound)?;
213if it.peek().is_some() {
214f.write_fmt(format_args!(", "))write!(f, ", ")?
215}
216 }
217Ok(())
218 };
219match bound {
220 VerifyBound::IfEq(binder) => f.write_fmt(format_args!("{0:?} == {1:?}", generic_kind, binder))write!(f, "{:?} == {:?}", generic_kind, binder),
221 VerifyBound::OutlivedBy(region) => f.write_fmt(format_args!("{0:?}: {1:?}", region, lower))write!(f, "{region:?}: {lower:?}"),
222 VerifyBound::AnyBound(verify_bounds) => {
223f.write_fmt(format_args!("Any["))write!(f, "Any[")?;
224 fmt_bounds(f, verify_bounds)?;
225f.write_fmt(format_args!("]"))write!(f, "]")226 }
227 VerifyBound::AllBounds(verify_bounds) => {
228f.write_fmt(format_args!("All["))write!(f, "All[")?;
229 fmt_bounds(f, verify_bounds)?;
230f.write_fmt(format_args!("]"))write!(f, "]")231 }
232 VerifyBound::IsEmpty => f.write_fmt(format_args!("Empty({0:?})", lower))write!(f, "Empty({lower:?})"),
233 }
234 }
235f.write_fmt(format_args!("TypeTest from {0:?}[", self.span))write!(f, "TypeTest from {:?}[", self.span)?;
236 fmt_bound(f, self.generic_kind, self.lower_bound, &self.verify_bound)?;
237f.write_fmt(format_args!("] ⊢ {0:?}: {1:?}", self.generic_kind,
self.lower_bound))write!(f, "] ⊢ {:?}: {:?}", self.generic_kind, self.lower_bound)238 }
239}
240241/// When we have an unmet lifetime constraint, we try to propagate it outward (e.g. to a closure
242/// environment). If we can't, it is an error.
243#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for RegionRelationCheckResult { }
#[automatically_derived]
impl ::core::clone::Clone for RegionRelationCheckResult {
#[inline]
fn clone(&self) -> RegionRelationCheckResult { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for RegionRelationCheckResult { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for RegionRelationCheckResult {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
RegionRelationCheckResult::Ok => "Ok",
RegionRelationCheckResult::Propagated => "Propagated",
RegionRelationCheckResult::Error => "Error",
})
}
}Debug, #[automatically_derived]
impl ::core::cmp::Eq for RegionRelationCheckResult { }Eq, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for RegionRelationCheckResult { }
#[automatically_derived]
impl ::core::cmp::PartialEq for RegionRelationCheckResult {
#[inline]
fn eq(&self, other: &RegionRelationCheckResult) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq)]
244enum RegionRelationCheckResult {
245Ok,
246 Propagated,
247 Error,
248}
249250#[derive(#[automatically_derived]
impl<'a, 'tcx> ::core::clone::Clone for Trace<'a, 'tcx> {
#[inline]
fn clone(&self) -> Trace<'a, 'tcx> {
match self {
Trace::StartRegion => Trace::StartRegion,
Trace::FromGraph(__self_0) =>
Trace::FromGraph(::core::clone::Clone::clone(__self_0)),
Trace::FromStatic(__self_0) =>
Trace::FromStatic(::core::clone::Clone::clone(__self_0)),
Trace::NotVisited => Trace::NotVisited,
}
}
}Clone, #[automatically_derived]
impl<'a, 'tcx> ::core::marker::StructuralPartialEq for Trace<'a, 'tcx> { }
#[automatically_derived]
impl<'a, 'tcx> ::core::cmp::PartialEq for Trace<'a, 'tcx> {
#[inline]
fn eq(&self, other: &Trace<'a, 'tcx>) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(Trace::FromGraph(__self_0), Trace::FromGraph(__arg1_0)) =>
__self_0 == __arg1_0,
(Trace::FromStatic(__self_0), Trace::FromStatic(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl<'a, 'tcx> ::core::cmp::Eq for Trace<'a, 'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<&'a OutlivesConstraint<'tcx>>;
let _: ::core::cmp::AssertParamIsEq<RegionVid>;
}
}Eq, #[automatically_derived]
impl<'a, 'tcx> ::core::fmt::Debug for Trace<'a, 'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Trace::StartRegion =>
::core::fmt::Formatter::write_str(f, "StartRegion"),
Trace::FromGraph(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"FromGraph", &__self_0),
Trace::FromStatic(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"FromStatic", &__self_0),
Trace::NotVisited =>
::core::fmt::Formatter::write_str(f, "NotVisited"),
}
}
}Debug)]
251enum Trace<'a, 'tcx> {
252 StartRegion,
253 FromGraph(&'a OutlivesConstraint<'tcx>),
254 FromStatic(RegionVid),
255 NotVisited,
256}
257258{}
#[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("sccs_info",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(258u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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 crate::renumber::RegionCtxt;
let var_to_origin = infcx.reg_var_to_origin.borrow();
let mut var_to_origin_sorted =
var_to_origin.clone().into_iter().collect::<Vec<_>>();
var_to_origin_sorted.sort_by_key(|vto| vto.0);
if {
if Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("enabled /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:267",
"rustc_borrowck::region_infer", Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(267u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::HINT.hint())
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let interest = __CALLSITE.interest();
if !interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::dispatcher::get_default(|current|
current.enabled(meta))
} else { false }
} else { false }
} {
let mut reg_vars_to_origins_str =
"region variables to origins:\n".to_string();
for (reg_var, origin) in var_to_origin_sorted.into_iter() {
reg_vars_to_origins_str.push_str(&::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:?}: {1:?}\n", reg_var,
origin))
}));
}
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:272",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(272u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("{0}",
reg_vars_to_origins_str) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
}
let num_components = sccs.num_sccs();
let mut components =
::alloc::vec::from_elem(FxIndexSet::default(),
num_components);
for (reg_var, scc_idx) in sccs.scc_indices().iter_enumerated() {
let origin =
var_to_origin.get(®_var).unwrap_or(&RegionCtxt::Unknown);
components[scc_idx.as_usize()].insert((reg_var, *origin));
}
if {
if Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("enabled /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:283",
"rustc_borrowck::region_infer", Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(283u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::HINT.hint())
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let interest = __CALLSITE.interest();
if !interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::dispatcher::get_default(|current|
current.enabled(meta))
} else { false }
} else { false }
} {
let mut components_str =
"strongly connected components:".to_string();
for (scc_idx, reg_vars_origins) in
components.iter().enumerate() {
let regions_info =
reg_vars_origins.clone().into_iter().collect::<Vec<_>>();
components_str.push_str(&::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:?}: {1:?},\n)",
ConstraintSccIndex::from_usize(scc_idx), regions_info))
}))
}
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:293",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(293u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("{0}",
components_str) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
}
let components_representatives =
components.into_iter().enumerate().map(|(scc_idx,
region_ctxts)|
{
let repr =
region_ctxts.into_iter().map(|reg_var_origin|
reg_var_origin.1).max_by(|x, y|
x.preference_value().cmp(&y.preference_value())).unwrap();
(ConstraintSccIndex::from_usize(scc_idx), repr)
}).collect::<FxIndexMap<_, _>>();
let mut scc_node_to_edges = FxIndexMap::default();
for (scc_idx, repr) in components_representatives.iter() {
let edge_representatives =
sccs.successors(*scc_idx).iter().map(|scc_idx|
components_representatives[scc_idx]).collect::<Vec<_>>();
scc_node_to_edges.insert((scc_idx, repr),
edge_representatives);
}
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:321",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(321u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("SCC edges {0:#?}",
scc_node_to_edges) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
}
}
}#[instrument(skip(infcx, sccs), level = "debug")]259fn sccs_info<'tcx>(infcx: &BorrowckInferCtxt<'tcx>, sccs: &ConstraintSccs) {
260use crate::renumber::RegionCtxt;
261262let var_to_origin = infcx.reg_var_to_origin.borrow();
263264let mut var_to_origin_sorted = var_to_origin.clone().into_iter().collect::<Vec<_>>();
265 var_to_origin_sorted.sort_by_key(|vto| vto.0);
266267if enabled!(Level::DEBUG) {
268let mut reg_vars_to_origins_str = "region variables to origins:\n".to_string();
269for (reg_var, origin) in var_to_origin_sorted.into_iter() {
270 reg_vars_to_origins_str.push_str(&format!("{reg_var:?}: {origin:?}\n"));
271 }
272debug!("{}", reg_vars_to_origins_str);
273 }
274275let num_components = sccs.num_sccs();
276let mut components = vec![FxIndexSet::default(); num_components];
277278for (reg_var, scc_idx) in sccs.scc_indices().iter_enumerated() {
279let origin = var_to_origin.get(®_var).unwrap_or(&RegionCtxt::Unknown);
280 components[scc_idx.as_usize()].insert((reg_var, *origin));
281 }
282283if enabled!(Level::DEBUG) {
284let mut components_str = "strongly connected components:".to_string();
285for (scc_idx, reg_vars_origins) in components.iter().enumerate() {
286let regions_info = reg_vars_origins.clone().into_iter().collect::<Vec<_>>();
287 components_str.push_str(&format!(
288"{:?}: {:?},\n)",
289 ConstraintSccIndex::from_usize(scc_idx),
290 regions_info,
291 ))
292 }
293debug!("{}", components_str);
294 }
295296// calculate the best representative for each component
297let components_representatives = components
298 .into_iter()
299 .enumerate()
300 .map(|(scc_idx, region_ctxts)| {
301let repr = region_ctxts
302 .into_iter()
303 .map(|reg_var_origin| reg_var_origin.1)
304 .max_by(|x, y| x.preference_value().cmp(&y.preference_value()))
305 .unwrap();
306307 (ConstraintSccIndex::from_usize(scc_idx), repr)
308 })
309 .collect::<FxIndexMap<_, _>>();
310311let mut scc_node_to_edges = FxIndexMap::default();
312for (scc_idx, repr) in components_representatives.iter() {
313let edge_representatives = sccs
314 .successors(*scc_idx)
315 .iter()
316 .map(|scc_idx| components_representatives[scc_idx])
317 .collect::<Vec<_>>();
318 scc_node_to_edges.insert((scc_idx, repr), edge_representatives);
319 }
320321debug!("SCC edges {:#?}", scc_node_to_edges);
322}
323324impl<'tcx> RegionInferenceContext<'tcx> {
325/// Creates a new region inference context with a total of
326 /// `num_region_variables` valid inference variables; the first N
327 /// of those will be constant regions representing the free
328 /// regions defined in `universal_regions`.
329 ///
330 /// The `outlives_constraints` and `type_tests` are an initial set
331 /// of constraints produced by the MIR type check.
332pub(crate) fn new(
333 infcx: &BorrowckInferCtxt<'tcx>,
334 lowered_constraints: LoweredConstraints<'tcx>,
335 universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
336 location_map: Rc<DenseLocationMap>,
337 ) -> Self {
338let universal_regions = &universal_region_relations.universal_regions;
339340let LoweredConstraints {
341 constraint_sccs,
342 definitions,
343 outlives_constraints,
344 scc_annotations,
345 type_tests,
346 liveness_constraints,
347 universe_causes,
348 placeholder_indices,
349 } = lowered_constraints;
350351{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:351",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(351u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("universal_regions: {0:#?}",
universal_region_relations.universal_regions) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("universal_regions: {:#?}", universal_region_relations.universal_regions);
352{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:352",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(352u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("outlives constraints: {0:#?}",
outlives_constraints) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("outlives constraints: {:#?}", outlives_constraints);
353{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:353",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(353u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("placeholder_indices: {0:#?}",
placeholder_indices) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("placeholder_indices: {:#?}", placeholder_indices);
354{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:354",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(354u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("type tests: {0:#?}",
type_tests) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("type tests: {:#?}", type_tests);
355356let constraint_graph = Frozen::freeze(outlives_constraints.graph(definitions.len()));
357358if truecfg!(debug_assertions) {
359sccs_info(infcx, &constraint_sccs);
360 }
361362let mut scc_values =
363RegionValues::new(location_map, universal_regions.len(), placeholder_indices);
364365// Initializes the region variables with their initial live points.
366for (region, definition) in definitions.iter_enumerated() {
367let scc = constraint_sccs.scc(region);
368369// For each universally quantified region (lifetime parameter). The
370 // first N variables always correspond to the regions appearing in the
371 // function signature (both named and anonymous) and in where-clauses.
372match definition.origin {
373// For each free, universally quantified region X:
374NllRegionVariableOrigin::FreeRegion => {
375// Add `end(X)` into the set for X.
376scc_values.add_free_region(scc, region);
377 }
378379 NllRegionVariableOrigin::Placeholder(placeholder) => {
380 scc_values.add_placeholder(scc, placeholder);
381 }
382383 NllRegionVariableOrigin::Existential { .. } => {
384// For existential, regions, nothing to do.
385}
386 }
387388// Initially copy the liveness constraints of any region that
389 // has them, setting `scc_values[scc(region)] |= liveness_constraints[region]`.
390 //
391 // These values will later be propagated during [`Self::propagate_constraints()`].
392 // The values include any live-at-all-points constraints added previously in `liveness::generate`.
393if let Some(liveness) = liveness_constraints.point_liveness(region) {
394 scc_values.merge_liveness(scc, liveness)
395 }
396 }
397398Self {
399definitions,
400liveness_constraints,
401 constraints: outlives_constraints,
402constraint_graph,
403constraint_sccs,
404scc_annotations,
405universe_causes,
406scc_values,
407type_tests,
408universal_region_relations,
409 }
410 }
411412/// Returns an iterator over all the region indices.
413pub(crate) fn regions(&self) -> impl Iterator<Item = RegionVid> + 'tcx {
414self.definitions.indices()
415 }
416417/// Given a universal region in scope on the MIR, returns the
418 /// corresponding index.
419 ///
420 /// Panics if `r` is not a registered universal region, most notably
421 /// if it is a placeholder. Handling placeholders requires access to the
422 /// `MirTypeckRegionConstraints`.
423pub(crate) fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
424self.universal_regions().to_region_vid(r)
425 }
426427/// Returns an iterator over all the outlives constraints.
428pub(crate) fn outlives_constraints(&self) -> impl Iterator<Item = OutlivesConstraint<'tcx>> {
429self.constraints.outlives().iter().copied()
430 }
431432/// Adds annotations for `#[rustc_regions]`; see `UniversalRegions::annotate`.
433pub(crate) fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut Diag<'_, ()>) {
434self.universal_regions().annotate(tcx, err)
435 }
436437/// Returns `true` if the region `r` contains the point `p`.
438 ///
439 /// Panics if called before `solve()` executes,
440pub(crate) fn region_contains_point(&self, r: RegionVid, p: Location) -> bool {
441let scc = self.constraint_sccs.scc(r);
442self.scc_values.contains_point(scc, p)
443 }
444445/// Returns the lowest statement index in `start..=end` which is not contained by `r`.
446 ///
447 /// Panics if called before `solve()` executes.
448pub(crate) fn first_non_contained_inclusive(
449&self,
450 r: RegionVid,
451 block: BasicBlock,
452 start: usize,
453 end: usize,
454 ) -> Option<usize> {
455let scc = self.constraint_sccs.scc(r);
456self.scc_values.first_non_contained_inclusive(scc, block, start, end)
457 }
458459/// Returns access to the value of `r` for debugging purposes.
460pub(crate) fn region_value_str(&self, r: RegionVid) -> String {
461let scc = self.constraint_sccs.scc(r);
462self.scc_values.region_value_str(scc)
463 }
464465pub(crate) fn placeholders_contained_in(
466&self,
467 r: RegionVid,
468 ) -> impl Iterator<Item = ty::PlaceholderRegion<'tcx>> {
469let scc = self.constraint_sccs.scc(r);
470self.scc_values.placeholders_contained_in(scc)
471 }
472473/// Performs region inference and report errors if we see any
474 /// unsatisfiable constraints. If this is a closure, returns the
475 /// region requirements to propagate to our creator, if any.
476{}
#[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("solve",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(476u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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:
(Option<ClosureRegionRequirements<'tcx>>,
RegionErrors<'tcx>) = loop {};
return __tracing_attr_fake_return;
}
{
let mir_def_id = body.source.def_id();
self.propagate_constraints();
let mut errors_buffer = RegionErrors::new(infcx.tcx);
let mut propagated_outlives_requirements =
infcx.tcx.is_typeck_child(mir_def_id).then(Vec::new);
self.check_type_tests(infcx,
propagated_outlives_requirements.as_mut(),
&mut errors_buffer);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:496",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(496u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("errors_buffer")
}> =
::tracing::__macro_support::FieldName::new("errors_buffer");
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(&errors_buffer)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:497",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(497u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("propagated_outlives_requirements")
}> =
::tracing::__macro_support::FieldName::new("propagated_outlives_requirements");
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(&propagated_outlives_requirements)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
if infcx.tcx.sess.opts.unstable_opts.polonius.is_legacy_enabled()
{
self.check_polonius_subset_errors(propagated_outlives_requirements.as_mut(),
&mut errors_buffer,
polonius_output.as_ref().expect("Polonius output is unavailable despite `-Z polonius`"));
} else {
self.check_universal_regions(propagated_outlives_requirements.as_mut(),
&mut errors_buffer);
}
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:517",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(517u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("errors_buffer")
}> =
::tracing::__macro_support::FieldName::new("errors_buffer");
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(&errors_buffer)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let propagated_outlives_requirements =
propagated_outlives_requirements.unwrap_or_default();
if propagated_outlives_requirements.is_empty() {
(None, errors_buffer)
} else {
let num_external_vids =
self.universal_regions().num_global_and_external_regions();
(Some(ClosureRegionRequirements {
num_external_vids,
outlives_requirements: propagated_outlives_requirements,
}), errors_buffer)
}
}
}
}#[instrument(skip(self, infcx, body, polonius_output), level = "debug")]477pub(super) fn solve(
478&mut self,
479 infcx: &InferCtxt<'tcx>,
480 body: &Body<'tcx>,
481 polonius_output: Option<Box<PoloniusOutput>>,
482 ) -> (Option<ClosureRegionRequirements<'tcx>>, RegionErrors<'tcx>) {
483let mir_def_id = body.source.def_id();
484self.propagate_constraints();
485486let mut errors_buffer = RegionErrors::new(infcx.tcx);
487488// If this is a nested body, we propagate unsatisfied
489 // outlives constraints to the parent body instead of
490 // eagerly erroing.
491let mut propagated_outlives_requirements =
492 infcx.tcx.is_typeck_child(mir_def_id).then(Vec::new);
493494self.check_type_tests(infcx, propagated_outlives_requirements.as_mut(), &mut errors_buffer);
495496debug!(?errors_buffer);
497debug!(?propagated_outlives_requirements);
498499// In Polonius mode, the errors about missing universal region relations are in the output
500 // and need to be emitted or propagated. Otherwise, we need to check whether the
501 // constraints were too strong, and if so, emit or propagate those errors.
502if infcx.tcx.sess.opts.unstable_opts.polonius.is_legacy_enabled() {
503self.check_polonius_subset_errors(
504 propagated_outlives_requirements.as_mut(),
505&mut errors_buffer,
506 polonius_output
507 .as_ref()
508 .expect("Polonius output is unavailable despite `-Z polonius`"),
509 );
510 } else {
511self.check_universal_regions(
512 propagated_outlives_requirements.as_mut(),
513&mut errors_buffer,
514 );
515 }
516517debug!(?errors_buffer);
518519let propagated_outlives_requirements = propagated_outlives_requirements.unwrap_or_default();
520521if propagated_outlives_requirements.is_empty() {
522 (None, errors_buffer)
523 } else {
524let num_external_vids = self.universal_regions().num_global_and_external_regions();
525 (
526Some(ClosureRegionRequirements {
527 num_external_vids,
528 outlives_requirements: propagated_outlives_requirements,
529 }),
530 errors_buffer,
531 )
532 }
533 }
534535/// Propagate the region constraints: this will grow the values
536 /// for each region variable until all the constraints are
537 /// satisfied. Note that some values may grow **too** large to be
538 /// feasible, but we check this later.
539{}
#[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("propagate_constraints",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(539u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:541",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(541u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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={0:#?}",
{
let mut constraints: Vec<_> =
self.outlives_constraints().collect();
constraints.sort_by_key(|c| (c.sup, c.sub));
constraints.into_iter().map(|c|
(c, self.constraint_sccs.scc(c.sup),
self.constraint_sccs.scc(c.sub))).collect::<Vec<_>>()
}) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
for scc_a in self.constraint_sccs.all_sccs() {
for &scc_b in self.constraint_sccs.successors(scc_a) {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:558",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(558u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("scc_b")
}> =
::tracing::__macro_support::FieldName::new("scc_b");
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(&scc_b)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
self.scc_values.add_region(scc_a, scc_b);
}
}
}
}
}#[instrument(skip(self), level = "debug")]540fn propagate_constraints(&mut self) {
541debug!("constraints={:#?}", {
542let mut constraints: Vec<_> = self.outlives_constraints().collect();
543 constraints.sort_by_key(|c| (c.sup, c.sub));
544 constraints
545 .into_iter()
546 .map(|c| (c, self.constraint_sccs.scc(c.sup), self.constraint_sccs.scc(c.sub)))
547 .collect::<Vec<_>>()
548 });
549550// To propagate constraints, we walk the DAG induced by the
551 // SCC. For each SCC `A`, we visit its successors and compute
552 // their values, then we union all those values to get our
553 // own. This one-shot approach works because iteration is in
554 // dependency order. I.e. a chain A: B: C will visit C, B, A.
555for scc_a in self.constraint_sccs.all_sccs() {
556// Walk each SCC `B` such that `A: B`...
557for &scc_b in self.constraint_sccs.successors(scc_a) {
558debug!(?scc_b);
559self.scc_values.add_region(scc_a, scc_b);
560 }
561 }
562 }
563564/// Returns `true` if all the placeholders in the value of `scc_b` are nameable
565 /// in `scc_a`. Used during constraint propagation, and only once
566 /// the value of `scc_b` has been computed.
567fn can_name_all_placeholders(
568&self,
569 scc_a: ConstraintSccIndex,
570 scc_b: ConstraintSccIndex,
571 ) -> bool {
572self.scc_annotations[scc_a].can_name_all_placeholders(self.scc_annotations[scc_b])
573 }
574575/// Once regions have been propagated, this method is used to see
576 /// whether the "type tests" produced by typeck were satisfied;
577 /// type tests encode type-outlives relationships like `T:
578 /// 'a`. See `TypeTest` for more details.
579fn check_type_tests(
580&self,
581 infcx: &InferCtxt<'tcx>,
582mut propagated_outlives_requirements: Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
583 errors_buffer: &mut RegionErrors<'tcx>,
584 ) {
585let tcx = infcx.tcx;
586587// Sometimes we register equivalent type-tests that would
588 // result in basically the exact same error being reported to
589 // the user. Avoid that.
590let mut deduplicate_errors = FxIndexSet::default();
591let mut failed_type_tests = Vec::new();
592593for type_test in &self.type_tests {
594{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:594",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(594u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("check_type_test: {0:?}",
type_test) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("check_type_test: {:?}", type_test);
595596let generic_ty = type_test.generic_kind.to_ty(tcx);
597if self.eval_verify_bound(
598 infcx,
599 generic_ty,
600 type_test.lower_bound,
601&type_test.verify_bound,
602 ) {
603continue;
604 }
605606if let Some(propagated_outlives_requirements) = &mut propagated_outlives_requirements
607 && self.try_promote_type_test(infcx, type_test, propagated_outlives_requirements)
608 {
609continue;
610 }
611612// Type-test failed. Collect it so we can suppress redundant errors below.
613let erased_generic_kind = infcx.tcx.erase_and_anonymize_regions(type_test.generic_kind);
614 failed_type_tests.push((erased_generic_kind, type_test));
615 }
616617// An async body can produce both `G: 'static` and `G: 'a` type-test failures at
618 // the same span, as in `tests/ui/async-await/spurious-static-bound-issue-115376.rs`.
619 // Reporting the weaker bound adds a redundant diagnostic and suggests a lifetime
620 // bound that cannot fix the missing `G: 'static` requirement. Keep the `'static`
621 // error and suppress weaker failures for the same erased generic kind and span.
622 // This is a diagnostic heuristic, using the same erasure as deduplication below.
623 //
624 // Collect all failed `'static` bounds before reporting errors so suppression does
625 // not depend on the order of the type tests. Compare SCCs because a lower-bound
626 // region can be equivalent to `'static` without being `fr_static` itself.
627let static_scc = self.constraint_sccs.scc(self.universal_regions().fr_static);
628let static_bound_errors: FxIndexSet<_> = failed_type_tests629 .iter()
630 .filter_map(|&(erased_generic_kind, type_test)| {
631if self.constraint_sccs.scc(type_test.lower_bound) == static_scc {
632Some((erased_generic_kind, type_test.span))
633 } else {
634None635 }
636 })
637 .collect();
638639// If `G: 'static` failed at this span, then same-span `G: 'a` failures are weaker.
640for (erased_generic_kind, type_test) in failed_type_tests {
641if self.constraint_sccs.scc(type_test.lower_bound) != static_scc
642 && static_bound_errors.contains(&(erased_generic_kind, type_test.span))
643 {
644continue;
645 }
646647// Skip duplicate-ish errors.
648if deduplicate_errors.insert((
649 erased_generic_kind,
650 type_test.lower_bound,
651 type_test.span,
652 )) {
653{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:653",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(653u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("check_type_test: reporting error for erased_generic_kind={0:?}, lower_bound_region={1:?}, type_test.span={2:?}",
erased_generic_kind, type_test.lower_bound, type_test.span)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
654"check_type_test: reporting error for erased_generic_kind={:?}, \
655 lower_bound_region={:?}, \
656 type_test.span={:?}",
657 erased_generic_kind, type_test.lower_bound, type_test.span,
658 );
659660 errors_buffer.push(RegionErrorKind::TypeTestError { type_test: type_test.clone() });
661 }
662 }
663 }
664665/// Invoked when we have some type-test (e.g., `T: 'X`) that we cannot
666 /// prove to be satisfied. If this is a closure, we will attempt to
667 /// "promote" this type-test into our `ClosureRegionRequirements` and
668 /// hence pass it up the creator. To do this, we have to phrase the
669 /// type-test in terms of external free regions, as local free
670 /// regions are not nameable by the closure's creator.
671 ///
672 /// Promotion works as follows: we first check that the type `T`
673 /// contains only regions that the creator knows about. If this is
674 /// true, then -- as a consequence -- we know that all regions in
675 /// the type `T` are free regions that outlive the closure body. If
676 /// false, then promotion fails.
677 ///
678 /// Once we've promoted T, we have to "promote" `'X` to some region
679 /// that is "external" to the closure. Generally speaking, a region
680 /// may be the union of some points in the closure body as well as
681 /// various free lifetimes. We can ignore the points in the closure
682 /// body: if the type T can be expressed in terms of external regions,
683 /// we know it outlives the points in the closure body. That
684 /// just leaves the free regions.
685 ///
686 /// The idea then is to lower the `T: 'X` constraint into multiple
687 /// bounds -- e.g., if `'X` is the union of two free lifetimes,
688 /// `'1` and `'2`, then we would create `T: '1` and `T: '2`.
689{}
#[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("try_promote_type_test",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(689u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("type_test")
}> =
::tracing::__macro_support::FieldName::new("type_test");
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(&type_test)
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: bool = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = infcx.tcx;
let TypeTest {
generic_kind, lower_bound, span: blame_span, verify_bound: _
} = *type_test;
let generic_ty = generic_kind.to_ty(tcx);
let Some(subject) =
self.try_promote_type_test_subject(infcx,
generic_ty) else { return false; };
let r_scc = self.constraint_sccs.scc(lower_bound);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:705",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(705u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("lower_bound = {0:?} r_scc={1:?} universe={2:?}",
lower_bound, r_scc, self.max_nameable_universe(r_scc)) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};
if let Some(p) =
self.scc_values.placeholders_contained_in(r_scc).next() {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:718",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(718u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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 placeholder in higher universe: {0:?}, requiring \'static",
p) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let static_r = self.universal_regions().fr_static;
propagated_outlives_requirements.push(ClosureOutlivesRequirement {
subject,
outlived_free_region: static_r,
blame_span,
category: ConstraintCategory::Boring,
});
return true;
}
let mut found_outlived_universal_region = false;
for ur in self.scc_values.universal_regions_outlived_by(r_scc) {
found_outlived_universal_region = true;
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:738",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(738u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("universal_region_outlived_by ur={0:?}",
ur) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let non_local_ub =
self.universal_region_relations.non_local_upper_bounds(ur);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:740",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(740u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("non_local_ub")
}> =
::tracing::__macro_support::FieldName::new("non_local_ub");
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(&non_local_ub)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
for upper_bound in non_local_ub {
if true {
if !self.universal_regions().is_universal_region(upper_bound)
{
::core::panicking::panic("assertion failed: self.universal_regions().is_universal_region(upper_bound)")
};
};
if true {
if !!self.universal_regions().is_local_free_region(upper_bound)
{
::core::panicking::panic("assertion failed: !self.universal_regions().is_local_free_region(upper_bound)")
};
};
let requirement =
ClosureOutlivesRequirement {
subject,
outlived_free_region: upper_bound,
blame_span,
category: ConstraintCategory::Boring,
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:756",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(756u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("requirement")
}> =
::tracing::__macro_support::FieldName::new("requirement");
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(&format_args!("adding closure requirement")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&requirement)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
propagated_outlives_requirements.push(requirement);
}
}
if !found_outlived_universal_region {
::core::panicking::panic("assertion failed: found_outlived_universal_region")
};
true
}
}
}#[instrument(level = "debug", skip(self, infcx, propagated_outlives_requirements))]690fn try_promote_type_test(
691&self,
692 infcx: &InferCtxt<'tcx>,
693 type_test: &TypeTest<'tcx>,
694 propagated_outlives_requirements: &mut Vec<ClosureOutlivesRequirement<'tcx>>,
695 ) -> bool {
696let tcx = infcx.tcx;
697let TypeTest { generic_kind, lower_bound, span: blame_span, verify_bound: _ } = *type_test;
698699let generic_ty = generic_kind.to_ty(tcx);
700let Some(subject) = self.try_promote_type_test_subject(infcx, generic_ty) else {
701return false;
702 };
703704let r_scc = self.constraint_sccs.scc(lower_bound);
705debug!(
706"lower_bound = {:?} r_scc={:?} universe={:?}",
707 lower_bound,
708 r_scc,
709self.max_nameable_universe(r_scc)
710 );
711// If the type test requires that `T: 'a` where `'a` is a
712 // placeholder from another universe, that effectively requires
713 // `T: 'static`, so we have to propagate that requirement.
714 //
715 // It doesn't matter *what* universe because the promoted `T` will
716 // always be in the root universe.
717if let Some(p) = self.scc_values.placeholders_contained_in(r_scc).next() {
718debug!("encountered placeholder in higher universe: {:?}, requiring 'static", p);
719let static_r = self.universal_regions().fr_static;
720 propagated_outlives_requirements.push(ClosureOutlivesRequirement {
721 subject,
722 outlived_free_region: static_r,
723 blame_span,
724 category: ConstraintCategory::Boring,
725 });
726727// we can return here -- the code below might push add'l constraints
728 // but they would all be weaker than this one.
729return true;
730 }
731732// For each region outlived by lower_bound find a non-local,
733 // universal region (it may be the same region) and add it to
734 // `ClosureOutlivesRequirement`.
735let mut found_outlived_universal_region = false;
736for ur in self.scc_values.universal_regions_outlived_by(r_scc) {
737 found_outlived_universal_region = true;
738debug!("universal_region_outlived_by ur={:?}", ur);
739let non_local_ub = self.universal_region_relations.non_local_upper_bounds(ur);
740debug!(?non_local_ub);
741742// This is slightly too conservative. To show T: '1, given `'2: '1`
743 // and `'3: '1` we only need to prove that T: '2 *or* T: '3, but to
744 // avoid potential non-determinism we approximate this by requiring
745 // T: '1 and T: '2.
746for upper_bound in non_local_ub {
747debug_assert!(self.universal_regions().is_universal_region(upper_bound));
748debug_assert!(!self.universal_regions().is_local_free_region(upper_bound));
749750let requirement = ClosureOutlivesRequirement {
751 subject,
752 outlived_free_region: upper_bound,
753 blame_span,
754 category: ConstraintCategory::Boring,
755 };
756debug!(?requirement, "adding closure requirement");
757 propagated_outlives_requirements.push(requirement);
758 }
759 }
760// If we succeed to promote the subject, i.e. it only contains non-local regions,
761 // and fail to prove the type test inside of the closure, the `lower_bound` has to
762 // also be at least as large as some universal region, as the type test is otherwise
763 // trivial.
764assert!(found_outlived_universal_region);
765true
766}
767768/// When we promote a type test `T: 'r`, we have to replace all region
769 /// variables in the type `T` with an equal universal region from the
770 /// closure signature.
771 /// This is not always possible, so this is a fallible process.
772{}
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("try_promote_type_test_subject",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(772u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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:
Option<ClosureOutlivesSubject<'tcx>> = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = infcx.tcx;
let mut failed = false;
let ty =
fold_regions(tcx, ty,
|r, _depth|
{
let r_vid = self.to_region_vid(r);
let r_scc = self.constraint_sccs.scc(r_vid);
self.scc_values.universal_regions_outlived_by(r_scc).filter(|&u_r|
!self.universal_regions().is_local_free_region(u_r)).find(|&u_r|
self.eval_equal(u_r,
r_vid)).map(|u_r|
ty::Region::new_var(tcx,
u_r)).unwrap_or_else(|| { failed = true; r })
});
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:802",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(802u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("try_promote_type_test_subject: folded ty = {0:?}",
ty) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
if failed { return None; }
Some(ClosureOutlivesSubject::Ty(ClosureOutlivesSubjectTy::bind(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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:772",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(772u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
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(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip(self, infcx), ret)]773fn try_promote_type_test_subject(
774&self,
775 infcx: &InferCtxt<'tcx>,
776 ty: Ty<'tcx>,
777 ) -> Option<ClosureOutlivesSubject<'tcx>> {
778let tcx = infcx.tcx;
779let mut failed = false;
780let ty = fold_regions(tcx, ty, |r, _depth| {
781let r_vid = self.to_region_vid(r);
782let r_scc = self.constraint_sccs.scc(r_vid);
783784// The challenge is this. We have some region variable `r`
785 // whose value is a set of CFG points and universal
786 // regions. We want to find if that set is *equivalent* to
787 // any of the named regions found in the closure.
788 // To do so, we simply check every candidate `u_r` for equality.
789self.scc_values
790 .universal_regions_outlived_by(r_scc)
791 .filter(|&u_r| !self.universal_regions().is_local_free_region(u_r))
792 .find(|&u_r| self.eval_equal(u_r, r_vid))
793 .map(|u_r| ty::Region::new_var(tcx, u_r))
794// In case we could not find a named region to map to,
795 // we will return `None` below.
796.unwrap_or_else(|| {
797 failed = true;
798 r
799 })
800 });
801802debug!("try_promote_type_test_subject: folded ty = {:?}", ty);
803804// This will be true if we failed to promote some region.
805if failed {
806return None;
807 }
808809Some(ClosureOutlivesSubject::Ty(ClosureOutlivesSubjectTy::bind(tcx, ty)))
810 }
811812/// Like `universal_upper_bound`, but returns an approximation more suitable
813 /// for diagnostics. If `r` contains multiple disjoint universal regions
814 /// (e.g. 'a and 'b in `fn foo<'a, 'b> { ... }`, we pick the lower-numbered region.
815 /// This corresponds to picking named regions over unnamed regions
816 /// (e.g. picking early-bound regions over a closure late-bound region).
817 ///
818 /// This means that the returned value may not be a true upper bound, since
819 /// only 'static is known to outlive disjoint universal regions.
820 /// Therefore, this method should only be used in diagnostic code,
821 /// where displaying *some* named universal region is better than
822 /// falling back to 'static.
823{}
#[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("approx_universal_upper_bound",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(823u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("r")
}> =
::tracing::__macro_support::FieldName::new("r");
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(&r)
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: RegionVid = 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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:825",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(825u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("{0}",
self.region_value_str(r)) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};
let mut lub = self.universal_regions().fr_fn_body;
let r_scc = self.constraint_sccs.scc(r);
let static_r = self.universal_regions().fr_static;
for ur in self.scc_values.universal_regions_outlived_by(r_scc) {
let new_lub =
self.universal_region_relations.postdom_upper_bound(lub,
ur);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:834",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(834u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ur")
}> =
::tracing::__macro_support::FieldName::new("ur");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("lub")
}> =
::tracing::__macro_support::FieldName::new("lub");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("new_lub")
}> =
::tracing::__macro_support::FieldName::new("new_lub");
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(&ur)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&lub)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&new_lub)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
if ur != static_r && lub != static_r && new_lub == static_r {
if self.region_definition(ur).external_name.is_some() {
lub = ur;
} else if self.region_definition(lub).external_name.is_some()
{} else { lub = std::cmp::min(ur, lub); }
} else { lub = new_lub; }
}
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:858",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(858u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("r")
}> =
::tracing::__macro_support::FieldName::new("r");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("lub")
}> =
::tracing::__macro_support::FieldName::new("lub");
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(&r)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&lub)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
lub
}
}
}#[instrument(level = "debug", skip(self))]824pub(crate) fn approx_universal_upper_bound(&self, r: RegionVid) -> RegionVid {
825debug!("{}", self.region_value_str(r));
826827// Find the smallest universal region that contains all other
828 // universal regions within `region`.
829let mut lub = self.universal_regions().fr_fn_body;
830let r_scc = self.constraint_sccs.scc(r);
831let static_r = self.universal_regions().fr_static;
832for ur in self.scc_values.universal_regions_outlived_by(r_scc) {
833let new_lub = self.universal_region_relations.postdom_upper_bound(lub, ur);
834debug!(?ur, ?lub, ?new_lub);
835// The upper bound of two non-static regions is static: this
836 // means we know nothing about the relationship between these
837 // two regions. Pick a 'better' one to use when constructing
838 // a diagnostic
839if ur != static_r && lub != static_r && new_lub == static_r {
840// Prefer the region with an `external_name` - this
841 // indicates that the region is early-bound, so working with
842 // it can produce a nicer error.
843if self.region_definition(ur).external_name.is_some() {
844 lub = ur;
845 } else if self.region_definition(lub).external_name.is_some() {
846// Leave lub unchanged
847} else {
848// If we get here, we don't have any reason to prefer
849 // one region over the other. Just pick the
850 // one with the lower index for now.
851lub = std::cmp::min(ur, lub);
852 }
853 } else {
854 lub = new_lub;
855 }
856 }
857858debug!(?r, ?lub);
859860 lub
861 }
862863/// Tests if `test` is true when applied to `lower_bound` at
864 /// `point`.
865fn eval_verify_bound(
866&self,
867 infcx: &InferCtxt<'tcx>,
868 generic_ty: Ty<'tcx>,
869 lower_bound: RegionVid,
870 verify_bound: &VerifyBound<'tcx>,
871 ) -> bool {
872{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:872",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(872u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("eval_verify_bound(lower_bound={0:?}, verify_bound={1:?})",
lower_bound, verify_bound) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("eval_verify_bound(lower_bound={:?}, verify_bound={:?})", lower_bound, verify_bound);
873874match verify_bound {
875 VerifyBound::IfEq(verify_if_eq_b) => {
876self.eval_if_eq(infcx, generic_ty, lower_bound, *verify_if_eq_b)
877 }
878879 VerifyBound::IsEmpty => {
880let lower_bound_scc = self.constraint_sccs.scc(lower_bound);
881self.scc_values.elements_contained_in(lower_bound_scc).next().is_none()
882 }
883884 VerifyBound::OutlivedBy(r) => {
885let r_vid = self.to_region_vid(*r);
886self.eval_outlives(r_vid, lower_bound)
887 }
888889 VerifyBound::AnyBound(verify_bounds) => verify_bounds.iter().any(|verify_bound| {
890self.eval_verify_bound(infcx, generic_ty, lower_bound, verify_bound)
891 }),
892893 VerifyBound::AllBounds(verify_bounds) => verify_bounds.iter().all(|verify_bound| {
894self.eval_verify_bound(infcx, generic_ty, lower_bound, verify_bound)
895 }),
896 }
897 }
898899fn eval_if_eq(
900&self,
901 infcx: &InferCtxt<'tcx>,
902 generic_ty: Ty<'tcx>,
903 lower_bound: RegionVid,
904 verify_if_eq_b: ty::Binder<'tcx, VerifyIfEq<'tcx>>,
905 ) -> bool {
906let generic_ty = self.normalize_to_scc_representatives(infcx.tcx, generic_ty);
907let verify_if_eq_b = self.normalize_to_scc_representatives(infcx.tcx, verify_if_eq_b);
908match test_type_match::extract_verify_if_eq(infcx.tcx, &verify_if_eq_b, generic_ty) {
909Some(r) => {
910let r_vid = self.to_region_vid(r);
911self.eval_outlives(r_vid, lower_bound)
912 }
913None => false,
914 }
915 }
916917/// This is a conservative normalization procedure. It takes every
918 /// free region in `value` and replaces it with the
919 /// "representative" of its SCC (see `scc_representatives` field).
920 /// We are guaranteed that if two values normalize to the same
921 /// thing, then they are equal; this is a conservative check in
922 /// that they could still be equal even if they normalize to
923 /// different results. (For example, there might be two regions
924 /// with the same value that are not in the same SCC).
925 ///
926 /// N.B., this is not an ideal approach and I would like to revisit
927 /// it. However, it works pretty well in practice. In particular,
928 /// this is needed to deal with projection outlives bounds like
929 ///
930 /// ```text
931 /// <T as Foo<'0>>::Item: '1
932 /// ```
933 ///
934 /// In particular, this routine winds up being important when
935 /// there are bounds like `where <T as Foo<'a>>::Item: 'b` in the
936 /// environment. In this case, if we can show that `'0 == 'a`,
937 /// and that `'b: '1`, then we know that the clause is
938 /// satisfied. In such cases, particularly due to limitations of
939 /// the trait solver =), we usually wind up with a where-clause like
940 /// `T: Foo<'a>` in scope, which thus forces `'0 == 'a` to be added as
941 /// a constraint, and thus ensures that they are in the same SCC.
942 ///
943 /// So why can't we do a more correct routine? Well, we could
944 /// *almost* use the `relate_tys` code, but the way it is
945 /// currently setup it creates inference variables to deal with
946 /// higher-ranked things and so forth, and right now the inference
947 /// context is not permitted to make more inference variables. So
948 /// we use this kind of hacky solution.
949fn normalize_to_scc_representatives<T>(&self, tcx: TyCtxt<'tcx>, value: T) -> T
950where
951T: TypeFoldable<TyCtxt<'tcx>>,
952 {
953fold_regions(tcx, value, |r, _db| {
954let vid = self.to_region_vid(r);
955let scc = self.constraint_sccs.scc(vid);
956let repr = self.scc_representative(scc);
957 ty::Region::new_var(tcx, repr)
958 })
959 }
960961/// Evaluate whether `sup_region == sub_region`.
962 ///
963 /// Panics if called before `solve()` executes,
964// This is `pub` because it's used by unstable external borrowck data users, see `consumers.rs`.
965pub fn eval_equal(&self, r1: RegionVid, r2: RegionVid) -> bool {
966self.eval_outlives(r1, r2) && self.eval_outlives(r2, r1)
967 }
968969/// Evaluate whether `sup_region: sub_region`.
970 ///
971 /// Panics if called before `solve()` executes,
972// This is `pub` because it's used by unstable external borrowck data users, see `consumers.rs`.
973{}
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("eval_outlives",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(973u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("sup_region")
}> =
::tracing::__macro_support::FieldName::new("sup_region");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("sub_region")
}> =
::tracing::__macro_support::FieldName::new("sub_region");
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(&sup_region)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&sub_region)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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: bool = 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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:975",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(975u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("sup_region\'s value = {0:?} universal={1:?}",
self.region_value_str(sup_region),
self.universal_regions().is_universal_region(sup_region)) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:980",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(980u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("sub_region\'s value = {0:?} universal={1:?}",
self.region_value_str(sub_region),
self.universal_regions().is_universal_region(sub_region)) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};
let sub_region_scc = self.constraint_sccs.scc(sub_region);
let sup_region_scc = self.constraint_sccs.scc(sup_region);
if sub_region_scc == sup_region_scc {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:990",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(990u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("{0:?}: {1:?} holds trivially; they are in the same SCC",
sup_region, sub_region) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
return true;
}
let fr_static = self.universal_regions().fr_static;
if sub_region != fr_static &&
!self.can_name_all_placeholders(sup_region_scc,
sub_region_scc) {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:1004",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1004u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("sub universe `{0:?}` is not nameable by super `{1:?}`, promoting to static",
sub_region_scc, sup_region_scc) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};
return self.eval_outlives(sup_region, fr_static);
}
let universal_outlives =
self.scc_values.universal_regions_outlived_by(sub_region_scc).all(|r1|
{
self.scc_values.universal_regions_outlived_by(sup_region_scc).any(|r2|
self.universal_region_relations.outlives(r2, r1))
});
if !universal_outlives {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:1026",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1026u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("sub region contains a universal region not present in super")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
return false;
}
if self.universal_regions().is_universal_region(sup_region)
{
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:1035",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1035u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("super is universal and hence contains all points")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
return true;
}
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:1039",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1039u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("comparison between points in sup/sub")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
self.scc_values.contains_points(sup_region_scc,
sub_region_scc)
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:973",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(973u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
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(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(skip(self), level = "debug", ret)]974pub fn eval_outlives(&self, sup_region: RegionVid, sub_region: RegionVid) -> bool {
975debug!(
976"sup_region's value = {:?} universal={:?}",
977self.region_value_str(sup_region),
978self.universal_regions().is_universal_region(sup_region),
979 );
980debug!(
981"sub_region's value = {:?} universal={:?}",
982self.region_value_str(sub_region),
983self.universal_regions().is_universal_region(sub_region),
984 );
985986let sub_region_scc = self.constraint_sccs.scc(sub_region);
987let sup_region_scc = self.constraint_sccs.scc(sup_region);
988989if sub_region_scc == sup_region_scc {
990debug!("{sup_region:?}: {sub_region:?} holds trivially; they are in the same SCC");
991return true;
992 }
993994let fr_static = self.universal_regions().fr_static;
995996// If we are checking that `'sup: 'sub`, and `'sub` contains
997 // some placeholder that `'sup` cannot name, then this is only
998 // true if `'sup` outlives static.
999 //
1000 // Avoid infinite recursion if `sub_region` is already `'static`
1001if sub_region != fr_static
1002 && !self.can_name_all_placeholders(sup_region_scc, sub_region_scc)
1003 {
1004debug!(
1005"sub universe `{sub_region_scc:?}` is not nameable \
1006 by super `{sup_region_scc:?}`, promoting to static",
1007 );
10081009return self.eval_outlives(sup_region, fr_static);
1010 }
10111012// Both the `sub_region` and `sup_region` consist of the union
1013 // of some number of universal regions (along with the union
1014 // of various points in the CFG; ignore those points for
1015 // now). Therefore, the sup-region outlives the sub-region if,
1016 // for each universal region R1 in the sub-region, there
1017 // exists some region R2 in the sup-region that outlives R1.
1018let universal_outlives =
1019self.scc_values.universal_regions_outlived_by(sub_region_scc).all(|r1| {
1020self.scc_values
1021 .universal_regions_outlived_by(sup_region_scc)
1022 .any(|r2| self.universal_region_relations.outlives(r2, r1))
1023 });
10241025if !universal_outlives {
1026debug!("sub region contains a universal region not present in super");
1027return false;
1028 }
10291030// Now we have to compare all the points in the sub region and make
1031 // sure they exist in the sup region.
10321033if self.universal_regions().is_universal_region(sup_region) {
1034// Micro-opt: universal regions contain all points.
1035debug!("super is universal and hence contains all points");
1036return true;
1037 }
10381039debug!("comparison between points in sup/sub");
10401041self.scc_values.contains_points(sup_region_scc, sub_region_scc)
1042 }
10431044/// Once regions have been propagated, this method is used to see
1045 /// whether any of the constraints were too strong. In particular,
1046 /// we want to check for a case where a universally quantified
1047 /// region exceeded its bounds. Consider:
1048 /// ```compile_fail
1049 /// fn foo<'a, 'b>(x: &'a u32) -> &'b u32 { x }
1050 /// ```
1051 /// In this case, returning `x` requires `&'a u32 <: &'b u32`
1052 /// and hence we establish (transitively) a constraint that
1053 /// `'a: 'b`. The `propagate_constraints` code above will
1054 /// therefore add `end('a)` into the region for `'b` -- but we
1055 /// have no evidence that `'b` outlives `'a`, so we want to report
1056 /// an error.
1057 ///
1058 /// If `propagated_outlives_requirements` is `Some`, then we will
1059 /// push unsatisfied obligations into there. Otherwise, we'll
1060 /// report them as errors.
1061fn check_universal_regions(
1062&self,
1063mut propagated_outlives_requirements: Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
1064 errors_buffer: &mut RegionErrors<'tcx>,
1065 ) {
1066for (fr, fr_definition) in self.definitions.iter_enumerated() {
1067{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:1067",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1067u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("fr")
}> =
::tracing::__macro_support::FieldName::new("fr");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("fr_definition")
}> =
::tracing::__macro_support::FieldName::new("fr_definition");
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(&fr)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fr_definition)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?fr, ?fr_definition);
1068match fr_definition.origin {
1069 NllRegionVariableOrigin::FreeRegion => {
1070// Go through each of the universal regions `fr` and check that
1071 // they did not grow too large, accumulating any requirements
1072 // for our caller into the `outlives_requirements` vector.
1073self.check_universal_region(
1074 fr,
1075&mut propagated_outlives_requirements,
1076 errors_buffer,
1077 );
1078 }
10791080 NllRegionVariableOrigin::Placeholder(placeholder) => {
1081self.check_bound_universal_region(fr, placeholder, errors_buffer);
1082 }
10831084 NllRegionVariableOrigin::Existential { .. } => {
1085// nothing to check here
1086}
1087 }
1088 }
1089 }
10901091/// Checks if Polonius has found any unexpected free region relations.
1092 ///
1093 /// In Polonius terms, a "subset error" (or "illegal subset relation error") is the equivalent
1094 /// of NLL's "checking if any region constraints were too strong": a placeholder origin `'a`
1095 /// was unexpectedly found to be a subset of another placeholder origin `'b`, and means in NLL
1096 /// terms that the "longer free region" `'a` outlived the "shorter free region" `'b`.
1097 ///
1098 /// More details can be found in this blog post by Niko:
1099 /// <https://smallcultfollowing.com/babysteps/blog/2019/01/17/polonius-and-region-errors/>
1100 ///
1101 /// In the canonical example
1102 /// ```compile_fail
1103 /// fn foo<'a, 'b>(x: &'a u32) -> &'b u32 { x }
1104 /// ```
1105 /// returning `x` requires `&'a u32 <: &'b u32` and hence we establish (transitively) a
1106 /// constraint that `'a: 'b`. It is an error that we have no evidence that this
1107 /// constraint holds.
1108 ///
1109 /// If `propagated_outlives_requirements` is `Some`, then we will
1110 /// push unsatisfied obligations into there. Otherwise, we'll
1111 /// report them as errors.
1112fn check_polonius_subset_errors(
1113&self,
1114mut propagated_outlives_requirements: Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
1115 errors_buffer: &mut RegionErrors<'tcx>,
1116 polonius_output: &PoloniusOutput,
1117 ) {
1118{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:1118",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1118u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("check_polonius_subset_errors: {0} subset_errors",
polonius_output.subset_errors.len()) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
1119"check_polonius_subset_errors: {} subset_errors",
1120 polonius_output.subset_errors.len()
1121 );
11221123// Similarly to `check_universal_regions`: a free region relation, which was not explicitly
1124 // declared ("known") was found by Polonius, so emit an error, or propagate the
1125 // requirements for our caller into the `propagated_outlives_requirements` vector.
1126 //
1127 // Polonius doesn't model regions ("origins") as CFG-subsets or durations, but the
1128 // `longer_fr` and `shorter_fr` terminology will still be used here, for consistency with
1129 // the rest of the NLL infrastructure. The "subset origin" is the "longer free region",
1130 // and the "superset origin" is the outlived "shorter free region".
1131 //
1132 // Note: Polonius will produce a subset error at every point where the unexpected
1133 // `longer_fr`'s "placeholder loan" is contained in the `shorter_fr`. This can be helpful
1134 // for diagnostics in the future, e.g. to point more precisely at the key locations
1135 // requiring this constraint to hold. However, the error and diagnostics code downstream
1136 // expects that these errors are not duplicated (and that they are in a certain order).
1137 // Otherwise, diagnostics messages such as the ones giving names like `'1` to elided or
1138 // anonymous lifetimes for example, could give these names differently, while others like
1139 // the outlives suggestions or the debug output from `#[rustc_regions]` would be
1140 // duplicated. The polonius subset errors are deduplicated here, while keeping the
1141 // CFG-location ordering.
1142 // We can iterate the HashMap here because the result is sorted afterwards.
1143#[allow(rustc::potential_query_instability)]
1144let mut subset_errors: Vec<_> = polonius_output1145 .subset_errors
1146 .iter()
1147 .flat_map(|(_location, subset_errors)| subset_errors.iter())
1148 .collect();
1149subset_errors.sort();
1150subset_errors.dedup();
11511152for &(longer_fr, shorter_fr) in subset_errors.into_iter() {
1153{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:1153",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1153u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("check_polonius_subset_errors: subset_error longer_fr={0:?},shorter_fr={1:?}",
longer_fr, shorter_fr) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
1154"check_polonius_subset_errors: subset_error longer_fr={:?},\
1155 shorter_fr={:?}",
1156 longer_fr, shorter_fr
1157 );
11581159let propagated = self.try_propagate_universal_region_error(
1160 longer_fr.into(),
1161 shorter_fr.into(),
1162&mut propagated_outlives_requirements,
1163 );
1164if propagated == RegionRelationCheckResult::Error {
1165 errors_buffer.push(RegionErrorKind::RegionError {
1166 longer_fr: longer_fr.into(),
1167 shorter_fr: shorter_fr.into(),
1168 fr_origin: NllRegionVariableOrigin::FreeRegion,
1169 is_reported: true,
1170 });
1171 }
1172 }
11731174// Handle the placeholder errors as usual, until the chalk-rustc-polonius triumvirate has
1175 // a more complete picture on how to separate this responsibility.
1176for (fr, fr_definition) in self.definitions.iter_enumerated() {
1177match fr_definition.origin {
1178 NllRegionVariableOrigin::FreeRegion => {
1179// handled by polonius above
1180}
11811182 NllRegionVariableOrigin::Placeholder(placeholder) => {
1183self.check_bound_universal_region(fr, placeholder, errors_buffer);
1184 }
11851186 NllRegionVariableOrigin::Existential { .. } => {
1187// nothing to check here
1188}
1189 }
1190 }
1191 }
11921193/// The largest universe of any region nameable from this SCC.
1194fn max_nameable_universe(&self, scc: ConstraintSccIndex) -> UniverseIndex {
1195self.scc_annotations[scc].max_nameable_universe()
1196 }
11971198/// Checks the final value for the free region `fr` to see if it
1199 /// grew too large. In particular, examine what `end(X)` points
1200 /// wound up in `fr`'s final value; for each `end(X)` where `X !=
1201 /// fr`, we want to check that `fr: X`. If not, that's either an
1202 /// error, or something we have to propagate to our creator.
1203 ///
1204 /// Things that are to be propagated are accumulated into the
1205 /// `outlives_requirements` vector.
1206{}
#[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_universal_region",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1206u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("longer_fr")
}> =
::tracing::__macro_support::FieldName::new("longer_fr");
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(&longer_fr)
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;
}
{
let longer_fr_scc = self.constraint_sccs.scc(longer_fr);
if !self.max_nameable_universe(longer_fr_scc).is_root() {
::core::panicking::panic("assertion failed: self.max_nameable_universe(longer_fr_scc).is_root()")
};
let representative = self.scc_representative(longer_fr_scc);
if representative != longer_fr {
if let RegionRelationCheckResult::Error =
self.check_universal_region_relation(longer_fr,
representative, propagated_outlives_requirements) {
errors_buffer.push(RegionErrorKind::RegionError {
longer_fr,
shorter_fr: representative,
fr_origin: NllRegionVariableOrigin::FreeRegion,
is_reported: true,
});
}
return;
}
let mut error_reported = false;
for shorter_fr in
self.scc_values.universal_regions_outlived_by(longer_fr_scc) {
if let RegionRelationCheckResult::Error =
self.check_universal_region_relation(longer_fr, shorter_fr,
propagated_outlives_requirements) {
errors_buffer.push(RegionErrorKind::RegionError {
longer_fr,
shorter_fr,
fr_origin: NllRegionVariableOrigin::FreeRegion,
is_reported: !error_reported,
});
error_reported = true;
}
}
}
}
}#[instrument(skip(self, propagated_outlives_requirements, errors_buffer), level = "debug")]1207fn check_universal_region(
1208&self,
1209 longer_fr: RegionVid,
1210 propagated_outlives_requirements: &mut Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
1211 errors_buffer: &mut RegionErrors<'tcx>,
1212 ) {
1213let longer_fr_scc = self.constraint_sccs.scc(longer_fr);
12141215// Because this free region must be in the ROOT universe, we
1216 // know it cannot contain any bound universes.
1217assert!(self.max_nameable_universe(longer_fr_scc).is_root());
12181219// Only check all of the relations for the main representative of each
1220 // SCC, otherwise just check that we outlive said representative. This
1221 // reduces the number of redundant relations propagated out of
1222 // closures.
1223 // Note that the representative will be a universal region if there is
1224 // one in this SCC, so we will always check the representative here.
1225let representative = self.scc_representative(longer_fr_scc);
1226if representative != longer_fr {
1227if let RegionRelationCheckResult::Error = self.check_universal_region_relation(
1228 longer_fr,
1229 representative,
1230 propagated_outlives_requirements,
1231 ) {
1232 errors_buffer.push(RegionErrorKind::RegionError {
1233 longer_fr,
1234 shorter_fr: representative,
1235 fr_origin: NllRegionVariableOrigin::FreeRegion,
1236 is_reported: true,
1237 });
1238 }
1239return;
1240 }
12411242// Find every region `o` such that `fr: o`
1243 // (because `fr` includes `end(o)`).
1244let mut error_reported = false;
1245for shorter_fr in self.scc_values.universal_regions_outlived_by(longer_fr_scc) {
1246if let RegionRelationCheckResult::Error = self.check_universal_region_relation(
1247 longer_fr,
1248 shorter_fr,
1249 propagated_outlives_requirements,
1250 ) {
1251// We only report the first region error. Subsequent errors are hidden so as
1252 // not to overwhelm the user, but we do record them so as to potentially print
1253 // better diagnostics elsewhere...
1254errors_buffer.push(RegionErrorKind::RegionError {
1255 longer_fr,
1256 shorter_fr,
1257 fr_origin: NllRegionVariableOrigin::FreeRegion,
1258 is_reported: !error_reported,
1259 });
12601261 error_reported = true;
1262 }
1263 }
1264 }
12651266/// Checks that we can prove that `longer_fr: shorter_fr`. If we can't we attempt to propagate
1267 /// the constraint outward (e.g. to a closure environment), but if that fails, there is an
1268 /// error.
1269fn check_universal_region_relation(
1270&self,
1271 longer_fr: RegionVid,
1272 shorter_fr: RegionVid,
1273 propagated_outlives_requirements: &mut Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
1274 ) -> RegionRelationCheckResult {
1275// If it is known that `fr: o`, carry on.
1276if self.universal_region_relations.outlives(longer_fr, shorter_fr) {
1277 RegionRelationCheckResult::Ok1278 } else {
1279// If we are not in a context where we can't propagate errors, or we
1280 // could not shrink `fr` to something smaller, then just report an
1281 // error.
1282 //
1283 // Note: in this case, we use the unapproximated regions to report the
1284 // error. This gives better error messages in some cases.
1285self.try_propagate_universal_region_error(
1286longer_fr,
1287shorter_fr,
1288propagated_outlives_requirements,
1289 )
1290 }
1291 }
12921293/// Attempt to propagate a region error (e.g. `'a: 'b`) that is not met to a closure's
1294 /// creator. If we cannot, then the caller should report an error to the user.
1295fn try_propagate_universal_region_error(
1296&self,
1297 longer_fr: RegionVid,
1298 shorter_fr: RegionVid,
1299 propagated_outlives_requirements: &mut Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
1300 ) -> RegionRelationCheckResult {
1301if let Some(propagated_outlives_requirements) = propagated_outlives_requirements {
1302// Shrink `longer_fr` until we find some non-local regions.
1303 // We'll call them `longer_fr-` -- they are ever so slightly smaller than
1304 // `longer_fr`.
1305let longer_fr_minus = self.universal_region_relations.non_local_lower_bounds(longer_fr);
13061307{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:1307",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1307u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("try_propagate_universal_region_error: fr_minus={0:?}",
longer_fr_minus) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("try_propagate_universal_region_error: fr_minus={:?}", longer_fr_minus);
13081309// If we don't find a any non-local regions, we should error out as there is nothing
1310 // to propagate.
1311if longer_fr_minus.is_empty() {
1312return RegionRelationCheckResult::Error;
1313 }
13141315let best_blame = self.best_blame_constraint(
1316longer_fr,
1317 NllRegionVariableOrigin::FreeRegion,
1318shorter_fr,
1319 );
1320let OutlivesConstraint { category, span, .. } = best_blame.constraint();
13211322// Grow `shorter_fr` until we find some non-local regions.
1323 // We will always find at least one: `'static`. We'll call
1324 // them `shorter_fr+` -- they're ever so slightly larger
1325 // than `shorter_fr`.
1326let shorter_fr_plus =
1327self.universal_region_relations.non_local_upper_bounds(shorter_fr);
1328{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:1328",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1328u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("try_propagate_universal_region_error: shorter_fr_plus={0:?}",
shorter_fr_plus) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("try_propagate_universal_region_error: shorter_fr_plus={:?}", shorter_fr_plus);
13291330// We then create constraints `longer_fr-: shorter_fr+` that may or may not
1331 // be propagated (see below).
1332let mut constraints = ::alloc::vec::Vec::new()vec![];
1333for fr_minus in longer_fr_minus {
1334for shorter_fr_plus in &shorter_fr_plus {
1335 constraints.push((fr_minus, *shorter_fr_plus));
1336 }
1337 }
13381339// We only need to propagate at least one of the constraints for
1340 // soundness. However, we want to avoid arbitrary choices here
1341 // and currently don't support returning OR constraints.
1342 //
1343 // If any of the `shorter_fr+` regions are already outlived by `longer_fr-`,
1344 // we propagate only those.
1345 //
1346 // Consider this example (`'b: 'a` == `a -> b`), where we try to propagate `'d: 'a`:
1347 // a --> b --> d
1348 // \
1349 // \-> c
1350 // Here, `shorter_fr+` of `'a` == `['b, 'c]`.
1351 // Propagating `'d: 'b` is correct and should occur; `'d: 'c` is redundant because of
1352 // `'d: 'b` and could reject valid code.
1353 //
1354 // So we filter the constraints to regions already outlived by `longer_fr-`, but if
1355 // the filter yields an empty set, we fall back to the original one.
1356let subset: Vec<_> = constraints1357 .iter()
1358 .filter(|&&(fr_minus, shorter_fr_plus)| {
1359self.eval_outlives(fr_minus, shorter_fr_plus)
1360 })
1361 .copied()
1362 .collect();
1363let propagated_constraints = if subset.is_empty() { constraints } else { subset };
1364{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:1364",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1364u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("try_propagate_universal_region_error: constraints={0:?}",
propagated_constraints) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
1365"try_propagate_universal_region_error: constraints={:?}",
1366 propagated_constraints
1367 );
13681369if !!propagated_constraints.is_empty() {
{
::core::panicking::panic_fmt(format_args!("Expected at least one constraint to propagate here"));
}
};assert!(
1370 !propagated_constraints.is_empty(),
1371"Expected at least one constraint to propagate here"
1372);
13731374for (fr_minus, fr_plus) in propagated_constraints {
1375// Push the constraint `long_fr-: shorter_fr+`
1376propagated_outlives_requirements.push(ClosureOutlivesRequirement {
1377 subject: ClosureOutlivesSubject::Region(fr_minus),
1378 outlived_free_region: fr_plus,
1379 blame_span: *span,
1380 category: *category,
1381 });
1382 }
1383return RegionRelationCheckResult::Propagated;
1384 }
13851386 RegionRelationCheckResult::Error1387 }
13881389fn check_bound_universal_region(
1390&self,
1391 longer_fr: RegionVid,
1392 placeholder: ty::PlaceholderRegion<'tcx>,
1393 errors_buffer: &mut RegionErrors<'tcx>,
1394 ) {
1395{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:1395",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1395u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("check_bound_universal_region(fr={0:?}, placeholder={1:?})",
longer_fr, placeholder) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("check_bound_universal_region(fr={:?}, placeholder={:?})", longer_fr, placeholder,);
13961397let longer_fr_scc = self.constraint_sccs.scc(longer_fr);
1398{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:1398",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1398u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("check_bound_universal_region: longer_fr_scc={0:?}",
longer_fr_scc) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("check_bound_universal_region: longer_fr_scc={:?}", longer_fr_scc,);
13991400// If we have some bound universal region `'a`, then the only
1401 // elements it can contain is itself -- we don't know anything
1402 // else about it!
1403if let Some(error_element) = self1404 .scc_values
1405 .elements_contained_in(longer_fr_scc)
1406 .find(|e| *e != RegionElement::PlaceholderRegion(placeholder))
1407 {
1408let illegally_outlived_r = self.region_from_element(longer_fr, &error_element);
1409// Stop after the first error, it gets too noisy otherwise, and does not provide more information.
1410errors_buffer.push(RegionErrorKind::PlaceholderOutlivesIllegalRegion {
1411longer_fr,
1412illegally_outlived_r,
1413 });
1414 } else {
1415{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:1415",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1415u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("check_bound_universal_region: all bounds satisfied")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("check_bound_universal_region: all bounds satisfied");
1416 }
1417 }
14181419pub(crate) fn constraint_path_between_regions(
1420&self,
1421 from_region: RegionVid,
1422 to_region: RegionVid,
1423 ) -> Option<Vec<OutlivesConstraint<'tcx>>> {
1424if from_region == to_region {
1425bug_impl(None,
format_args!("Tried to find a path between {0:?} and itself!",
from_region), Location::caller());bug!("Tried to find a path between {from_region:?} and itself!");
1426 }
1427self.constraint_path_to(from_region, |to| to == to_region, true).map(|o| o.0)
1428 }
14291430/// Walks the graph of constraints (where `'a: 'b` is considered
1431 /// an edge `'a -> 'b`) to find a path from `from_region` to
1432 /// `to_region`.
1433 ///
1434 /// Returns: a series of constraints as well as the region `R`
1435 /// that passed the target test.
1436 /// If `include_static_outlives_all` is `true`, then the synthetic
1437 /// outlives constraints `'static -> a` for every region `a` are
1438 /// considered in the search, otherwise they are ignored.
1439{}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::INFO <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::INFO <=
::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("constraint_path_to",
"rustc_borrowck::region_infer", ::tracing::Level::INFO,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1439u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("from_region")
}> =
::tracing::__macro_support::FieldName::new("from_region");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("include_placeholder_static")
}> =
::tracing::__macro_support::FieldName::new("include_placeholder_static");
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::INFO <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::INFO <=
::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(&from_region)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&include_placeholder_static
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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:
Option<(Vec<OutlivesConstraint<'tcx>>, RegionVid)> =
loop {};
return __tracing_attr_fake_return;
}
{
self.find_constraint_path_between_regions_inner(true,
from_region, &target_test,
include_placeholder_static).or_else(||
{
self.find_constraint_path_between_regions_inner(false,
from_region, &target_test, include_placeholder_static)
})
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:1439",
"rustc_borrowck::region_infer", ::tracing::Level::INFO,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1439u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::INFO <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::INFO <=
::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(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(skip(self, target_test), ret)]1440pub(crate) fn constraint_path_to(
1441&self,
1442 from_region: RegionVid,
1443 target_test: impl Fn(RegionVid) -> bool,
1444 include_placeholder_static: bool,
1445 ) -> Option<(Vec<OutlivesConstraint<'tcx>>, RegionVid)> {
1446self.find_constraint_path_between_regions_inner(
1447true,
1448 from_region,
1449&target_test,
1450 include_placeholder_static,
1451 )
1452 .or_else(|| {
1453self.find_constraint_path_between_regions_inner(
1454false,
1455 from_region,
1456&target_test,
1457 include_placeholder_static,
1458 )
1459 })
1460 }
14611462/// The constraints we get from equating the hidden type of each use of an opaque
1463 /// with its final hidden type may end up getting preferred over other, potentially
1464 /// longer constraint paths.
1465 ///
1466 /// Given that we compute the final hidden type by relying on this existing constraint
1467 /// path, this can easily end up hiding the actual reason for why we require these regions
1468 /// to be equal.
1469 ///
1470 /// To handle this, we first look at the path while ignoring these constraints and then
1471 /// retry while considering them. This is not perfect, as the `from_region` may have already
1472 /// been partially related to its argument region, so while we rely on a member constraint
1473 /// to get a complete path, the most relevant step of that path already existed before then.
1474fn find_constraint_path_between_regions_inner(
1475&self,
1476 ignore_opaque_type_constraints: bool,
1477 from_region: RegionVid,
1478 target_test: impl Fn(RegionVid) -> bool,
1479 include_placeholder_static: bool,
1480 ) -> Option<(Vec<OutlivesConstraint<'tcx>>, RegionVid)> {
1481let mut context = IndexVec::from_elem(Trace::NotVisited, &self.definitions);
1482context[from_region] = Trace::StartRegion;
14831484let fr_static = self.universal_regions().fr_static;
14851486// Use a deque so that we do a breadth-first search. We will
1487 // stop at the first match, which ought to be the shortest
1488 // path (fewest constraints).
1489let mut deque = VecDeque::new();
1490deque.push_back(from_region);
14911492while let Some(r) = deque.pop_front() {
1493{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:1493",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1493u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("constraint_path_to: from_region={0:?} r={1:?} value={2}",
from_region, r, self.region_value_str(r)) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
1494"constraint_path_to: from_region={:?} r={:?} value={}",
1495 from_region,
1496 r,
1497self.region_value_str(r),
1498 );
14991500// Check if we reached the region we were looking for. If so,
1501 // we can reconstruct the path that led to it and return it.
1502if target_test(r) {
1503let mut result = ::alloc::vec::Vec::new()vec![];
1504let mut p = r;
1505// This loop is cold and runs at the end, which is why we delay
1506 // `OutlivesConstraint` construction until now.
1507loop {
1508match context[p] {
1509 Trace::FromGraph(c) => {
1510 p = c.sup;
1511 result.push(*c);
1512 }
15131514 Trace::FromStatic(sub) => {
1515let c = OutlivesConstraint {
1516 sup: fr_static,
1517 sub,
1518 locations: Locations::All(DUMMY_SP),
1519 span: DUMMY_SP,
1520 category: ConstraintCategory::Internal,
1521 variance_info: ty::VarianceDiagInfo::default(),
1522 from_closure: false,
1523 };
1524 p = c.sup;
1525 result.push(c);
1526 }
15271528 Trace::StartRegion => {
1529 result.reverse();
1530return Some((result, r));
1531 }
15321533 Trace::NotVisited => {
1534bug_impl(None,
format_args!("found unvisited region {0:?} on path to {1:?}", p, r),
Location::caller())bug!("found unvisited region {:?} on path to {:?}", p, r)1535 }
1536 }
1537 }
1538 }
15391540// Otherwise, walk over the outgoing constraints and
1541 // enqueue any regions we find, keeping track of how we
1542 // reached them.
15431544 // A constraint like `'r: 'x` can come from our constraint
1545 // graph.
15461547 // Always inline this closure because it can be hot.
1548let mut handle_trace = #[inline(always)]
1549|sub, trace| {
1550if let Trace::NotVisited = context[sub] {
1551 context[sub] = trace;
1552 deque.push_back(sub);
1553 }
1554 };
15551556// If this is the `'static` region and the graph's direction is normal, then set up the
1557 // Edges iterator to return all regions (#53178).
1558if r == fr_static && self.constraint_graph.is_normal() {
1559for sub in self.constraint_graph.outgoing_edges_from_static() {
1560 handle_trace(sub, Trace::FromStatic(sub));
1561 }
1562 } else {
1563let edges = self.constraint_graph.outgoing_edges_from_graph(r, &self.constraints);
1564// This loop can be hot.
1565for constraint in edges {
1566match constraint.category {
1567 ConstraintCategory::OutlivesUnnameablePlaceholder(_)
1568if !include_placeholder_static =>
1569 {
1570{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:1570",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1570u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("Ignoring illegal placeholder constraint: {0:?}",
constraint) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("Ignoring illegal placeholder constraint: {constraint:?}");
1571continue;
1572 }
1573 ConstraintCategory::OpaqueType if ignore_opaque_type_constraints => {
1574{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:1574",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1574u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("Ignoring member constraint: {0:?}",
constraint) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("Ignoring member constraint: {constraint:?}");
1575continue;
1576 }
1577_ => {}
1578 }
15791580if true {
{
match (&constraint.sup, &r) {
(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);
}
}
}
};
};debug_assert_eq!(constraint.sup, r);
1581 handle_trace(constraint.sub, Trace::FromGraph(constraint));
1582 }
1583 }
1584 }
15851586None1587 }
15881589/// Finds some region R such that `fr1: R` and `R` is live at `location`.
1590{}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::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("find_sub_region_live_at",
"rustc_borrowck::region_infer", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1590u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("fr1")
}> =
::tracing::__macro_support::FieldName::new("fr1");
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::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::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(&fr1)
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();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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: RegionVid = 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/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:1592",
"rustc_borrowck::region_infer", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1592u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("scc")
}> =
::tracing::__macro_support::FieldName::new("scc");
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(&self.constraint_sccs.scc(fr1))
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:1593",
"rustc_borrowck::region_infer", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1593u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("universe")
}> =
::tracing::__macro_support::FieldName::new("universe");
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(&self.max_nameable_universe(self.constraint_sccs.scc(fr1)))
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
self.constraint_path_to(fr1,
|r|
{
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:1595",
"rustc_borrowck::region_infer", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1595u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("r")
}> =
::tracing::__macro_support::FieldName::new("r");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("liveness_constraints")
}> =
::tracing::__macro_support::FieldName::new("liveness_constraints");
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(&r)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self.liveness_constraints.pretty_print_live_points(r))
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
self.liveness_constraints.is_live_at(r, location)
}, true).unwrap().1
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:1590",
"rustc_borrowck::region_infer", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1590u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
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(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(skip(self), level = "trace", ret)]1591pub(crate) fn find_sub_region_live_at(&self, fr1: RegionVid, location: Location) -> RegionVid {
1592trace!(scc = ?self.constraint_sccs.scc(fr1));
1593trace!(universe = ?self.max_nameable_universe(self.constraint_sccs.scc(fr1)));
1594self.constraint_path_to(fr1, |r| {
1595trace!(?r, liveness_constraints=?self.liveness_constraints.pretty_print_live_points(r));
1596self.liveness_constraints.is_live_at(r, location)
1597 }, true).unwrap().1
1598}
15991600/// Get the region outlived by `longer_fr` and live at `element`.
1601fn region_from_element(
1602&self,
1603 longer_fr: RegionVid,
1604 element: &RegionElement<'tcx>,
1605 ) -> RegionVid {
1606match *element {
1607 RegionElement::Location(l) => self.find_sub_region_live_at(longer_fr, l),
1608 RegionElement::RootUniversalRegion(r) => r,
1609 RegionElement::PlaceholderRegion(error_placeholder) => self1610 .definitions
1611 .iter_enumerated()
1612 .find_map(|(r, definition)| match definition.origin {
1613 NllRegionVariableOrigin::Placeholder(p) if p == error_placeholder => Some(r),
1614_ => None,
1615 })
1616 .unwrap(),
1617 }
1618 }
16191620/// Get the region definition of `r`.
1621pub(crate) fn region_definition(&self, r: RegionVid) -> &RegionDefinition<'tcx> {
1622&self.definitions[r]
1623 }
16241625/// Check if the SCC of `r` contains `upper`, a free region.
1626pub(crate) fn upper_bound_in_region_scc(&self, r: RegionVid, upper: RegionVid) -> bool {
1627let r_scc = self.constraint_sccs.scc(r);
1628self.scc_values.contains_free_region(r_scc, upper)
1629 }
16301631pub(crate) fn universal_regions(&self) -> &UniversalRegions<'tcx> {
1632&self.universal_region_relations.universal_regions
1633 }
16341635/// Tries to find the best constraint to blame for the fact that
1636 /// `R: from_region`, where `R` is some region that meets
1637 /// `target_test`. This works by following the constraint graph,
1638 /// creating a constraint path that forces `R` to outlive
1639 /// `from_region`, and then finding the best choices within that
1640 /// path to blame.
1641{}
#[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("best_blame_constraint",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1641u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("from_region")
}> =
::tracing::__macro_support::FieldName::new("from_region");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("from_region_origin")
}> =
::tracing::__macro_support::FieldName::new("from_region_origin");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("to_region")
}> =
::tracing::__macro_support::FieldName::new("to_region");
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(&from_region)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&from_region_origin)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&to_region)
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: BestBlame<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
if !(from_region != to_region) {
{
::core::panicking::panic_fmt(format_args!("Trying to blame a region for itself!"));
}
};
let path =
self.constraint_path_between_regions(from_region,
to_region).unwrap();
let due_to_placeholder_outlives =
path.iter().find_map(|c|
{
if let ConstraintCategory::OutlivesUnnameablePlaceholder(unnameable)
= c.category {
Some(unnameable)
} else { None }
});
let mut path =
if let Some(unnameable) = due_to_placeholder_outlives &&
unnameable != from_region {
self.constraint_path_to(from_region, |r| r == unnameable,
false).unwrap().0
} else { path };
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:1673",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1673u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("path={0:#?}",
path.iter().map(|c|
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:?} ({1:?}: {2:?})", c,
self.constraint_sccs.scc(c.sup),
self.constraint_sccs.scc(c.sub)))
})).collect::<Vec<_>>()) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let blame_source =
match from_region_origin {
NllRegionVariableOrigin::FreeRegion => true,
NllRegionVariableOrigin::Placeholder(_) => false,
NllRegionVariableOrigin::Existential { name: _ } => {
{
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("existentials can outlive everything")));
}
}
};
let constraint_interest =
|constraint: &OutlivesConstraint<'tcx>|
{
let category =
if let Some(kind) = constraint.span.desugaring_kind() &&
(kind != DesugaringKind::QuestionMark ||
!#[allow(non_exhaustive_omitted_patterns)] match constraint.category
{
ConstraintCategory::Return(_) => true,
_ => false,
}) {
ConstraintCategory::Boring
} else { constraint.category };
let interest =
match category {
ConstraintCategory::Return(_) => 0,
ConstraintCategory::Cast {
is_raw_ptr_dyn_type_cast: _,
unsize_to: Some(unsize_ty),
is_implicit_coercion: true } if
to_region == self.universal_regions().fr_static &&
let ty::Adt(_, args) = unsize_ty.kind() &&
args.iter().any(|arg|
arg.as_type().is_some_and(|ty| ty.is_trait())) &&
!path.iter().any(|c|
#[allow(non_exhaustive_omitted_patterns)] match c.category {
ConstraintCategory::TypeAnnotation(_) => true,
_ => false,
}) => {
1
}
ConstraintCategory::Yield | ConstraintCategory::UseAsConst |
ConstraintCategory::UseAsStatic |
ConstraintCategory::TypeAnnotation(AnnotationSource::Ascription
| AnnotationSource::Declaration |
AnnotationSource::OpaqueCast) | ConstraintCategory::Cast {
.. } | ConstraintCategory::CallArgument(_) |
ConstraintCategory::CopyBound |
ConstraintCategory::SizedBound |
ConstraintCategory::Assignment | ConstraintCategory::Usage |
ConstraintCategory::ClosureUpvar(_) => 2,
ConstraintCategory::TypeAnnotation(AnnotationSource::GenericArg)
=> 3,
ConstraintCategory::Predicate(_) |
ConstraintCategory::OpaqueType => 4,
ConstraintCategory::Boring => 5,
ConstraintCategory::BoringNoLocation => 6,
ConstraintCategory::Internal => 7,
ConstraintCategory::OutlivesUnnameablePlaceholder(_) => 8,
ConstraintCategory::SolverRegionConstraint(_) => 9,
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:1807",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1807u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::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!("constraint {0:?} category: {1:?}, interest: {2:?}",
constraint, category, interest) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};
interest
};
let best_choice =
if blame_source {
path.iter().enumerate().rev().min_by_key(|(_, c)|
constraint_interest(c)).unwrap().0
} else {
path.iter().enumerate().min_by_key(|(_, c)|
constraint_interest(c)).unwrap().0
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs:1818",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1818u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("best_choice")
}> =
::tracing::__macro_support::FieldName::new("best_choice");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("blame_source")
}> =
::tracing::__macro_support::FieldName::new("blame_source");
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(&best_choice)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&blame_source)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let best_blame_idx =
if let Some(next) = path.get(best_choice + 1) &&
#[allow(non_exhaustive_omitted_patterns)] match path[best_choice].category
{
ConstraintCategory::Return(_) => true,
_ => false,
} && next.category == ConstraintCategory::OpaqueType {
best_choice + 1
} else if path[best_choice].category ==
ConstraintCategory::Return(ReturnConstraint::Normal) &&
let Some(field) =
path.iter().find_map(|p|
{
if let ConstraintCategory::ClosureUpvar(f) = p.category {
Some(f)
} else { None }
}) {
path[best_choice].category =
ConstraintCategory::Return(ReturnConstraint::ClosureUpvar(field));
best_choice
} else { best_choice };
if !!#[allow(non_exhaustive_omitted_patterns)] match path[best_blame_idx].category
{
ConstraintCategory::OutlivesUnnameablePlaceholder(_) =>
true,
_ => false,
} {
{
::core::panicking::panic_fmt(format_args!("Illegal placeholder constraint blamed; should have redirected to other region relation"));
}
};
BestBlame { path, idx: best_blame_idx }
}
}
}#[instrument(level = "debug", skip(self))]1642pub(crate) fn best_blame_constraint(
1643&self,
1644 from_region: RegionVid,
1645 from_region_origin: NllRegionVariableOrigin<'tcx>,
1646 to_region: RegionVid,
1647 ) -> BestBlame<'tcx> {
1648assert!(from_region != to_region, "Trying to blame a region for itself!");
16491650let path = self.constraint_path_between_regions(from_region, to_region).unwrap();
16511652// If we are passing through a constraint added because we reached an unnameable placeholder `'unnameable`,
1653 // redirect search towards `'unnameable`.
1654let due_to_placeholder_outlives = path.iter().find_map(|c| {
1655if let ConstraintCategory::OutlivesUnnameablePlaceholder(unnameable) = c.category {
1656Some(unnameable)
1657 } else {
1658None
1659}
1660 });
16611662// Edge case: it's possible that `'from_region` is an unnameable placeholder.
1663let mut path = if let Some(unnameable) = due_to_placeholder_outlives
1664 && unnameable != from_region
1665 {
1666// We ignore the extra edges due to unnameable placeholders to get
1667 // an explanation that was present in the original constraint graph.
1668self.constraint_path_to(from_region, |r| r == unnameable, false).unwrap().0
1669} else {
1670 path
1671 };
16721673debug!(
1674"path={:#?}",
1675 path.iter()
1676 .map(|c| format!(
1677"{:?} ({:?}: {:?})",
1678 c,
1679self.constraint_sccs.scc(c.sup),
1680self.constraint_sccs.scc(c.sub),
1681 ))
1682 .collect::<Vec<_>>()
1683 );
16841685// When reporting an error, there is typically a chain of constraints leading from some
1686 // "source" region which must outlive some "target" region.
1687 // In most cases, we prefer to "blame" the constraints closer to the target --
1688 // but there is one exception. When constraints arise from higher-ranked subtyping,
1689 // we generally prefer to blame the source value,
1690 // as the "target" in this case tends to be some type annotation that the user gave.
1691 // Therefore, if we find that the region origin is some instantiation
1692 // of a higher-ranked region, we start our search from the "source" point
1693 // rather than the "target", and we also tweak a few other things.
1694 //
1695 // An example might be this bit of Rust code:
1696 //
1697 // ```rust
1698 // let x: fn(&'static ()) = |_| {};
1699 // let y: for<'a> fn(&'a ()) = x;
1700 // ```
1701 //
1702 // In MIR, this will be converted into a combination of assignments and type ascriptions.
1703 // In particular, the 'static is imposed through a type ascription:
1704 //
1705 // ```rust
1706 // x = ...;
1707 // AscribeUserType(x, fn(&'static ())
1708 // y = x;
1709 // ```
1710 //
1711 // We wind up ultimately with constraints like
1712 //
1713 // ```rust
1714 // !a: 'temp1 // from the `y = x` statement
1715 // 'temp1: 'temp2
1716 // 'temp2: 'static // from the AscribeUserType
1717 // ```
1718 //
1719 // and here we prefer to blame the source (the y = x statement).
1720let blame_source = match from_region_origin {
1721 NllRegionVariableOrigin::FreeRegion => true,
1722 NllRegionVariableOrigin::Placeholder(_) => false,
1723// `'existential: 'whatever` never results in a region error by itself.
1724 // We may always infer it to `'static` afterall. This means while an error
1725 // path may go through an existential, these existentials are never the
1726 // `from_region`.
1727NllRegionVariableOrigin::Existential { name: _ } => {
1728unreachable!("existentials can outlive everything")
1729 }
1730 };
17311732// To pick a constraint to blame, we organize constraints by how interesting we expect them
1733 // to be in diagnostics, then pick the most interesting one closest to either the source or
1734 // the target on our constraint path.
1735let constraint_interest = |constraint: &OutlivesConstraint<'tcx>| {
1736// Try to avoid blaming constraints from desugarings, since they may not clearly match
1737 // match what users have written. As an exception, allow blaming returns generated by
1738 // `?` desugaring, since the correspondence is fairly clear.
1739let category = if let Some(kind) = constraint.span.desugaring_kind()
1740 && (kind != DesugaringKind::QuestionMark
1741 || !matches!(constraint.category, ConstraintCategory::Return(_)))
1742 {
1743 ConstraintCategory::Boring
1744 } else {
1745 constraint.category
1746 };
17471748let interest = match category {
1749// Returns usually provide a type to blame and have specially written diagnostics,
1750 // so prioritize them.
1751ConstraintCategory::Return(_) => 0,
1752// Unsizing coercions are interesting, since we have a note for that:
1753 // `BorrowExplanation::add_object_lifetime_default_note`.
1754 // FIXME(dianne): That note shouldn't depend on a coercion being blamed; see issue
1755 // #131008 for an example of where we currently don't emit it but should.
1756 // Once the note is handled properly, this case should be removed. Until then, it
1757 // should be as limited as possible; the note is prone to false positives and this
1758 // constraint usually isn't best to blame.
1759ConstraintCategory::Cast {
1760 is_raw_ptr_dyn_type_cast: _,
1761 unsize_to: Some(unsize_ty),
1762 is_implicit_coercion: true,
1763 } if to_region == self.universal_regions().fr_static
1764// Mirror the note's condition, to minimize how often this diverts blame.
1765&& let ty::Adt(_, args) = unsize_ty.kind()
1766 && args.iter().any(|arg| arg.as_type().is_some_and(|ty| ty.is_trait()))
1767// Mimic old logic for this, to minimize false positives in tests.
1768&& !path
1769 .iter()
1770 .any(|c| matches!(c.category, ConstraintCategory::TypeAnnotation(_))) =>
1771 {
17721
1773}
1774// Between other interesting constraints, order by their position on the `path`.
1775ConstraintCategory::Yield
1776 | ConstraintCategory::UseAsConst
1777 | ConstraintCategory::UseAsStatic
1778 | ConstraintCategory::TypeAnnotation(
1779 AnnotationSource::Ascription
1780 | AnnotationSource::Declaration
1781 | AnnotationSource::OpaqueCast,
1782 )
1783 | ConstraintCategory::Cast { .. }
1784 | ConstraintCategory::CallArgument(_)
1785 | ConstraintCategory::CopyBound
1786 | ConstraintCategory::SizedBound
1787 | ConstraintCategory::Assignment
1788 | ConstraintCategory::Usage
1789 | ConstraintCategory::ClosureUpvar(_) => 2,
1790// Generic arguments are unlikely to be what relates regions together
1791ConstraintCategory::TypeAnnotation(AnnotationSource::GenericArg) => 3,
1792// We handle predicates and opaque types specially; don't prioritize them here.
1793ConstraintCategory::Predicate(_) | ConstraintCategory::OpaqueType => 4,
1794// `Boring` constraints can correspond to user-written code and have useful spans,
1795 // but don't provide any other useful information for diagnostics.
1796ConstraintCategory::Boring => 5,
1797// `BoringNoLocation` constraints can point to user-written code, but are less
1798 // specific, and are not used for relations that would make sense to blame.
1799ConstraintCategory::BoringNoLocation => 6,
1800// Do not blame internal constraints if we can avoid it. Never blame
1801 // the `'region: 'static` constraints introduced by placeholder outlives.
1802ConstraintCategory::Internal => 7,
1803 ConstraintCategory::OutlivesUnnameablePlaceholder(_) => 8,
1804 ConstraintCategory::SolverRegionConstraint(_) => 9,
1805 };
18061807debug!("constraint {constraint:?} category: {category:?}, interest: {interest:?}");
18081809 interest
1810 };
18111812let best_choice = if blame_source {
1813 path.iter().enumerate().rev().min_by_key(|(_, c)| constraint_interest(c)).unwrap().0
1814} else {
1815 path.iter().enumerate().min_by_key(|(_, c)| constraint_interest(c)).unwrap().0
1816};
18171818debug!(?best_choice, ?blame_source);
18191820let best_blame_idx = if let Some(next) = path.get(best_choice + 1)
1821 && matches!(path[best_choice].category, ConstraintCategory::Return(_))
1822 && next.category == ConstraintCategory::OpaqueType
1823 {
1824// The return expression is being influenced by the return type being
1825 // impl Trait, point at the return type and not the return expr.
1826best_choice + 1
1827} else if path[best_choice].category == ConstraintCategory::Return(ReturnConstraint::Normal)
1828 && let Some(field) = path.iter().find_map(|p| {
1829if let ConstraintCategory::ClosureUpvar(f) = p.category { Some(f) } else { None }
1830 })
1831 {
1832 path[best_choice].category =
1833 ConstraintCategory::Return(ReturnConstraint::ClosureUpvar(field));
1834 best_choice
1835 } else {
1836 best_choice
1837 };
18381839assert!(
1840 !matches!(
1841 path[best_blame_idx].category,
1842 ConstraintCategory::OutlivesUnnameablePlaceholder(_)
1843 ),
1844"Illegal placeholder constraint blamed; should have redirected to other region relation"
1845);
18461847 BestBlame { path, idx: best_blame_idx }
1848 }
18491850pub(crate) fn universe_info(&self, universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
1851// Query canonicalization can create local superuniverses (for example in
1852 // `InferCtx::query_response_instantiation_guess`), but they don't have an associated
1853 // `UniverseInfo` explaining why they were created.
1854 // This can cause ICEs if these causes are accessed in diagnostics, for example in issue
1855 // #114907 where this happens via liveness and dropck outlives results.
1856 // Therefore, we return a default value in case that happens, which should at worst emit a
1857 // suboptimal error, instead of the ICE.
1858self.universe_causes.get(&universe).cloned().unwrap_or_else(UniverseInfo::other)
1859 }
18601861/// Tries to find the terminator of the loop in which the region 'r' resides.
1862 /// Returns the location of the terminator if found.
1863pub(crate) fn find_loop_terminator_location(
1864&self,
1865 r: RegionVid,
1866 body: &Body<'_>,
1867 ) -> Option<Location> {
1868let scc = self.constraint_sccs.scc(r);
1869let locations = self.scc_values.locations_outlived_by(scc);
1870for location in locations {
1871let bb = &body[location.block];
1872if let Some(terminator) = &bb.terminator
1873// terminator of a loop should be TerminatorKind::FalseUnwind
1874&& let TerminatorKind::FalseUnwind { .. } = terminator.kind
1875 {
1876return Some(location);
1877 }
1878 }
1879None1880 }
18811882/// Access to the SCC constraint graph.
1883 /// This can be used to quickly under-approximate the regions which are equal to each other
1884 /// and their relative orderings.
1885// This is `pub` because it's used by unstable external borrowck data users, see `consumers.rs`.
1886pub fn constraint_sccs(&self) -> &ConstraintSccs {
1887&self.constraint_sccs
1888 }
18891890/// Returns the representative `RegionVid` for a given SCC.
1891 /// See `RegionTracker` for how a region variable ID is chosen.
1892 ///
1893 /// It is a hacky way to manage checking regions for equality,
1894 /// since we can 'canonicalize' each region to the representative
1895 /// of its SCC and be sure that -- if they have the same repr --
1896 /// they *must* be equal (though not having the same repr does not
1897 /// mean they are unequal).
1898fn scc_representative(&self, scc: ConstraintSccIndex) -> RegionVid {
1899self.scc_annotations[scc].representative.rvid()
1900 }
19011902pub(crate) fn liveness_constraints(&self) -> &LivenessValues {
1903&self.liveness_constraints
1904 }
19051906/// Returns whether the `loan_idx` is live at the given `location`: whether its issuing
1907 /// region is contained within the type of a variable that is live at this point.
1908 /// Note: for now, the sets of live loans is only available when using `-Zpolonius=next`.
1909pub(crate) fn is_loan_live_at(&self, loan_idx: BorrowIndex, location: Location) -> bool {
1910let point = self.liveness_constraints.point_from_location(location);
1911self.liveness_constraints.is_loan_live_at(loan_idx, point)
1912 }
1913}
19141915#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for BestBlame<'tcx> {
#[inline]
fn clone(&self) -> BestBlame<'tcx> {
BestBlame {
path: ::core::clone::Clone::clone(&self.path),
idx: ::core::clone::Clone::clone(&self.idx),
}
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for BestBlame<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "BestBlame",
"path", &self.path, "idx", &&self.idx)
}
}Debug)]
1916pub(crate) struct BestBlame<'tcx> {
1917/// See docs on [`RegionInferenceContext::best_blame_constraint`] for what this is.
1918path: Vec<OutlivesConstraint<'tcx>>,
1919/// Index into `path` of the constraint most relevant to report to users.
1920idx: usize,
1921}
19221923impl<'tcx> BestBlame<'tcx> {
1924pub(crate) fn to_obligation_cause(&self) -> ObligationCause<'tcx> {
1925// FIXME - determine what we should do if we encounter multiple
1926 // `ConstraintCategory::Predicate` constraints. Currently, we just pick the first one.
1927let cause_code = self1928 .path
1929 .iter()
1930 .find_map(|constraint| {
1931if let ConstraintCategory::Predicate(predicate_span) = constraint.category {
1932// We currently do not store the `DefId` in the `ConstraintCategory`
1933 // for performances reasons. The error reporting code used by NLL only
1934 // uses the span, so this doesn't cause any problems at the moment.
1935Some(ObligationCauseCode::WhereClause(CRATE_DEF_ID.to_def_id(), predicate_span))
1936 } else {
1937None1938 }
1939 })
1940 .unwrap_or_else(|| ObligationCauseCode::Misc);
19411942ObligationCause::new(self.constraint().span, CRATE_DEF_ID, cause_code.clone())
1943 }
19441945pub(crate) fn constraint(&self) -> &OutlivesConstraint<'tcx> {
1946&self.path[self.idx]
1947 }
19481949pub(crate) fn path(&self) -> &[OutlivesConstraint<'tcx>] {
1950&self.path
1951 }
1952}