Skip to content

Commit e5f32ef

Browse files
authored
add comment
1 parent ffe336d commit e5f32ef

File tree

1 file changed

+24
-0
lines changed
  • src/librustc_mir/borrow_check/nll/region_infer

1 file changed

+24
-0
lines changed

src/librustc_mir/borrow_check/nll/region_infer/mod.rs

+24
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,30 @@ impl<'tcx> RegionInferenceContext<'tcx> {
645645
}
646646
}
647647

648+
/// Invoked when we have some type-test (e.g., `T: 'X`) that we cannot
649+
/// prove to be satisfied. If this is a closure, we will attempt to
650+
/// "promote" this type-test into our `ClosureRegionRequirements` and
651+
/// hence pass it up the creator. To do this, we have to phrase the
652+
/// type-test in terms of external free regions, as local free
653+
/// regions are not nameable by the closure's creator.
654+
///
655+
/// Promotion works as follows: we first check that the type `T`
656+
/// contains only regions that the creator knows about. If this is
657+
/// true, then -- as a consequence -- we know that all regions in
658+
/// the type `T` are free regions that outlive the closure body. If
659+
/// false, then promotion fails.
660+
///
661+
/// Once we've promoted T, we have to "promote" `'X` to some region
662+
/// that is "external" to the closure. Generally speaking, a region
663+
/// may be the union of some points in the closure body as well as
664+
/// various free lifetimes. We can ignore the points in the closure
665+
/// body: if the type T can be expressed in terms of external regions,
666+
/// we know it outlives the points in the closure body. That
667+
/// just leaves the free regions.
668+
///
669+
/// The idea then is to lower the `T: 'X` constraint into multiple
670+
/// bounds -- e.g., if `'X` is the union of two free lifetimes,
671+
/// `'1` and `'2`, then we would create `T: '1` and `T: '2`.
648672
fn try_promote_type_test<'gcx>(
649673
&self,
650674
infcx: &InferCtxt<'_, 'gcx, 'tcx>,

0 commit comments

Comments
 (0)