1use std::collections::VecDeque;
2use std::rc::Rc;
34use rustc_data_structures::frozen::Frozen;
5use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
6use rustc_data_structures::graph::scc::Sccs;
7use rustc_errors::Diag;
8use rustc_hir::def_id::CRATE_DEF_ID;
9use rustc_index::IndexVec;
10use rustc_infer::infer::outlives::test_type_match;
11use rustc_infer::infer::region_constraints::{GenericKind, VerifyBound, VerifyIfEq};
12use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin};
13use rustc_middle::bug;
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};
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::LiveLoans;
31use crate::polonius::legacy::PoloniusOutput;
32use crate::region_infer::values::{LivenessValues, RegionElement, RegionValues, ToElementIndex};
33use crate::type_check::Locations;
34use crate::type_check::free_region_relations::UniversalRegionRelations;
35use crate::universal_regions::UniversalRegions;
36use crate::{
37BorrowckInferCtxt, ClosureOutlivesRequirement, ClosureOutlivesSubject,
38ClosureOutlivesSubjectTy, ClosureRegionRequirements,
39};
4041mod dump_mir;
42mod graphviz;
43pub(crate) mod opaque_types;
44mod reverse_sccs;
4546pub(crate) mod values;
4748/// The representative region variable for an SCC, tagged by its origin.
49/// We prefer placeholders over existentially quantified variables, otherwise
50/// it's the one with the smallest Region Variable ID. In other words,
51/// the order of this enumeration really matters!
52#[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]
impl ::core::clone::Clone for Representative {
#[inline]
fn clone(&self) -> Representative {
let _: ::core::clone::AssertParamIsClone<RegionVid>;
*self
}
}Clone, #[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> {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
match (self, other) {
(Representative::FreeRegion(__self_0),
Representative::FreeRegion(__arg1_0)) =>
::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0),
(Representative::Placeholder(__self_0),
Representative::Placeholder(__arg1_0)) =>
::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0),
(Representative::Existential(__self_0),
Representative::Existential(__arg1_0)) =>
::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0),
_ =>
::core::cmp::PartialOrd::partial_cmp(&__self_discr,
&__arg1_discr),
}
}
}PartialOrd, #[automatically_derived]
impl ::core::cmp::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)]
53pub(crate) enum Representative {
54 FreeRegion(RegionVid),
55 Placeholder(RegionVid),
56 Existential(RegionVid),
57}
5859impl Representative {
60pub(crate) fn rvid(self) -> RegionVid {
61match self {
62 Representative::FreeRegion(region_vid)
63 | Representative::Placeholder(region_vid)
64 | Representative::Existential(region_vid) => region_vid,
65 }
66 }
6768pub(crate) fn new(r: RegionVid, definition: &RegionDefinition<'_>) -> Self {
69match definition.origin {
70 NllRegionVariableOrigin::FreeRegion => Representative::FreeRegion(r),
71 NllRegionVariableOrigin::Placeholder(_) => Representative::Placeholder(r),
72 NllRegionVariableOrigin::Existential { .. } => Representative::Existential(r),
73 }
74 }
75}
7677pub(crate) type ConstraintSccs = Sccs<RegionVid, ConstraintSccIndex>;
7879pub struct RegionInferenceContext<'tcx> {
80/// Contains the definition for every region variable. Region
81 /// variables are identified by their index (`RegionVid`). The
82 /// definition contains information about where the region came
83 /// from as well as its final inferred value.
84pub(crate) definitions: Frozen<IndexVec<RegionVid, RegionDefinition<'tcx>>>,
8586/// The liveness constraints added to each region. For most
87 /// regions, these start out empty and steadily grow, though for
88 /// each universally quantified region R they start out containing
89 /// the entire CFG and `end(R)`.
90liveness_constraints: LivenessValues,
9192/// The outlives constraints computed by the type-check.
93constraints: Frozen<OutlivesConstraintSet<'tcx>>,
9495/// The constraint-set, but in graph form, making it easy to traverse
96 /// the constraints adjacent to a particular region. Used to construct
97 /// the SCC (see `constraint_sccs`) and for error reporting.
98constraint_graph: Frozen<NormalConstraintGraph>,
99100/// The SCC computed from `constraints` and the constraint
101 /// graph. We have an edge from SCC A to SCC B if `A: B`. Used to
102 /// compute the values of each region.
103constraint_sccs: ConstraintSccs,
104105 scc_annotations: IndexVec<ConstraintSccIndex, RegionTracker>,
106107/// Map universe indexes to information on why we created it.
108universe_causes: FxIndexMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
109110/// The final inferred values of the region variables; we compute
111 /// one value per SCC. To get the value for any given *region*,
112 /// you first find which scc it is a part of.
113scc_values: RegionValues<'tcx, ConstraintSccIndex>,
114115/// Type constraints that we check after solving.
116type_tests: Vec<TypeTest<'tcx>>,
117118/// Information about how the universally quantified regions in
119 /// scope on this function relate to one another.
120universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
121}
122123#[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)]
124pub(crate) struct RegionDefinition<'tcx> {
125/// What kind of variable is this -- a free region? existential
126 /// variable? etc. (See the `NllRegionVariableOrigin` for more
127 /// info.)
128pub(crate) origin: NllRegionVariableOrigin<'tcx>,
129130/// Which universe is this region variable defined in? This is
131 /// most often `ty::UniverseIndex::ROOT`, but when we encounter
132 /// forall-quantifiers like `for<'a> { 'a = 'b }`, we would create
133 /// the variable for `'a` in a fresh universe that extends ROOT.
134pub(crate) universe: ty::UniverseIndex,
135136/// If this is 'static or an early-bound region, then this is
137 /// `Some(X)` where `X` is the name of the region.
138pub(crate) external_name: Option<ty::Region<'tcx>>,
139}
140141/// N.B., the variants in `Cause` are intentionally ordered. Lower
142/// values are preferred when it comes to error messages. Do not
143/// reorder willy nilly.
144#[derive(#[automatically_derived]
impl ::core::marker::Copy for Cause { }Copy, #[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> {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
match (self, other) {
(Cause::LiveVar(__self_0, __self_1),
Cause::LiveVar(__arg1_0, __arg1_1)) =>
match ::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0)
{
::core::option::Option::Some(::core::cmp::Ordering::Equal)
=> ::core::cmp::PartialOrd::partial_cmp(__self_1, __arg1_1),
cmp => cmp,
},
(Cause::DropVar(__self_0, __self_1),
Cause::DropVar(__arg1_0, __arg1_1)) =>
match ::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0)
{
::core::option::Option::Some(::core::cmp::Ordering::Equal)
=> ::core::cmp::PartialOrd::partial_cmp(__self_1, __arg1_1),
cmp => cmp,
},
_ =>
::core::cmp::PartialOrd::partial_cmp(&__self_discr,
&__arg1_discr),
}
}
}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::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)]
145pub(crate) enum Cause {
146/// point inserted because Local was live at the given Location
147LiveVar(Local, Location),
148149/// point inserted because Local was dropped at the given Location
150DropVar(Local, Location),
151}
152153/// A "type test" corresponds to an outlives constraint between a type
154/// and a lifetime, like `T: 'x` or `<T as Foo>::Bar: 'x`. They are
155/// translated from the `Verify` region constraints in the ordinary
156/// inference context.
157///
158/// These sorts of constraints are handled differently than ordinary
159/// constraints, at least at present. During type checking, the
160/// `InferCtxt::process_registered_region_obligations` method will
161/// attempt to convert a type test like `T: 'x` into an ordinary
162/// outlives constraint when possible (for example, `&'a T: 'b` will
163/// be converted into `'a: 'b` and registered as a `Constraint`).
164///
165/// In some cases, however, there are outlives relationships that are
166/// not converted into a region constraint, but rather into one of
167/// these "type tests". The distinction is that a type test does not
168/// influence the inference result, but instead just examines the
169/// values that we ultimately inferred for each region variable and
170/// checks that they meet certain extra criteria. If not, an error
171/// can be issued.
172///
173/// One reason for this is that these type tests typically boil down
174/// to a check like `'a: 'x` where `'a` is a universally quantified
175/// region -- and therefore not one whose value is really meant to be
176/// *inferred*, precisely (this is not always the case: one can have a
177/// type test like `<Foo as Trait<'?0>>::Bar: 'x`, where `'?0` is an
178/// inference variable). Another reason is that these type tests can
179/// involve *disjunction* -- that is, they can be satisfied in more
180/// than one way.
181///
182/// For more information about this translation, see
183/// `InferCtxt::process_registered_region_obligations` and
184/// `InferCtxt::type_must_outlive` in `rustc_infer::infer::InferCtxt`.
185#[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, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for TypeTest<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field4_finish(f, "TypeTest",
"generic_kind", &self.generic_kind, "lower_bound",
&self.lower_bound, "span", &self.span, "verify_bound",
&&self.verify_bound)
}
}Debug)]
186pub(crate) struct TypeTest<'tcx> {
187/// The type `T` that must outlive the region.
188pub generic_kind: GenericKind<'tcx>,
189190/// The region `'x` that the type must outlive.
191pub lower_bound: RegionVid,
192193/// The span to blame.
194pub span: Span,
195196/// A test which, if met by the region `'x`, proves that this type
197 /// constraint is satisfied.
198pub verify_bound: VerifyBound<'tcx>,
199}
200201/// When we have an unmet lifetime constraint, we try to propagate it outward (e.g. to a closure
202/// environment). If we can't, it is an error.
203#[derive(#[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 {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq, #[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)]
204enum RegionRelationCheckResult {
205Ok,
206 Propagated,
207 Error,
208}
209210#[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::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)]
211enum Trace<'a, 'tcx> {
212 StartRegion,
213 FromGraph(&'a OutlivesConstraint<'tcx>),
214 FromStatic(RegionVid),
215 NotVisited,
216}
217218#[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("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(218u32),
::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(&[]) })
} 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 compiler/rustc_borrowck/src/region_infer/mod.rs:227",
"rustc_borrowck::region_infer", Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(227u32),
::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 compiler/rustc_borrowck/src/region_infer/mod.rs:232",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(232u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("{0}",
reg_vars_to_origins_str) as &dyn 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 compiler/rustc_borrowck/src/region_infer/mod.rs:243",
"rustc_borrowck::region_infer", Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(243u32),
::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 compiler/rustc_borrowck/src/region_infer/mod.rs:253",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(253u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("{0}",
components_str) as &dyn 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 compiler/rustc_borrowck/src/region_infer/mod.rs:281",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(281u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("SCC edges {0:#?}",
scc_node_to_edges) as &dyn Value))])
});
} else { ; }
};
}
}
}#[instrument(skip(infcx, sccs), level = "debug")]219fn sccs_info<'tcx>(infcx: &BorrowckInferCtxt<'tcx>, sccs: &ConstraintSccs) {
220use crate::renumber::RegionCtxt;
221222let var_to_origin = infcx.reg_var_to_origin.borrow();
223224let mut var_to_origin_sorted = var_to_origin.clone().into_iter().collect::<Vec<_>>();
225 var_to_origin_sorted.sort_by_key(|vto| vto.0);
226227if enabled!(Level::DEBUG) {
228let mut reg_vars_to_origins_str = "region variables to origins:\n".to_string();
229for (reg_var, origin) in var_to_origin_sorted.into_iter() {
230 reg_vars_to_origins_str.push_str(&format!("{reg_var:?}: {origin:?}\n"));
231 }
232debug!("{}", reg_vars_to_origins_str);
233 }
234235let num_components = sccs.num_sccs();
236let mut components = vec![FxIndexSet::default(); num_components];
237238for (reg_var, scc_idx) in sccs.scc_indices().iter_enumerated() {
239let origin = var_to_origin.get(®_var).unwrap_or(&RegionCtxt::Unknown);
240 components[scc_idx.as_usize()].insert((reg_var, *origin));
241 }
242243if enabled!(Level::DEBUG) {
244let mut components_str = "strongly connected components:".to_string();
245for (scc_idx, reg_vars_origins) in components.iter().enumerate() {
246let regions_info = reg_vars_origins.clone().into_iter().collect::<Vec<_>>();
247 components_str.push_str(&format!(
248"{:?}: {:?},\n)",
249 ConstraintSccIndex::from_usize(scc_idx),
250 regions_info,
251 ))
252 }
253debug!("{}", components_str);
254 }
255256// calculate the best representative for each component
257let components_representatives = components
258 .into_iter()
259 .enumerate()
260 .map(|(scc_idx, region_ctxts)| {
261let repr = region_ctxts
262 .into_iter()
263 .map(|reg_var_origin| reg_var_origin.1)
264 .max_by(|x, y| x.preference_value().cmp(&y.preference_value()))
265 .unwrap();
266267 (ConstraintSccIndex::from_usize(scc_idx), repr)
268 })
269 .collect::<FxIndexMap<_, _>>();
270271let mut scc_node_to_edges = FxIndexMap::default();
272for (scc_idx, repr) in components_representatives.iter() {
273let edge_representatives = sccs
274 .successors(*scc_idx)
275 .iter()
276 .map(|scc_idx| components_representatives[scc_idx])
277 .collect::<Vec<_>>();
278 scc_node_to_edges.insert((scc_idx, repr), edge_representatives);
279 }
280281debug!("SCC edges {:#?}", scc_node_to_edges);
282}
283284impl<'tcx> RegionInferenceContext<'tcx> {
285/// Creates a new region inference context with a total of
286 /// `num_region_variables` valid inference variables; the first N
287 /// of those will be constant regions representing the free
288 /// regions defined in `universal_regions`.
289 ///
290 /// The `outlives_constraints` and `type_tests` are an initial set
291 /// of constraints produced by the MIR type check.
292pub(crate) fn new(
293 infcx: &BorrowckInferCtxt<'tcx>,
294 lowered_constraints: LoweredConstraints<'tcx>,
295 universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
296 location_map: Rc<DenseLocationMap>,
297 ) -> Self {
298let universal_regions = &universal_region_relations.universal_regions;
299300let LoweredConstraints {
301 constraint_sccs,
302 definitions,
303 outlives_constraints,
304 scc_annotations,
305 type_tests,
306 liveness_constraints,
307 universe_causes,
308 placeholder_indices,
309 } = lowered_constraints;
310311{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/region_infer/mod.rs:311",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(311u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("universal_regions: {0:#?}",
universal_region_relations.universal_regions) as
&dyn Value))])
});
} else { ; }
};debug!("universal_regions: {:#?}", universal_region_relations.universal_regions);
312{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/region_infer/mod.rs:312",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(312u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("outlives constraints: {0:#?}",
outlives_constraints) as &dyn Value))])
});
} else { ; }
};debug!("outlives constraints: {:#?}", outlives_constraints);
313{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/region_infer/mod.rs:313",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(313u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("placeholder_indices: {0:#?}",
placeholder_indices) as &dyn Value))])
});
} else { ; }
};debug!("placeholder_indices: {:#?}", placeholder_indices);
314{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/region_infer/mod.rs:314",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(314u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("type tests: {0:#?}",
type_tests) as &dyn Value))])
});
} else { ; }
};debug!("type tests: {:#?}", type_tests);
315316let constraint_graph = Frozen::freeze(outlives_constraints.graph(definitions.len()));
317318if truecfg!(debug_assertions) {
319sccs_info(infcx, &constraint_sccs);
320 }
321322let mut scc_values =
323RegionValues::new(location_map, universal_regions.len(), placeholder_indices);
324325for region in liveness_constraints.regions() {
326let scc = constraint_sccs.scc(region);
327 scc_values.merge_liveness(scc, region, &liveness_constraints);
328 }
329330let mut result = Self {
331definitions,
332liveness_constraints,
333 constraints: outlives_constraints,
334constraint_graph,
335constraint_sccs,
336scc_annotations,
337universe_causes,
338scc_values,
339type_tests,
340universal_region_relations,
341 };
342343result.init_free_and_bound_regions();
344345result346 }
347348/// Initializes the region variables for each universally
349 /// quantified region (lifetime parameter). The first N variables
350 /// always correspond to the regions appearing in the function
351 /// signature (both named and anonymous) and where-clauses. This
352 /// function iterates over those regions and initializes them with
353 /// minimum values.
354 ///
355 /// For example:
356 /// ```ignore (illustrative)
357 /// fn foo<'a, 'b>( /* ... */ ) where 'a: 'b { /* ... */ }
358 /// ```
359 /// would initialize two variables like so:
360 /// ```ignore (illustrative)
361 /// R0 = { CFG, R0 } // 'a
362 /// R1 = { CFG, R0, R1 } // 'b
363 /// ```
364 /// Here, R0 represents `'a`, and it contains (a) the entire CFG
365 /// and (b) any universally quantified regions that it outlives,
366 /// which in this case is just itself. R1 (`'b`) in contrast also
367 /// outlives `'a` and hence contains R0 and R1.
368 ///
369 /// This bit of logic also handles invalid universe relations
370 /// for higher-kinded types.
371 ///
372 /// We Walk each SCC `A` and `B` such that `A: B`
373 /// and ensure that universe(A) can see universe(B).
374 ///
375 /// This serves to enforce the 'empty/placeholder' hierarchy
376 /// (described in more detail on `RegionKind`):
377 ///
378 /// ```ignore (illustrative)
379 /// static -----+
380 /// | |
381 /// empty(U0) placeholder(U1)
382 /// | /
383 /// empty(U1)
384 /// ```
385 ///
386 /// In particular, imagine we have variables R0 in U0 and R1
387 /// created in U1, and constraints like this;
388 ///
389 /// ```ignore (illustrative)
390 /// R1: !1 // R1 outlives the placeholder in U1
391 /// R1: R0 // R1 outlives R0
392 /// ```
393 ///
394 /// Here, we wish for R1 to be `'static`, because it
395 /// cannot outlive `placeholder(U1)` and `empty(U0)` any other way.
396 ///
397 /// Thanks to this loop, what happens is that the `R1: R0`
398 /// constraint has lowered the universe of `R1` to `U0`, which in turn
399 /// means that the `R1: !1` constraint here will cause
400 /// `R1` to become `'static`.
401fn init_free_and_bound_regions(&mut self) {
402for variable in self.definitions.indices() {
403let scc = self.constraint_sccs.scc(variable);
404405match self.definitions[variable].origin {
406 NllRegionVariableOrigin::FreeRegion => {
407// For each free, universally quantified region X:
408409 // Add all nodes in the CFG to liveness constraints
410self.liveness_constraints.add_all_points(variable);
411self.scc_values.add_all_points(scc);
412413// Add `end(X)` into the set for X.
414self.scc_values.add_element(scc, variable);
415 }
416417 NllRegionVariableOrigin::Placeholder(placeholder) => {
418self.scc_values.add_element(scc, placeholder);
419 }
420421 NllRegionVariableOrigin::Existential { .. } => {
422// For existential, regions, nothing to do.
423}
424 }
425 }
426 }
427428/// Returns an iterator over all the region indices.
429pub(crate) fn regions(&self) -> impl Iterator<Item = RegionVid> + 'tcx {
430self.definitions.indices()
431 }
432433/// Given a universal region in scope on the MIR, returns the
434 /// corresponding index.
435 ///
436 /// Panics if `r` is not a registered universal region, most notably
437 /// if it is a placeholder. Handling placeholders requires access to the
438 /// `MirTypeckRegionConstraints`.
439pub(crate) fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
440self.universal_regions().to_region_vid(r)
441 }
442443/// Returns an iterator over all the outlives constraints.
444pub(crate) fn outlives_constraints(&self) -> impl Iterator<Item = OutlivesConstraint<'tcx>> {
445self.constraints.outlives().iter().copied()
446 }
447448/// Adds annotations for `#[rustc_regions]`; see `UniversalRegions::annotate`.
449pub(crate) fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut Diag<'_, ()>) {
450self.universal_regions().annotate(tcx, err)
451 }
452453/// Returns `true` if the region `r` contains the point `p`.
454 ///
455 /// Panics if called before `solve()` executes,
456pub(crate) fn region_contains(&self, r: RegionVid, p: impl ToElementIndex<'tcx>) -> bool {
457let scc = self.constraint_sccs.scc(r);
458self.scc_values.contains(scc, p)
459 }
460461/// Returns the lowest statement index in `start..=end` which is not contained by `r`.
462 ///
463 /// Panics if called before `solve()` executes.
464pub(crate) fn first_non_contained_inclusive(
465&self,
466 r: RegionVid,
467 block: BasicBlock,
468 start: usize,
469 end: usize,
470 ) -> Option<usize> {
471let scc = self.constraint_sccs.scc(r);
472self.scc_values.first_non_contained_inclusive(scc, block, start, end)
473 }
474475/// Returns access to the value of `r` for debugging purposes.
476pub(crate) fn region_value_str(&self, r: RegionVid) -> String {
477let scc = self.constraint_sccs.scc(r);
478self.scc_values.region_value_str(scc)
479 }
480481pub(crate) fn placeholders_contained_in(
482&self,
483 r: RegionVid,
484 ) -> impl Iterator<Item = ty::PlaceholderRegion<'tcx>> {
485let scc = self.constraint_sccs.scc(r);
486self.scc_values.placeholders_contained_in(scc)
487 }
488489/// Performs region inference and report errors if we see any
490 /// unsatisfiable constraints. If this is a closure, returns the
491 /// region requirements to propagate to our creator, if any.
492#[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("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(492u32),
::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(&[]) })
} 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 compiler/rustc_borrowck/src/region_infer/mod.rs:512",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(512u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&["errors_buffer"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&errors_buffer)
as &dyn Value))])
});
} else { ; }
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/region_infer/mod.rs:513",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(513u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&["propagated_outlives_requirements"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&propagated_outlives_requirements)
as &dyn 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 compiler/rustc_borrowck/src/region_infer/mod.rs:533",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(533u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&["errors_buffer"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&errors_buffer)
as &dyn 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")]493pub(super) fn solve(
494&mut self,
495 infcx: &InferCtxt<'tcx>,
496 body: &Body<'tcx>,
497 polonius_output: Option<Box<PoloniusOutput>>,
498 ) -> (Option<ClosureRegionRequirements<'tcx>>, RegionErrors<'tcx>) {
499let mir_def_id = body.source.def_id();
500self.propagate_constraints();
501502let mut errors_buffer = RegionErrors::new(infcx.tcx);
503504// If this is a nested body, we propagate unsatisfied
505 // outlives constraints to the parent body instead of
506 // eagerly erroing.
507let mut propagated_outlives_requirements =
508 infcx.tcx.is_typeck_child(mir_def_id).then(Vec::new);
509510self.check_type_tests(infcx, propagated_outlives_requirements.as_mut(), &mut errors_buffer);
511512debug!(?errors_buffer);
513debug!(?propagated_outlives_requirements);
514515// In Polonius mode, the errors about missing universal region relations are in the output
516 // and need to be emitted or propagated. Otherwise, we need to check whether the
517 // constraints were too strong, and if so, emit or propagate those errors.
518if infcx.tcx.sess.opts.unstable_opts.polonius.is_legacy_enabled() {
519self.check_polonius_subset_errors(
520 propagated_outlives_requirements.as_mut(),
521&mut errors_buffer,
522 polonius_output
523 .as_ref()
524 .expect("Polonius output is unavailable despite `-Z polonius`"),
525 );
526 } else {
527self.check_universal_regions(
528 propagated_outlives_requirements.as_mut(),
529&mut errors_buffer,
530 );
531 }
532533debug!(?errors_buffer);
534535let propagated_outlives_requirements = propagated_outlives_requirements.unwrap_or_default();
536537if propagated_outlives_requirements.is_empty() {
538 (None, errors_buffer)
539 } else {
540let num_external_vids = self.universal_regions().num_global_and_external_regions();
541 (
542Some(ClosureRegionRequirements {
543 num_external_vids,
544 outlives_requirements: propagated_outlives_requirements,
545 }),
546 errors_buffer,
547 )
548 }
549 }
550551/// Propagate the region constraints: this will grow the values
552 /// for each region variable until all the constraints are
553 /// satisfied. Note that some values may grow **too** large to be
554 /// feasible, but we check this later.
555#[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("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(555u32),
::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(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/region_infer/mod.rs:557",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(557u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("constraints={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 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 compiler/rustc_borrowck/src/region_infer/mod.rs:573",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(573u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&["scc_b"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&scc_b) as
&dyn Value))])
});
} else { ; }
};
self.scc_values.add_region(scc_a, scc_b);
}
}
}
}
}#[instrument(skip(self), level = "debug")]556fn propagate_constraints(&mut self) {
557debug!("constraints={:#?}", {
558let mut constraints: Vec<_> = self.outlives_constraints().collect();
559 constraints.sort_by_key(|c| (c.sup, c.sub));
560 constraints
561 .into_iter()
562 .map(|c| (c, self.constraint_sccs.scc(c.sup), self.constraint_sccs.scc(c.sub)))
563 .collect::<Vec<_>>()
564 });
565566// To propagate constraints, we walk the DAG induced by the
567 // SCC. For each SCC `A`, we visit its successors and compute
568 // their values, then we union all those values to get our
569 // own.
570for scc_a in self.constraint_sccs.all_sccs() {
571// Walk each SCC `B` such that `A: B`...
572for &scc_b in self.constraint_sccs.successors(scc_a) {
573debug!(?scc_b);
574self.scc_values.add_region(scc_a, scc_b);
575 }
576 }
577 }
578579/// Returns `true` if all the placeholders in the value of `scc_b` are nameable
580 /// in `scc_a`. Used during constraint propagation, and only once
581 /// the value of `scc_b` has been computed.
582fn can_name_all_placeholders(
583&self,
584 scc_a: ConstraintSccIndex,
585 scc_b: ConstraintSccIndex,
586 ) -> bool {
587self.scc_annotations[scc_a].can_name_all_placeholders(self.scc_annotations[scc_b])
588 }
589590/// Once regions have been propagated, this method is used to see
591 /// whether the "type tests" produced by typeck were satisfied;
592 /// type tests encode type-outlives relationships like `T:
593 /// 'a`. See `TypeTest` for more details.
594fn check_type_tests(
595&self,
596 infcx: &InferCtxt<'tcx>,
597mut propagated_outlives_requirements: Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
598 errors_buffer: &mut RegionErrors<'tcx>,
599 ) {
600let tcx = infcx.tcx;
601602// Sometimes we register equivalent type-tests that would
603 // result in basically the exact same error being reported to
604 // the user. Avoid that.
605let mut deduplicate_errors = FxIndexSet::default();
606607for type_test in &self.type_tests {
608{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/region_infer/mod.rs:608",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(608u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("check_type_test: {0:?}",
type_test) as &dyn Value))])
});
} else { ; }
};debug!("check_type_test: {:?}", type_test);
609610let generic_ty = type_test.generic_kind.to_ty(tcx);
611if self.eval_verify_bound(
612 infcx,
613 generic_ty,
614 type_test.lower_bound,
615&type_test.verify_bound,
616 ) {
617continue;
618 }
619620if let Some(propagated_outlives_requirements) = &mut propagated_outlives_requirements
621 && self.try_promote_type_test(infcx, type_test, propagated_outlives_requirements)
622 {
623continue;
624 }
625626// Type-test failed. Report the error.
627let erased_generic_kind = infcx.tcx.erase_and_anonymize_regions(type_test.generic_kind);
628629// Skip duplicate-ish errors.
630if deduplicate_errors.insert((
631 erased_generic_kind,
632 type_test.lower_bound,
633 type_test.span,
634 )) {
635{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/region_infer/mod.rs:635",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(635u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("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 Value))])
});
} else { ; }
};debug!(
636"check_type_test: reporting error for erased_generic_kind={:?}, \
637 lower_bound_region={:?}, \
638 type_test.span={:?}",
639 erased_generic_kind, type_test.lower_bound, type_test.span,
640 );
641642 errors_buffer.push(RegionErrorKind::TypeTestError { type_test: type_test.clone() });
643 }
644 }
645 }
646647/// Invoked when we have some type-test (e.g., `T: 'X`) that we cannot
648 /// prove to be satisfied. If this is a closure, we will attempt to
649 /// "promote" this type-test into our `ClosureRegionRequirements` and
650 /// hence pass it up the creator. To do this, we have to phrase the
651 /// type-test in terms of external free regions, as local free
652 /// regions are not nameable by the closure's creator.
653 ///
654 /// Promotion works as follows: we first check that the type `T`
655 /// contains only regions that the creator knows about. If this is
656 /// true, then -- as a consequence -- we know that all regions in
657 /// the type `T` are free regions that outlive the closure body. If
658 /// false, then promotion fails.
659 ///
660 /// Once we've promoted T, we have to "promote" `'X` to some region
661 /// that is "external" to the closure. Generally speaking, a region
662 /// may be the union of some points in the closure body as well as
663 /// various free lifetimes. We can ignore the points in the closure
664 /// body: if the type T can be expressed in terms of external regions,
665 /// we know it outlives the points in the closure body. That
666 /// just leaves the free regions.
667 ///
668 /// The idea then is to lower the `T: 'X` constraint into multiple
669 /// bounds -- e.g., if `'X` is the union of two free lifetimes,
670 /// `'1` and `'2`, then we would create `T: '1` and `T: '2`.
671#[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("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(671u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&["type_test"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&type_test)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: 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 compiler/rustc_borrowck/src/region_infer/mod.rs:687",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(687u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("lower_bound = {0:?} r_scc={1:?} universe={2:?}",
lower_bound, r_scc, self.max_nameable_universe(r_scc)) as
&dyn 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 compiler/rustc_borrowck/src/region_infer/mod.rs:700",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(700u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("encountered placeholder in higher universe: {0:?}, requiring \'static",
p) as &dyn 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 compiler/rustc_borrowck/src/region_infer/mod.rs:720",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(720u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("universal_region_outlived_by ur={0:?}",
ur) as &dyn 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 compiler/rustc_borrowck/src/region_infer/mod.rs:722",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(722u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&["non_local_ub"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&non_local_ub)
as &dyn 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 compiler/rustc_borrowck/src/region_infer/mod.rs:738",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("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",
"requirement"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("adding closure requirement")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&requirement)
as &dyn 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))]672fn try_promote_type_test(
673&self,
674 infcx: &InferCtxt<'tcx>,
675 type_test: &TypeTest<'tcx>,
676 propagated_outlives_requirements: &mut Vec<ClosureOutlivesRequirement<'tcx>>,
677 ) -> bool {
678let tcx = infcx.tcx;
679let TypeTest { generic_kind, lower_bound, span: blame_span, verify_bound: _ } = *type_test;
680681let generic_ty = generic_kind.to_ty(tcx);
682let Some(subject) = self.try_promote_type_test_subject(infcx, generic_ty) else {
683return false;
684 };
685686let r_scc = self.constraint_sccs.scc(lower_bound);
687debug!(
688"lower_bound = {:?} r_scc={:?} universe={:?}",
689 lower_bound,
690 r_scc,
691self.max_nameable_universe(r_scc)
692 );
693// If the type test requires that `T: 'a` where `'a` is a
694 // placeholder from another universe, that effectively requires
695 // `T: 'static`, so we have to propagate that requirement.
696 //
697 // It doesn't matter *what* universe because the promoted `T` will
698 // always be in the root universe.
699if let Some(p) = self.scc_values.placeholders_contained_in(r_scc).next() {
700debug!("encountered placeholder in higher universe: {:?}, requiring 'static", p);
701let static_r = self.universal_regions().fr_static;
702 propagated_outlives_requirements.push(ClosureOutlivesRequirement {
703 subject,
704 outlived_free_region: static_r,
705 blame_span,
706 category: ConstraintCategory::Boring,
707 });
708709// we can return here -- the code below might push add'l constraints
710 // but they would all be weaker than this one.
711return true;
712 }
713714// For each region outlived by lower_bound find a non-local,
715 // universal region (it may be the same region) and add it to
716 // `ClosureOutlivesRequirement`.
717let mut found_outlived_universal_region = false;
718for ur in self.scc_values.universal_regions_outlived_by(r_scc) {
719 found_outlived_universal_region = true;
720debug!("universal_region_outlived_by ur={:?}", ur);
721let non_local_ub = self.universal_region_relations.non_local_upper_bounds(ur);
722debug!(?non_local_ub);
723724// This is slightly too conservative. To show T: '1, given `'2: '1`
725 // and `'3: '1` we only need to prove that T: '2 *or* T: '3, but to
726 // avoid potential non-determinism we approximate this by requiring
727 // T: '1 and T: '2.
728for upper_bound in non_local_ub {
729debug_assert!(self.universal_regions().is_universal_region(upper_bound));
730debug_assert!(!self.universal_regions().is_local_free_region(upper_bound));
731732let requirement = ClosureOutlivesRequirement {
733 subject,
734 outlived_free_region: upper_bound,
735 blame_span,
736 category: ConstraintCategory::Boring,
737 };
738debug!(?requirement, "adding closure requirement");
739 propagated_outlives_requirements.push(requirement);
740 }
741 }
742// If we succeed to promote the subject, i.e. it only contains non-local regions,
743 // and fail to prove the type test inside of the closure, the `lower_bound` has to
744 // also be at least as large as some universal region, as the type test is otherwise
745 // trivial.
746assert!(found_outlived_universal_region);
747true
748}
749750/// When we promote a type test `T: 'r`, we have to replace all region
751 /// variables in the type `T` with an equal universal region from the
752 /// closure signature.
753 /// This is not always possible, so this is a fallible process.
754x;#[instrument(level = "debug", skip(self, infcx), ret)]755fn try_promote_type_test_subject(
756&self,
757 infcx: &InferCtxt<'tcx>,
758 ty: Ty<'tcx>,
759 ) -> Option<ClosureOutlivesSubject<'tcx>> {
760let tcx = infcx.tcx;
761let mut failed = false;
762let ty = fold_regions(tcx, ty, |r, _depth| {
763let r_vid = self.to_region_vid(r);
764let r_scc = self.constraint_sccs.scc(r_vid);
765766// The challenge is this. We have some region variable `r`
767 // whose value is a set of CFG points and universal
768 // regions. We want to find if that set is *equivalent* to
769 // any of the named regions found in the closure.
770 // To do so, we simply check every candidate `u_r` for equality.
771self.scc_values
772 .universal_regions_outlived_by(r_scc)
773 .filter(|&u_r| !self.universal_regions().is_local_free_region(u_r))
774 .find(|&u_r| self.eval_equal(u_r, r_vid))
775 .map(|u_r| ty::Region::new_var(tcx, u_r))
776// In case we could not find a named region to map to,
777 // we will return `None` below.
778.unwrap_or_else(|| {
779 failed = true;
780 r
781 })
782 });
783784debug!("try_promote_type_test_subject: folded ty = {:?}", ty);
785786// This will be true if we failed to promote some region.
787if failed {
788return None;
789 }
790791Some(ClosureOutlivesSubject::Ty(ClosureOutlivesSubjectTy::bind(tcx, ty)))
792 }
793794/// Like `universal_upper_bound`, but returns an approximation more suitable
795 /// for diagnostics. If `r` contains multiple disjoint universal regions
796 /// (e.g. 'a and 'b in `fn foo<'a, 'b> { ... }`, we pick the lower-numbered region.
797 /// This corresponds to picking named regions over unnamed regions
798 /// (e.g. picking early-bound regions over a closure late-bound region).
799 ///
800 /// This means that the returned value may not be a true upper bound, since
801 /// only 'static is known to outlive disjoint universal regions.
802 /// Therefore, this method should only be used in diagnostic code,
803 /// where displaying *some* named universal region is better than
804 /// falling back to 'static.
805#[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("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(805u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&["r"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&r)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: 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 compiler/rustc_borrowck/src/region_infer/mod.rs:807",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(807u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("{0}",
self.region_value_str(r)) as &dyn 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 compiler/rustc_borrowck/src/region_infer/mod.rs:816",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(816u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&["ur", "lub",
"new_lub"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&ur) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&lub) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&new_lub) as
&dyn 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 compiler/rustc_borrowck/src/region_infer/mod.rs:840",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(840u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&["r", "lub"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&r) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&lub) as
&dyn Value))])
});
} else { ; }
};
lub
}
}
}#[instrument(level = "debug", skip(self))]806pub(crate) fn approx_universal_upper_bound(&self, r: RegionVid) -> RegionVid {
807debug!("{}", self.region_value_str(r));
808809// Find the smallest universal region that contains all other
810 // universal regions within `region`.
811let mut lub = self.universal_regions().fr_fn_body;
812let r_scc = self.constraint_sccs.scc(r);
813let static_r = self.universal_regions().fr_static;
814for ur in self.scc_values.universal_regions_outlived_by(r_scc) {
815let new_lub = self.universal_region_relations.postdom_upper_bound(lub, ur);
816debug!(?ur, ?lub, ?new_lub);
817// The upper bound of two non-static regions is static: this
818 // means we know nothing about the relationship between these
819 // two regions. Pick a 'better' one to use when constructing
820 // a diagnostic
821if ur != static_r && lub != static_r && new_lub == static_r {
822// Prefer the region with an `external_name` - this
823 // indicates that the region is early-bound, so working with
824 // it can produce a nicer error.
825if self.region_definition(ur).external_name.is_some() {
826 lub = ur;
827 } else if self.region_definition(lub).external_name.is_some() {
828// Leave lub unchanged
829} else {
830// If we get here, we don't have any reason to prefer
831 // one region over the other. Just pick the
832 // one with the lower index for now.
833lub = std::cmp::min(ur, lub);
834 }
835 } else {
836 lub = new_lub;
837 }
838 }
839840debug!(?r, ?lub);
841842 lub
843 }
844845/// Tests if `test` is true when applied to `lower_bound` at
846 /// `point`.
847fn eval_verify_bound(
848&self,
849 infcx: &InferCtxt<'tcx>,
850 generic_ty: Ty<'tcx>,
851 lower_bound: RegionVid,
852 verify_bound: &VerifyBound<'tcx>,
853 ) -> bool {
854{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/region_infer/mod.rs:854",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(854u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("eval_verify_bound(lower_bound={0:?}, verify_bound={1:?})",
lower_bound, verify_bound) as &dyn Value))])
});
} else { ; }
};debug!("eval_verify_bound(lower_bound={:?}, verify_bound={:?})", lower_bound, verify_bound);
855856match verify_bound {
857 VerifyBound::IfEq(verify_if_eq_b) => {
858self.eval_if_eq(infcx, generic_ty, lower_bound, *verify_if_eq_b)
859 }
860861 VerifyBound::IsEmpty => {
862let lower_bound_scc = self.constraint_sccs.scc(lower_bound);
863self.scc_values.elements_contained_in(lower_bound_scc).next().is_none()
864 }
865866 VerifyBound::OutlivedBy(r) => {
867let r_vid = self.to_region_vid(*r);
868self.eval_outlives(r_vid, lower_bound)
869 }
870871 VerifyBound::AnyBound(verify_bounds) => verify_bounds.iter().any(|verify_bound| {
872self.eval_verify_bound(infcx, generic_ty, lower_bound, verify_bound)
873 }),
874875 VerifyBound::AllBounds(verify_bounds) => verify_bounds.iter().all(|verify_bound| {
876self.eval_verify_bound(infcx, generic_ty, lower_bound, verify_bound)
877 }),
878 }
879 }
880881fn eval_if_eq(
882&self,
883 infcx: &InferCtxt<'tcx>,
884 generic_ty: Ty<'tcx>,
885 lower_bound: RegionVid,
886 verify_if_eq_b: ty::Binder<'tcx, VerifyIfEq<'tcx>>,
887 ) -> bool {
888let generic_ty = self.normalize_to_scc_representatives(infcx.tcx, generic_ty);
889let verify_if_eq_b = self.normalize_to_scc_representatives(infcx.tcx, verify_if_eq_b);
890match test_type_match::extract_verify_if_eq(infcx.tcx, &verify_if_eq_b, generic_ty) {
891Some(r) => {
892let r_vid = self.to_region_vid(r);
893self.eval_outlives(r_vid, lower_bound)
894 }
895None => false,
896 }
897 }
898899/// This is a conservative normalization procedure. It takes every
900 /// free region in `value` and replaces it with the
901 /// "representative" of its SCC (see `scc_representatives` field).
902 /// We are guaranteed that if two values normalize to the same
903 /// thing, then they are equal; this is a conservative check in
904 /// that they could still be equal even if they normalize to
905 /// different results. (For example, there might be two regions
906 /// with the same value that are not in the same SCC).
907 ///
908 /// N.B., this is not an ideal approach and I would like to revisit
909 /// it. However, it works pretty well in practice. In particular,
910 /// this is needed to deal with projection outlives bounds like
911 ///
912 /// ```text
913 /// <T as Foo<'0>>::Item: '1
914 /// ```
915 ///
916 /// In particular, this routine winds up being important when
917 /// there are bounds like `where <T as Foo<'a>>::Item: 'b` in the
918 /// environment. In this case, if we can show that `'0 == 'a`,
919 /// and that `'b: '1`, then we know that the clause is
920 /// satisfied. In such cases, particularly due to limitations of
921 /// the trait solver =), we usually wind up with a where-clause like
922 /// `T: Foo<'a>` in scope, which thus forces `'0 == 'a` to be added as
923 /// a constraint, and thus ensures that they are in the same SCC.
924 ///
925 /// So why can't we do a more correct routine? Well, we could
926 /// *almost* use the `relate_tys` code, but the way it is
927 /// currently setup it creates inference variables to deal with
928 /// higher-ranked things and so forth, and right now the inference
929 /// context is not permitted to make more inference variables. So
930 /// we use this kind of hacky solution.
931fn normalize_to_scc_representatives<T>(&self, tcx: TyCtxt<'tcx>, value: T) -> T
932where
933T: TypeFoldable<TyCtxt<'tcx>>,
934 {
935fold_regions(tcx, value, |r, _db| {
936let vid = self.to_region_vid(r);
937let scc = self.constraint_sccs.scc(vid);
938let repr = self.scc_representative(scc);
939 ty::Region::new_var(tcx, repr)
940 })
941 }
942943/// Evaluate whether `sup_region == sub_region`.
944 ///
945 /// Panics if called before `solve()` executes,
946// This is `pub` because it's used by unstable external borrowck data users, see `consumers.rs`.
947pub fn eval_equal(&self, r1: RegionVid, r2: RegionVid) -> bool {
948self.eval_outlives(r1, r2) && self.eval_outlives(r2, r1)
949 }
950951/// Evaluate whether `sup_region: sub_region`.
952 ///
953 /// Panics if called before `solve()` executes,
954// This is `pub` because it's used by unstable external borrowck data users, see `consumers.rs`.
955x;#[instrument(skip(self), level = "debug", ret)]956pub fn eval_outlives(&self, sup_region: RegionVid, sub_region: RegionVid) -> bool {
957debug!(
958"sup_region's value = {:?} universal={:?}",
959self.region_value_str(sup_region),
960self.universal_regions().is_universal_region(sup_region),
961 );
962debug!(
963"sub_region's value = {:?} universal={:?}",
964self.region_value_str(sub_region),
965self.universal_regions().is_universal_region(sub_region),
966 );
967968let sub_region_scc = self.constraint_sccs.scc(sub_region);
969let sup_region_scc = self.constraint_sccs.scc(sup_region);
970971if sub_region_scc == sup_region_scc {
972debug!("{sup_region:?}: {sub_region:?} holds trivially; they are in the same SCC");
973return true;
974 }
975976let fr_static = self.universal_regions().fr_static;
977978// If we are checking that `'sup: 'sub`, and `'sub` contains
979 // some placeholder that `'sup` cannot name, then this is only
980 // true if `'sup` outlives static.
981 //
982 // Avoid infinite recursion if `sub_region` is already `'static`
983if sub_region != fr_static
984 && !self.can_name_all_placeholders(sup_region_scc, sub_region_scc)
985 {
986debug!(
987"sub universe `{sub_region_scc:?}` is not nameable \
988 by super `{sup_region_scc:?}`, promoting to static",
989 );
990991return self.eval_outlives(sup_region, fr_static);
992 }
993994// Both the `sub_region` and `sup_region` consist of the union
995 // of some number of universal regions (along with the union
996 // of various points in the CFG; ignore those points for
997 // now). Therefore, the sup-region outlives the sub-region if,
998 // for each universal region R1 in the sub-region, there
999 // exists some region R2 in the sup-region that outlives R1.
1000let universal_outlives =
1001self.scc_values.universal_regions_outlived_by(sub_region_scc).all(|r1| {
1002self.scc_values
1003 .universal_regions_outlived_by(sup_region_scc)
1004 .any(|r2| self.universal_region_relations.outlives(r2, r1))
1005 });
10061007if !universal_outlives {
1008debug!("sub region contains a universal region not present in super");
1009return false;
1010 }
10111012// Now we have to compare all the points in the sub region and make
1013 // sure they exist in the sup region.
10141015if self.universal_regions().is_universal_region(sup_region) {
1016// Micro-opt: universal regions contain all points.
1017debug!("super is universal and hence contains all points");
1018return true;
1019 }
10201021debug!("comparison between points in sup/sub");
10221023self.scc_values.contains_points(sup_region_scc, sub_region_scc)
1024 }
10251026/// Once regions have been propagated, this method is used to see
1027 /// whether any of the constraints were too strong. In particular,
1028 /// we want to check for a case where a universally quantified
1029 /// region exceeded its bounds. Consider:
1030 /// ```compile_fail
1031 /// fn foo<'a, 'b>(x: &'a u32) -> &'b u32 { x }
1032 /// ```
1033 /// In this case, returning `x` requires `&'a u32 <: &'b u32`
1034 /// and hence we establish (transitively) a constraint that
1035 /// `'a: 'b`. The `propagate_constraints` code above will
1036 /// therefore add `end('a)` into the region for `'b` -- but we
1037 /// have no evidence that `'b` outlives `'a`, so we want to report
1038 /// an error.
1039 ///
1040 /// If `propagated_outlives_requirements` is `Some`, then we will
1041 /// push unsatisfied obligations into there. Otherwise, we'll
1042 /// report them as errors.
1043fn check_universal_regions(
1044&self,
1045mut propagated_outlives_requirements: Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
1046 errors_buffer: &mut RegionErrors<'tcx>,
1047 ) {
1048for (fr, fr_definition) in self.definitions.iter_enumerated() {
1049{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/region_infer/mod.rs:1049",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1049u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&["fr",
"fr_definition"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&fr) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&fr_definition)
as &dyn Value))])
});
} else { ; }
};debug!(?fr, ?fr_definition);
1050match fr_definition.origin {
1051 NllRegionVariableOrigin::FreeRegion => {
1052// Go through each of the universal regions `fr` and check that
1053 // they did not grow too large, accumulating any requirements
1054 // for our caller into the `outlives_requirements` vector.
1055self.check_universal_region(
1056 fr,
1057&mut propagated_outlives_requirements,
1058 errors_buffer,
1059 );
1060 }
10611062 NllRegionVariableOrigin::Placeholder(placeholder) => {
1063self.check_bound_universal_region(fr, placeholder, errors_buffer);
1064 }
10651066 NllRegionVariableOrigin::Existential { .. } => {
1067// nothing to check here
1068}
1069 }
1070 }
1071 }
10721073/// Checks if Polonius has found any unexpected free region relations.
1074 ///
1075 /// In Polonius terms, a "subset error" (or "illegal subset relation error") is the equivalent
1076 /// of NLL's "checking if any region constraints were too strong": a placeholder origin `'a`
1077 /// was unexpectedly found to be a subset of another placeholder origin `'b`, and means in NLL
1078 /// terms that the "longer free region" `'a` outlived the "shorter free region" `'b`.
1079 ///
1080 /// More details can be found in this blog post by Niko:
1081 /// <https://smallcultfollowing.com/babysteps/blog/2019/01/17/polonius-and-region-errors/>
1082 ///
1083 /// In the canonical example
1084 /// ```compile_fail
1085 /// fn foo<'a, 'b>(x: &'a u32) -> &'b u32 { x }
1086 /// ```
1087 /// returning `x` requires `&'a u32 <: &'b u32` and hence we establish (transitively) a
1088 /// constraint that `'a: 'b`. It is an error that we have no evidence that this
1089 /// constraint holds.
1090 ///
1091 /// If `propagated_outlives_requirements` is `Some`, then we will
1092 /// push unsatisfied obligations into there. Otherwise, we'll
1093 /// report them as errors.
1094fn check_polonius_subset_errors(
1095&self,
1096mut propagated_outlives_requirements: Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
1097 errors_buffer: &mut RegionErrors<'tcx>,
1098 polonius_output: &PoloniusOutput,
1099 ) {
1100{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/region_infer/mod.rs:1100",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1100u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("check_polonius_subset_errors: {0} subset_errors",
polonius_output.subset_errors.len()) as &dyn Value))])
});
} else { ; }
};debug!(
1101"check_polonius_subset_errors: {} subset_errors",
1102 polonius_output.subset_errors.len()
1103 );
11041105// Similarly to `check_universal_regions`: a free region relation, which was not explicitly
1106 // declared ("known") was found by Polonius, so emit an error, or propagate the
1107 // requirements for our caller into the `propagated_outlives_requirements` vector.
1108 //
1109 // Polonius doesn't model regions ("origins") as CFG-subsets or durations, but the
1110 // `longer_fr` and `shorter_fr` terminology will still be used here, for consistency with
1111 // the rest of the NLL infrastructure. The "subset origin" is the "longer free region",
1112 // and the "superset origin" is the outlived "shorter free region".
1113 //
1114 // Note: Polonius will produce a subset error at every point where the unexpected
1115 // `longer_fr`'s "placeholder loan" is contained in the `shorter_fr`. This can be helpful
1116 // for diagnostics in the future, e.g. to point more precisely at the key locations
1117 // requiring this constraint to hold. However, the error and diagnostics code downstream
1118 // expects that these errors are not duplicated (and that they are in a certain order).
1119 // Otherwise, diagnostics messages such as the ones giving names like `'1` to elided or
1120 // anonymous lifetimes for example, could give these names differently, while others like
1121 // the outlives suggestions or the debug output from `#[rustc_regions]` would be
1122 // duplicated. The polonius subset errors are deduplicated here, while keeping the
1123 // CFG-location ordering.
1124 // We can iterate the HashMap here because the result is sorted afterwards.
1125#[allow(rustc::potential_query_instability)]
1126let mut subset_errors: Vec<_> = polonius_output1127 .subset_errors
1128 .iter()
1129 .flat_map(|(_location, subset_errors)| subset_errors.iter())
1130 .collect();
1131subset_errors.sort();
1132subset_errors.dedup();
11331134for &(longer_fr, shorter_fr) in subset_errors.into_iter() {
1135{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/region_infer/mod.rs:1135",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1135u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("check_polonius_subset_errors: subset_error longer_fr={0:?},shorter_fr={1:?}",
longer_fr, shorter_fr) as &dyn Value))])
});
} else { ; }
};debug!(
1136"check_polonius_subset_errors: subset_error longer_fr={:?},\
1137 shorter_fr={:?}",
1138 longer_fr, shorter_fr
1139 );
11401141let propagated = self.try_propagate_universal_region_error(
1142 longer_fr.into(),
1143 shorter_fr.into(),
1144&mut propagated_outlives_requirements,
1145 );
1146if propagated == RegionRelationCheckResult::Error {
1147 errors_buffer.push(RegionErrorKind::RegionError {
1148 longer_fr: longer_fr.into(),
1149 shorter_fr: shorter_fr.into(),
1150 fr_origin: NllRegionVariableOrigin::FreeRegion,
1151 is_reported: true,
1152 });
1153 }
1154 }
11551156// Handle the placeholder errors as usual, until the chalk-rustc-polonius triumvirate has
1157 // a more complete picture on how to separate this responsibility.
1158for (fr, fr_definition) in self.definitions.iter_enumerated() {
1159match fr_definition.origin {
1160 NllRegionVariableOrigin::FreeRegion => {
1161// handled by polonius above
1162}
11631164 NllRegionVariableOrigin::Placeholder(placeholder) => {
1165self.check_bound_universal_region(fr, placeholder, errors_buffer);
1166 }
11671168 NllRegionVariableOrigin::Existential { .. } => {
1169// nothing to check here
1170}
1171 }
1172 }
1173 }
11741175/// The largest universe of any region nameable from this SCC.
1176fn max_nameable_universe(&self, scc: ConstraintSccIndex) -> UniverseIndex {
1177self.scc_annotations[scc].max_nameable_universe()
1178 }
11791180/// Checks the final value for the free region `fr` to see if it
1181 /// grew too large. In particular, examine what `end(X)` points
1182 /// wound up in `fr`'s final value; for each `end(X)` where `X !=
1183 /// fr`, we want to check that `fr: X`. If not, that's either an
1184 /// error, or something we have to propagate to our creator.
1185 ///
1186 /// Things that are to be propagated are accumulated into the
1187 /// `outlives_requirements` vector.
1188#[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("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1188u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&["longer_fr"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&longer_fr)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let 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")]1189fn check_universal_region(
1190&self,
1191 longer_fr: RegionVid,
1192 propagated_outlives_requirements: &mut Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
1193 errors_buffer: &mut RegionErrors<'tcx>,
1194 ) {
1195let longer_fr_scc = self.constraint_sccs.scc(longer_fr);
11961197// Because this free region must be in the ROOT universe, we
1198 // know it cannot contain any bound universes.
1199assert!(self.max_nameable_universe(longer_fr_scc).is_root());
12001201// Only check all of the relations for the main representative of each
1202 // SCC, otherwise just check that we outlive said representative. This
1203 // reduces the number of redundant relations propagated out of
1204 // closures.
1205 // Note that the representative will be a universal region if there is
1206 // one in this SCC, so we will always check the representative here.
1207let representative = self.scc_representative(longer_fr_scc);
1208if representative != longer_fr {
1209if let RegionRelationCheckResult::Error = self.check_universal_region_relation(
1210 longer_fr,
1211 representative,
1212 propagated_outlives_requirements,
1213 ) {
1214 errors_buffer.push(RegionErrorKind::RegionError {
1215 longer_fr,
1216 shorter_fr: representative,
1217 fr_origin: NllRegionVariableOrigin::FreeRegion,
1218 is_reported: true,
1219 });
1220 }
1221return;
1222 }
12231224// Find every region `o` such that `fr: o`
1225 // (because `fr` includes `end(o)`).
1226let mut error_reported = false;
1227for shorter_fr in self.scc_values.universal_regions_outlived_by(longer_fr_scc) {
1228if let RegionRelationCheckResult::Error = self.check_universal_region_relation(
1229 longer_fr,
1230 shorter_fr,
1231 propagated_outlives_requirements,
1232 ) {
1233// We only report the first region error. Subsequent errors are hidden so as
1234 // not to overwhelm the user, but we do record them so as to potentially print
1235 // better diagnostics elsewhere...
1236errors_buffer.push(RegionErrorKind::RegionError {
1237 longer_fr,
1238 shorter_fr,
1239 fr_origin: NllRegionVariableOrigin::FreeRegion,
1240 is_reported: !error_reported,
1241 });
12421243 error_reported = true;
1244 }
1245 }
1246 }
12471248/// Checks that we can prove that `longer_fr: shorter_fr`. If we can't we attempt to propagate
1249 /// the constraint outward (e.g. to a closure environment), but if that fails, there is an
1250 /// error.
1251fn check_universal_region_relation(
1252&self,
1253 longer_fr: RegionVid,
1254 shorter_fr: RegionVid,
1255 propagated_outlives_requirements: &mut Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
1256 ) -> RegionRelationCheckResult {
1257// If it is known that `fr: o`, carry on.
1258if self.universal_region_relations.outlives(longer_fr, shorter_fr) {
1259 RegionRelationCheckResult::Ok1260 } else {
1261// If we are not in a context where we can't propagate errors, or we
1262 // could not shrink `fr` to something smaller, then just report an
1263 // error.
1264 //
1265 // Note: in this case, we use the unapproximated regions to report the
1266 // error. This gives better error messages in some cases.
1267self.try_propagate_universal_region_error(
1268longer_fr,
1269shorter_fr,
1270propagated_outlives_requirements,
1271 )
1272 }
1273 }
12741275/// Attempt to propagate a region error (e.g. `'a: 'b`) that is not met to a closure's
1276 /// creator. If we cannot, then the caller should report an error to the user.
1277fn try_propagate_universal_region_error(
1278&self,
1279 longer_fr: RegionVid,
1280 shorter_fr: RegionVid,
1281 propagated_outlives_requirements: &mut Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
1282 ) -> RegionRelationCheckResult {
1283if let Some(propagated_outlives_requirements) = propagated_outlives_requirements {
1284// Shrink `longer_fr` until we find some non-local regions.
1285 // We'll call them `longer_fr-` -- they are ever so slightly smaller than
1286 // `longer_fr`.
1287let longer_fr_minus = self.universal_region_relations.non_local_lower_bounds(longer_fr);
12881289{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/region_infer/mod.rs:1289",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1289u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("try_propagate_universal_region_error: fr_minus={0:?}",
longer_fr_minus) as &dyn Value))])
});
} else { ; }
};debug!("try_propagate_universal_region_error: fr_minus={:?}", longer_fr_minus);
12901291// If we don't find a any non-local regions, we should error out as there is nothing
1292 // to propagate.
1293if longer_fr_minus.is_empty() {
1294return RegionRelationCheckResult::Error;
1295 }
12961297let blame_constraint = self1298 .best_blame_constraint(longer_fr, NllRegionVariableOrigin::FreeRegion, shorter_fr)
1299 .0;
13001301// Grow `shorter_fr` until we find some non-local regions.
1302 // We will always find at least one: `'static`. We'll call
1303 // them `shorter_fr+` -- they're ever so slightly larger
1304 // than `shorter_fr`.
1305let shorter_fr_plus =
1306self.universal_region_relations.non_local_upper_bounds(shorter_fr);
1307{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/region_infer/mod.rs:1307",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("try_propagate_universal_region_error: shorter_fr_plus={0:?}",
shorter_fr_plus) as &dyn Value))])
});
} else { ; }
};debug!("try_propagate_universal_region_error: shorter_fr_plus={:?}", shorter_fr_plus);
13081309// We then create constraints `longer_fr-: shorter_fr+` that may or may not
1310 // be propagated (see below).
1311let mut constraints = ::alloc::vec::Vec::new()vec![];
1312for fr_minus in longer_fr_minus {
1313for shorter_fr_plus in &shorter_fr_plus {
1314 constraints.push((fr_minus, *shorter_fr_plus));
1315 }
1316 }
13171318// We only need to propagate at least one of the constraints for
1319 // soundness. However, we want to avoid arbitrary choices here
1320 // and currently don't support returning OR constraints.
1321 //
1322 // If any of the `shorter_fr+` regions are already outlived by `longer_fr-`,
1323 // we propagate only those.
1324 //
1325 // Consider this example (`'b: 'a` == `a -> b`), where we try to propagate `'d: 'a`:
1326 // a --> b --> d
1327 // \
1328 // \-> c
1329 // Here, `shorter_fr+` of `'a` == `['b, 'c]`.
1330 // Propagating `'d: 'b` is correct and should occur; `'d: 'c` is redundant because of
1331 // `'d: 'b` and could reject valid code.
1332 //
1333 // So we filter the constraints to regions already outlived by `longer_fr-`, but if
1334 // the filter yields an empty set, we fall back to the original one.
1335let subset: Vec<_> = constraints1336 .iter()
1337 .filter(|&&(fr_minus, shorter_fr_plus)| {
1338self.eval_outlives(fr_minus, shorter_fr_plus)
1339 })
1340 .copied()
1341 .collect();
1342let propagated_constraints = if subset.is_empty() { constraints } else { subset };
1343{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/region_infer/mod.rs:1343",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1343u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("try_propagate_universal_region_error: constraints={0:?}",
propagated_constraints) as &dyn Value))])
});
} else { ; }
};debug!(
1344"try_propagate_universal_region_error: constraints={:?}",
1345 propagated_constraints
1346 );
13471348if !!propagated_constraints.is_empty() {
{
::core::panicking::panic_fmt(format_args!("Expected at least one constraint to propagate here"));
}
};assert!(
1349 !propagated_constraints.is_empty(),
1350"Expected at least one constraint to propagate here"
1351);
13521353for (fr_minus, fr_plus) in propagated_constraints {
1354// Push the constraint `long_fr-: shorter_fr+`
1355propagated_outlives_requirements.push(ClosureOutlivesRequirement {
1356 subject: ClosureOutlivesSubject::Region(fr_minus),
1357 outlived_free_region: fr_plus,
1358 blame_span: blame_constraint.cause.span,
1359 category: blame_constraint.category,
1360 });
1361 }
1362return RegionRelationCheckResult::Propagated;
1363 }
13641365 RegionRelationCheckResult::Error1366 }
13671368fn check_bound_universal_region(
1369&self,
1370 longer_fr: RegionVid,
1371 placeholder: ty::PlaceholderRegion<'tcx>,
1372 errors_buffer: &mut RegionErrors<'tcx>,
1373 ) {
1374{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/region_infer/mod.rs:1374",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1374u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("check_bound_universal_region(fr={0:?}, placeholder={1:?})",
longer_fr, placeholder) as &dyn Value))])
});
} else { ; }
};debug!("check_bound_universal_region(fr={:?}, placeholder={:?})", longer_fr, placeholder,);
13751376let longer_fr_scc = self.constraint_sccs.scc(longer_fr);
1377{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/region_infer/mod.rs:1377",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1377u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("check_bound_universal_region: longer_fr_scc={0:?}",
longer_fr_scc) as &dyn Value))])
});
} else { ; }
};debug!("check_bound_universal_region: longer_fr_scc={:?}", longer_fr_scc,);
13781379// If we have some bound universal region `'a`, then the only
1380 // elements it can contain is itself -- we don't know anything
1381 // else about it!
1382if let Some(error_element) = self1383 .scc_values
1384 .elements_contained_in(longer_fr_scc)
1385 .find(|e| *e != RegionElement::PlaceholderRegion(placeholder))
1386 {
1387let illegally_outlived_r = self.region_from_element(longer_fr, &error_element);
1388// Stop after the first error, it gets too noisy otherwise, and does not provide more information.
1389errors_buffer.push(RegionErrorKind::PlaceholderOutlivesIllegalRegion {
1390longer_fr,
1391illegally_outlived_r,
1392 });
1393 } else {
1394{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/region_infer/mod.rs:1394",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1394u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("check_bound_universal_region: all bounds satisfied")
as &dyn Value))])
});
} else { ; }
};debug!("check_bound_universal_region: all bounds satisfied");
1395 }
1396 }
13971398pub(crate) fn constraint_path_between_regions(
1399&self,
1400 from_region: RegionVid,
1401 to_region: RegionVid,
1402 ) -> Option<Vec<OutlivesConstraint<'tcx>>> {
1403if from_region == to_region {
1404::rustc_middle::util::bug::bug_fmt(format_args!("Tried to find a path between {0:?} and itself!",
from_region));bug!("Tried to find a path between {from_region:?} and itself!");
1405 }
1406self.constraint_path_to(from_region, |to| to == to_region, true).map(|o| o.0)
1407 }
14081409/// Walks the graph of constraints (where `'a: 'b` is considered
1410 /// an edge `'a -> 'b`) to find a path from `from_region` to
1411 /// `to_region`.
1412 ///
1413 /// Returns: a series of constraints as well as the region `R`
1414 /// that passed the target test.
1415 /// If `include_static_outlives_all` is `true`, then the synthetic
1416 /// outlives constraints `'static -> a` for every region `a` are
1417 /// considered in the search, otherwise they are ignored.
1418x;#[instrument(skip(self, target_test), ret)]1419pub(crate) fn constraint_path_to(
1420&self,
1421 from_region: RegionVid,
1422 target_test: impl Fn(RegionVid) -> bool,
1423 include_placeholder_static: bool,
1424 ) -> Option<(Vec<OutlivesConstraint<'tcx>>, RegionVid)> {
1425self.find_constraint_path_between_regions_inner(
1426true,
1427 from_region,
1428&target_test,
1429 include_placeholder_static,
1430 )
1431 .or_else(|| {
1432self.find_constraint_path_between_regions_inner(
1433false,
1434 from_region,
1435&target_test,
1436 include_placeholder_static,
1437 )
1438 })
1439 }
14401441/// The constraints we get from equating the hidden type of each use of an opaque
1442 /// with its final hidden type may end up getting preferred over other, potentially
1443 /// longer constraint paths.
1444 ///
1445 /// Given that we compute the final hidden type by relying on this existing constraint
1446 /// path, this can easily end up hiding the actual reason for why we require these regions
1447 /// to be equal.
1448 ///
1449 /// To handle this, we first look at the path while ignoring these constraints and then
1450 /// retry while considering them. This is not perfect, as the `from_region` may have already
1451 /// been partially related to its argument region, so while we rely on a member constraint
1452 /// to get a complete path, the most relevant step of that path already existed before then.
1453fn find_constraint_path_between_regions_inner(
1454&self,
1455 ignore_opaque_type_constraints: bool,
1456 from_region: RegionVid,
1457 target_test: impl Fn(RegionVid) -> bool,
1458 include_placeholder_static: bool,
1459 ) -> Option<(Vec<OutlivesConstraint<'tcx>>, RegionVid)> {
1460let mut context = IndexVec::from_elem(Trace::NotVisited, &self.definitions);
1461context[from_region] = Trace::StartRegion;
14621463let fr_static = self.universal_regions().fr_static;
14641465// Use a deque so that we do a breadth-first search. We will
1466 // stop at the first match, which ought to be the shortest
1467 // path (fewest constraints).
1468let mut deque = VecDeque::new();
1469deque.push_back(from_region);
14701471while let Some(r) = deque.pop_front() {
1472{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/region_infer/mod.rs:1472",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1472u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("constraint_path_to: from_region={0:?} r={1:?} value={2}",
from_region, r, self.region_value_str(r)) as &dyn Value))])
});
} else { ; }
};debug!(
1473"constraint_path_to: from_region={:?} r={:?} value={}",
1474 from_region,
1475 r,
1476self.region_value_str(r),
1477 );
14781479// Check if we reached the region we were looking for. If so,
1480 // we can reconstruct the path that led to it and return it.
1481if target_test(r) {
1482let mut result = ::alloc::vec::Vec::new()vec![];
1483let mut p = r;
1484// This loop is cold and runs at the end, which is why we delay
1485 // `OutlivesConstraint` construction until now.
1486loop {
1487match context[p] {
1488 Trace::FromGraph(c) => {
1489 p = c.sup;
1490 result.push(*c);
1491 }
14921493 Trace::FromStatic(sub) => {
1494let c = OutlivesConstraint {
1495 sup: fr_static,
1496 sub,
1497 locations: Locations::All(DUMMY_SP),
1498 span: DUMMY_SP,
1499 category: ConstraintCategory::Internal,
1500 variance_info: ty::VarianceDiagInfo::default(),
1501 from_closure: false,
1502 };
1503 p = c.sup;
1504 result.push(c);
1505 }
15061507 Trace::StartRegion => {
1508 result.reverse();
1509return Some((result, r));
1510 }
15111512 Trace::NotVisited => {
1513::rustc_middle::util::bug::bug_fmt(format_args!("found unvisited region {0:?} on path to {1:?}",
p, r))bug!("found unvisited region {:?} on path to {:?}", p, r)1514 }
1515 }
1516 }
1517 }
15181519// Otherwise, walk over the outgoing constraints and
1520 // enqueue any regions we find, keeping track of how we
1521 // reached them.
15221523 // A constraint like `'r: 'x` can come from our constraint
1524 // graph.
15251526 // Always inline this closure because it can be hot.
1527let mut handle_trace = #[inline(always)]
1528|sub, trace| {
1529if let Trace::NotVisited = context[sub] {
1530 context[sub] = trace;
1531 deque.push_back(sub);
1532 }
1533 };
15341535// If this is the `'static` region and the graph's direction is normal, then set up the
1536 // Edges iterator to return all regions (#53178).
1537if r == fr_static && self.constraint_graph.is_normal() {
1538for sub in self.constraint_graph.outgoing_edges_from_static() {
1539 handle_trace(sub, Trace::FromStatic(sub));
1540 }
1541 } else {
1542let edges = self.constraint_graph.outgoing_edges_from_graph(r, &self.constraints);
1543// This loop can be hot.
1544for constraint in edges {
1545match constraint.category {
1546 ConstraintCategory::OutlivesUnnameablePlaceholder(_)
1547if !include_placeholder_static =>
1548 {
1549{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/region_infer/mod.rs:1549",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1549u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("Ignoring illegal placeholder constraint: {0:?}",
constraint) as &dyn Value))])
});
} else { ; }
};debug!("Ignoring illegal placeholder constraint: {constraint:?}");
1550continue;
1551 }
1552 ConstraintCategory::OpaqueType if ignore_opaque_type_constraints => {
1553{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/region_infer/mod.rs:1553",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1553u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("Ignoring member constraint: {0:?}",
constraint) as &dyn Value))])
});
} else { ; }
};debug!("Ignoring member constraint: {constraint:?}");
1554continue;
1555 }
1556_ => {}
1557 }
15581559if 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);
1560 handle_trace(constraint.sub, Trace::FromGraph(constraint));
1561 }
1562 }
1563 }
15641565None1566 }
15671568/// Finds some region R such that `fr1: R` and `R` is live at `location`.
1569x;#[instrument(skip(self), level = "trace", ret)]1570pub(crate) fn find_sub_region_live_at(&self, fr1: RegionVid, location: Location) -> RegionVid {
1571trace!(scc = ?self.constraint_sccs.scc(fr1));
1572trace!(universe = ?self.max_nameable_universe(self.constraint_sccs.scc(fr1)));
1573self.constraint_path_to(fr1, |r| {
1574trace!(?r, liveness_constraints=?self.liveness_constraints.pretty_print_live_points(r));
1575self.liveness_constraints.is_live_at(r, location)
1576 }, true).unwrap().1
1577}
15781579/// Get the region outlived by `longer_fr` and live at `element`.
1580fn region_from_element(
1581&self,
1582 longer_fr: RegionVid,
1583 element: &RegionElement<'tcx>,
1584 ) -> RegionVid {
1585match *element {
1586 RegionElement::Location(l) => self.find_sub_region_live_at(longer_fr, l),
1587 RegionElement::RootUniversalRegion(r) => r,
1588 RegionElement::PlaceholderRegion(error_placeholder) => self1589 .definitions
1590 .iter_enumerated()
1591 .find_map(|(r, definition)| match definition.origin {
1592 NllRegionVariableOrigin::Placeholder(p) if p == error_placeholder => Some(r),
1593_ => None,
1594 })
1595 .unwrap(),
1596 }
1597 }
15981599/// Get the region definition of `r`.
1600pub(crate) fn region_definition(&self, r: RegionVid) -> &RegionDefinition<'tcx> {
1601&self.definitions[r]
1602 }
16031604/// Check if the SCC of `r` contains `upper`.
1605pub(crate) fn upper_bound_in_region_scc(&self, r: RegionVid, upper: RegionVid) -> bool {
1606let r_scc = self.constraint_sccs.scc(r);
1607self.scc_values.contains(r_scc, upper)
1608 }
16091610pub(crate) fn universal_regions(&self) -> &UniversalRegions<'tcx> {
1611&self.universal_region_relations.universal_regions
1612 }
16131614/// Tries to find the best constraint to blame for the fact that
1615 /// `R: from_region`, where `R` is some region that meets
1616 /// `target_test`. This works by following the constraint graph,
1617 /// creating a constraint path that forces `R` to outlive
1618 /// `from_region`, and then finding the best choices within that
1619 /// path to blame.
1620#[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("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1620u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&["from_region",
"from_region_origin", "to_region"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&from_region)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&from_region_origin)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&to_region)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
(BlameConstraint<'tcx>, Vec<OutlivesConstraint<'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 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 compiler/rustc_borrowck/src/region_infer/mod.rs:1652",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1652u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("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 Value))])
});
} else { ; }
};
let cause_code =
path.iter().find_map(|constraint|
{
if let ConstraintCategory::Predicate(predicate_span) =
constraint.category {
Some(ObligationCauseCode::WhereClause(CRATE_DEF_ID.to_def_id(),
predicate_span))
} else { None }
}).unwrap_or_else(|| ObligationCauseCode::Misc);
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,
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_borrowck/src/region_infer/mod.rs:1803",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1803u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("constraint {0:?} category: {1:?}, interest: {2:?}",
constraint, category, interest) as &dyn 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 compiler/rustc_borrowck/src/region_infer/mod.rs:1814",
"rustc_borrowck::region_infer", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_borrowck/src/region_infer/mod.rs"),
::tracing_core::__macro_support::Option::Some(1814u32),
::tracing_core::__macro_support::Option::Some("rustc_borrowck::region_infer"),
::tracing_core::field::FieldSet::new(&["best_choice",
"blame_source"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&best_choice)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&blame_source)
as &dyn Value))])
});
} else { ; }
};
let best_constraint =
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 {
*next
} 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 }
}) {
OutlivesConstraint {
category: ConstraintCategory::Return(ReturnConstraint::ClosureUpvar(field)),
..path[best_choice]
}
} else { path[best_choice] };
if !!#[allow(non_exhaustive_omitted_patterns)] match best_constraint.category
{
ConstraintCategory::OutlivesUnnameablePlaceholder(_) =>
true,
_ => false,
} {
{
::core::panicking::panic_fmt(format_args!("Illegal placeholder constraint blamed; should have redirected to other region relation"));
}
};
let blame_constraint =
BlameConstraint {
category: best_constraint.category,
from_closure: best_constraint.from_closure,
cause: ObligationCause::new(best_constraint.span,
CRATE_DEF_ID, cause_code.clone()),
variance_info: best_constraint.variance_info,
};
(blame_constraint, path)
}
}
}#[instrument(level = "debug", skip(self))]1621pub(crate) fn best_blame_constraint(
1622&self,
1623 from_region: RegionVid,
1624 from_region_origin: NllRegionVariableOrigin<'tcx>,
1625 to_region: RegionVid,
1626 ) -> (BlameConstraint<'tcx>, Vec<OutlivesConstraint<'tcx>>) {
1627assert!(from_region != to_region, "Trying to blame a region for itself!");
16281629let path = self.constraint_path_between_regions(from_region, to_region).unwrap();
16301631// If we are passing through a constraint added because we reached an unnameable placeholder `'unnameable`,
1632 // redirect search towards `'unnameable`.
1633let due_to_placeholder_outlives = path.iter().find_map(|c| {
1634if let ConstraintCategory::OutlivesUnnameablePlaceholder(unnameable) = c.category {
1635Some(unnameable)
1636 } else {
1637None
1638}
1639 });
16401641// Edge case: it's possible that `'from_region` is an unnameable placeholder.
1642let path = if let Some(unnameable) = due_to_placeholder_outlives
1643 && unnameable != from_region
1644 {
1645// We ignore the extra edges due to unnameable placeholders to get
1646 // an explanation that was present in the original constraint graph.
1647self.constraint_path_to(from_region, |r| r == unnameable, false).unwrap().0
1648} else {
1649 path
1650 };
16511652debug!(
1653"path={:#?}",
1654 path.iter()
1655 .map(|c| format!(
1656"{:?} ({:?}: {:?})",
1657 c,
1658self.constraint_sccs.scc(c.sup),
1659self.constraint_sccs.scc(c.sub),
1660 ))
1661 .collect::<Vec<_>>()
1662 );
16631664// We try to avoid reporting a `ConstraintCategory::Predicate` as our best constraint.
1665 // Instead, we use it to produce an improved `ObligationCauseCode`.
1666 // FIXME - determine what we should do if we encounter multiple
1667 // `ConstraintCategory::Predicate` constraints. Currently, we just pick the first one.
1668let cause_code = path
1669 .iter()
1670 .find_map(|constraint| {
1671if let ConstraintCategory::Predicate(predicate_span) = constraint.category {
1672// We currently do not store the `DefId` in the `ConstraintCategory`
1673 // for performances reasons. The error reporting code used by NLL only
1674 // uses the span, so this doesn't cause any problems at the moment.
1675Some(ObligationCauseCode::WhereClause(CRATE_DEF_ID.to_def_id(), predicate_span))
1676 } else {
1677None
1678}
1679 })
1680 .unwrap_or_else(|| ObligationCauseCode::Misc);
16811682// When reporting an error, there is typically a chain of constraints leading from some
1683 // "source" region which must outlive some "target" region.
1684 // In most cases, we prefer to "blame" the constraints closer to the target --
1685 // but there is one exception. When constraints arise from higher-ranked subtyping,
1686 // we generally prefer to blame the source value,
1687 // as the "target" in this case tends to be some type annotation that the user gave.
1688 // Therefore, if we find that the region origin is some instantiation
1689 // of a higher-ranked region, we start our search from the "source" point
1690 // rather than the "target", and we also tweak a few other things.
1691 //
1692 // An example might be this bit of Rust code:
1693 //
1694 // ```rust
1695 // let x: fn(&'static ()) = |_| {};
1696 // let y: for<'a> fn(&'a ()) = x;
1697 // ```
1698 //
1699 // In MIR, this will be converted into a combination of assignments and type ascriptions.
1700 // In particular, the 'static is imposed through a type ascription:
1701 //
1702 // ```rust
1703 // x = ...;
1704 // AscribeUserType(x, fn(&'static ())
1705 // y = x;
1706 // ```
1707 //
1708 // We wind up ultimately with constraints like
1709 //
1710 // ```rust
1711 // !a: 'temp1 // from the `y = x` statement
1712 // 'temp1: 'temp2
1713 // 'temp2: 'static // from the AscribeUserType
1714 // ```
1715 //
1716 // and here we prefer to blame the source (the y = x statement).
1717let blame_source = match from_region_origin {
1718 NllRegionVariableOrigin::FreeRegion => true,
1719 NllRegionVariableOrigin::Placeholder(_) => false,
1720// `'existential: 'whatever` never results in a region error by itself.
1721 // We may always infer it to `'static` afterall. This means while an error
1722 // path may go through an existential, these existentials are never the
1723 // `from_region`.
1724NllRegionVariableOrigin::Existential { name: _ } => {
1725unreachable!("existentials can outlive everything")
1726 }
1727 };
17281729// To pick a constraint to blame, we organize constraints by how interesting we expect them
1730 // to be in diagnostics, then pick the most interesting one closest to either the source or
1731 // the target on our constraint path.
1732let constraint_interest = |constraint: &OutlivesConstraint<'tcx>| {
1733// Try to avoid blaming constraints from desugarings, since they may not clearly match
1734 // match what users have written. As an exception, allow blaming returns generated by
1735 // `?` desugaring, since the correspondence is fairly clear.
1736let category = if let Some(kind) = constraint.span.desugaring_kind()
1737 && (kind != DesugaringKind::QuestionMark
1738 || !matches!(constraint.category, ConstraintCategory::Return(_)))
1739 {
1740 ConstraintCategory::Boring
1741 } else {
1742 constraint.category
1743 };
17441745let interest = match category {
1746// Returns usually provide a type to blame and have specially written diagnostics,
1747 // so prioritize them.
1748ConstraintCategory::Return(_) => 0,
1749// Unsizing coercions are interesting, since we have a note for that:
1750 // `BorrowExplanation::add_object_lifetime_default_note`.
1751 // FIXME(dianne): That note shouldn't depend on a coercion being blamed; see issue
1752 // #131008 for an example of where we currently don't emit it but should.
1753 // Once the note is handled properly, this case should be removed. Until then, it
1754 // should be as limited as possible; the note is prone to false positives and this
1755 // constraint usually isn't best to blame.
1756ConstraintCategory::Cast {
1757 is_raw_ptr_dyn_type_cast: _,
1758 unsize_to: Some(unsize_ty),
1759 is_implicit_coercion: true,
1760 } if to_region == self.universal_regions().fr_static
1761// Mirror the note's condition, to minimize how often this diverts blame.
1762&& let ty::Adt(_, args) = unsize_ty.kind()
1763 && args.iter().any(|arg| arg.as_type().is_some_and(|ty| ty.is_trait()))
1764// Mimic old logic for this, to minimize false positives in tests.
1765&& !path
1766 .iter()
1767 .any(|c| matches!(c.category, ConstraintCategory::TypeAnnotation(_))) =>
1768 {
17691
1770}
1771// Between other interesting constraints, order by their position on the `path`.
1772ConstraintCategory::Yield
1773 | ConstraintCategory::UseAsConst
1774 | ConstraintCategory::UseAsStatic
1775 | ConstraintCategory::TypeAnnotation(
1776 AnnotationSource::Ascription
1777 | AnnotationSource::Declaration
1778 | AnnotationSource::OpaqueCast,
1779 )
1780 | ConstraintCategory::Cast { .. }
1781 | ConstraintCategory::CallArgument(_)
1782 | ConstraintCategory::CopyBound
1783 | ConstraintCategory::SizedBound
1784 | ConstraintCategory::Assignment
1785 | ConstraintCategory::Usage
1786 | ConstraintCategory::ClosureUpvar(_) => 2,
1787// Generic arguments are unlikely to be what relates regions together
1788ConstraintCategory::TypeAnnotation(AnnotationSource::GenericArg) => 3,
1789// We handle predicates and opaque types specially; don't prioritize them here.
1790ConstraintCategory::Predicate(_) | ConstraintCategory::OpaqueType => 4,
1791// `Boring` constraints can correspond to user-written code and have useful spans,
1792 // but don't provide any other useful information for diagnostics.
1793ConstraintCategory::Boring => 5,
1794// `BoringNoLocation` constraints can point to user-written code, but are less
1795 // specific, and are not used for relations that would make sense to blame.
1796ConstraintCategory::BoringNoLocation => 6,
1797// Do not blame internal constraints if we can avoid it. Never blame
1798 // the `'region: 'static` constraints introduced by placeholder outlives.
1799ConstraintCategory::Internal => 7,
1800 ConstraintCategory::OutlivesUnnameablePlaceholder(_) => 8,
1801 };
18021803debug!("constraint {constraint:?} category: {category:?}, interest: {interest:?}");
18041805 interest
1806 };
18071808let best_choice = if blame_source {
1809 path.iter().enumerate().rev().min_by_key(|(_, c)| constraint_interest(c)).unwrap().0
1810} else {
1811 path.iter().enumerate().min_by_key(|(_, c)| constraint_interest(c)).unwrap().0
1812};
18131814debug!(?best_choice, ?blame_source);
18151816let best_constraint = if let Some(next) = path.get(best_choice + 1)
1817 && matches!(path[best_choice].category, ConstraintCategory::Return(_))
1818 && next.category == ConstraintCategory::OpaqueType
1819 {
1820// The return expression is being influenced by the return type being
1821 // impl Trait, point at the return type and not the return expr.
1822*next
1823 } else if path[best_choice].category == ConstraintCategory::Return(ReturnConstraint::Normal)
1824 && let Some(field) = path.iter().find_map(|p| {
1825if let ConstraintCategory::ClosureUpvar(f) = p.category { Some(f) } else { None }
1826 })
1827 {
1828 OutlivesConstraint {
1829 category: ConstraintCategory::Return(ReturnConstraint::ClosureUpvar(field)),
1830 ..path[best_choice]
1831 }
1832 } else {
1833 path[best_choice]
1834 };
18351836assert!(
1837 !matches!(
1838 best_constraint.category,
1839 ConstraintCategory::OutlivesUnnameablePlaceholder(_)
1840 ),
1841"Illegal placeholder constraint blamed; should have redirected to other region relation"
1842);
18431844let blame_constraint = BlameConstraint {
1845 category: best_constraint.category,
1846 from_closure: best_constraint.from_closure,
1847 cause: ObligationCause::new(best_constraint.span, CRATE_DEF_ID, cause_code.clone()),
1848 variance_info: best_constraint.variance_info,
1849 };
1850 (blame_constraint, path)
1851 }
18521853pub(crate) fn universe_info(&self, universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
1854// Query canonicalization can create local superuniverses (for example in
1855 // `InferCtx::query_response_instantiation_guess`), but they don't have an associated
1856 // `UniverseInfo` explaining why they were created.
1857 // This can cause ICEs if these causes are accessed in diagnostics, for example in issue
1858 // #114907 where this happens via liveness and dropck outlives results.
1859 // Therefore, we return a default value in case that happens, which should at worst emit a
1860 // suboptimal error, instead of the ICE.
1861self.universe_causes.get(&universe).cloned().unwrap_or_else(UniverseInfo::other)
1862 }
18631864/// Tries to find the terminator of the loop in which the region 'r' resides.
1865 /// Returns the location of the terminator if found.
1866pub(crate) fn find_loop_terminator_location(
1867&self,
1868 r: RegionVid,
1869 body: &Body<'_>,
1870 ) -> Option<Location> {
1871let scc = self.constraint_sccs.scc(r);
1872let locations = self.scc_values.locations_outlived_by(scc);
1873for location in locations {
1874let bb = &body[location.block];
1875if let Some(terminator) = &bb.terminator
1876// terminator of a loop should be TerminatorKind::FalseUnwind
1877&& let TerminatorKind::FalseUnwind { .. } = terminator.kind
1878 {
1879return Some(location);
1880 }
1881 }
1882None1883 }
18841885/// Access to the SCC constraint graph.
1886 /// This can be used to quickly under-approximate the regions which are equal to each other
1887 /// and their relative orderings.
1888// This is `pub` because it's used by unstable external borrowck data users, see `consumers.rs`.
1889pub fn constraint_sccs(&self) -> &ConstraintSccs {
1890&self.constraint_sccs
1891 }
18921893/// Returns the representative `RegionVid` for a given SCC.
1894 /// See `RegionTracker` for how a region variable ID is chosen.
1895 ///
1896 /// It is a hacky way to manage checking regions for equality,
1897 /// since we can 'canonicalize' each region to the representative
1898 /// of its SCC and be sure that -- if they have the same repr --
1899 /// they *must* be equal (though not having the same repr does not
1900 /// mean they are unequal).
1901fn scc_representative(&self, scc: ConstraintSccIndex) -> RegionVid {
1902self.scc_annotations[scc].representative.rvid()
1903 }
19041905pub(crate) fn liveness_constraints(&self) -> &LivenessValues {
1906&self.liveness_constraints
1907 }
19081909/// When using `-Zpolonius=next`, records the given live loans for the loan scopes and active
1910 /// loans dataflow computations.
1911pub(crate) fn record_live_loans(&mut self, live_loans: LiveLoans) {
1912self.liveness_constraints.record_live_loans(live_loans);
1913 }
19141915/// Returns whether the `loan_idx` is live at the given `location`: whether its issuing
1916 /// region is contained within the type of a variable that is live at this point.
1917 /// Note: for now, the sets of live loans is only available when using `-Zpolonius=next`.
1918pub(crate) fn is_loan_live_at(&self, loan_idx: BorrowIndex, location: Location) -> bool {
1919let point = self.liveness_constraints.point_from_location(location);
1920self.liveness_constraints.is_loan_live_at(loan_idx, point)
1921 }
1922}
19231924#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for BlameConstraint<'tcx> {
#[inline]
fn clone(&self) -> BlameConstraint<'tcx> {
BlameConstraint {
category: ::core::clone::Clone::clone(&self.category),
from_closure: ::core::clone::Clone::clone(&self.from_closure),
cause: ::core::clone::Clone::clone(&self.cause),
variance_info: ::core::clone::Clone::clone(&self.variance_info),
}
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for BlameConstraint<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field4_finish(f,
"BlameConstraint", "category", &self.category, "from_closure",
&self.from_closure, "cause", &self.cause, "variance_info",
&&self.variance_info)
}
}Debug)]
1925pub(crate) struct BlameConstraint<'tcx> {
1926pub category: ConstraintCategory<'tcx>,
1927pub from_closure: bool,
1928pub cause: ObligationCause<'tcx>,
1929pub variance_info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
1930}