Skip to content

Commit 402f3e0

Browse files
address review: improve documentation of impl
1 parent d1674cb commit 402f3e0

File tree

1 file changed

+16
-10
lines changed
  • compiler/rustc_borrowck/src/region_infer

1 file changed

+16
-10
lines changed

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,34 +1293,40 @@ impl<'tcx> RegionInferenceContext<'tcx> {
12931293
.best_blame_constraint(longer_fr, NllRegionVariableOrigin::FreeRegion, shorter_fr)
12941294
.0;
12951295

1296-
// Grow `shorter_fr` until we find some non-local regions. (We
1297-
// always will.) We'll call them `shorter_fr+` -- they're ever
1298-
// so slightly larger than `shorter_fr`.
1296+
// Grow `shorter_fr` until we find some non-local regions.
1297+
// We will always find at least one: `'static`. We'll call
1298+
// them `shorter_fr+` -- they're ever so slightly larger
1299+
// than `shorter_fr`.
12991300
let shorter_fr_plus =
13001301
self.universal_region_relations.non_local_upper_bounds(shorter_fr);
13011302
debug!("try_propagate_universal_region_error: shorter_fr_plus={:?}", shorter_fr_plus);
13021303

1303-
// We then create constraints `longer_fr-: shorter_fr+` that may or may not be propagated (see below).
1304+
// We then create constraints `longer_fr-: shorter_fr+` that may or may not
1305+
// be propagated (see below).
13041306
let mut constraints = vec![];
13051307
for fr_minus in longer_fr_minus {
13061308
for shorter_fr_plus in &shorter_fr_plus {
13071309
constraints.push((fr_minus, *shorter_fr_plus));
13081310
}
13091311
}
13101312

1311-
// If any of the `shorter_fr+` regions are already outlived by `longer_fr-`, we propagate only those.
1312-
// Otherwise, we might incorrectly reject valid code.
1313+
// We only need to propagate at least one of the constraints for
1314+
// soundness. However, we want to avoid arbitrary choices here
1315+
// and currently don't support returning OR constraints.
1316+
//
1317+
// If any of the `shorter_fr+` regions are already outlived by `longer_fr-`,
1318+
// we propagate only those.
13131319
//
13141320
// Consider this example (`'b: 'a` == `a -> b`), where we try to propagate `'d: 'a`:
13151321
// a --> b --> d
13161322
// \
13171323
// \-> c
13181324
// Here, `shorter_fr+` of `'a` == `['b, 'c]`.
1319-
// Propagating `'d: 'b` is correct and should occur; `'d: 'c` is redundant because of `'d: 'b`
1320-
// and could reject valid code.
1325+
// Propagating `'d: 'b` is correct and should occur; `'d: 'c` is redundant because of
1326+
// `'d: 'b` and could reject valid code.
13211327
//
1322-
// So we filter the constraints to regions already outlived by `longer_fr-`, but if the filter yields an empty set,
1323-
// we fall back to the original one.
1328+
// So we filter the constraints to regions already outlived by `longer_fr-`, but if
1329+
// the filter yields an empty set, we fall back to the original one.
13241330
let subset: Vec<_> = constraints
13251331
.iter()
13261332
.filter(|&&(fr_minus, shorter_fr_plus)| {

0 commit comments

Comments
 (0)