Skip to content

Commit b76881b

Browse files
committed
Clean up universe evaluation during type test evaluation
The logic was, as the removed comments suggest, hackish and meant to implement previous logic that was factored out. The new logic does exactly what the comments say, and is much less surprising.
1 parent 5e33838 commit b76881b

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

compiler/rustc_borrowck/src/handle_placeholders.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,9 @@ impl RegionTracker {
166166
}
167167
}
168168

169-
/// Determine if the tracked universes of the two SCCs are compatible.
170-
pub(crate) fn universe_compatible_with(&self, other: Self) -> bool {
171-
// HACK: We first check whether we can name the highest existential universe
172-
// of `other`. This only exists to avoid errors in case that scc already
173-
// depends on a placeholder it cannot name itself.
174-
self.max_nameable_universe().can_name(other.max_nameable_universe())
175-
|| other.reachable_placeholders.can_be_named_by(self.max_nameable_universe())
169+
/// Determine if we can name all the placeholders in `other`.
170+
pub(crate) fn can_name_all_placeholders(&self, other: Self) -> bool {
171+
other.reachable_placeholders.can_be_named_by(self.max_nameable_universe.0)
176172
}
177173

178174
/// If this SCC reaches a placeholder it can't name, return it.

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -571,11 +571,15 @@ impl<'tcx> RegionInferenceContext<'tcx> {
571571
}
572572
}
573573

574-
/// Returns `true` if all the elements in the value of `scc_b` are nameable
574+
/// Returns `true` if all the placeholders in the value of `scc_b` are nameable
575575
/// in `scc_a`. Used during constraint propagation, and only once
576576
/// the value of `scc_b` has been computed.
577-
fn universe_compatible(&self, scc_b: ConstraintSccIndex, scc_a: ConstraintSccIndex) -> bool {
578-
self.scc_annotations[scc_a].universe_compatible_with(self.scc_annotations[scc_b])
577+
fn can_name_all_placeholders(
578+
&self,
579+
scc_a: ConstraintSccIndex,
580+
scc_b: ConstraintSccIndex,
581+
) -> bool {
582+
self.scc_annotations[scc_a].can_name_all_placeholders(self.scc_annotations[scc_b])
579583
}
580584

581585
/// Once regions have been propagated, this method is used to see
@@ -964,16 +968,21 @@ impl<'tcx> RegionInferenceContext<'tcx> {
964968
return true;
965969
}
966970

971+
let fr_static = self.universal_regions().fr_static;
972+
967973
// If we are checking that `'sup: 'sub`, and `'sub` contains
968974
// some placeholder that `'sup` cannot name, then this is only
969975
// true if `'sup` outlives static.
970-
if !self.universe_compatible(sub_region_scc, sup_region_scc) {
976+
if !self.can_name_all_placeholders(sup_region_scc, sub_region_scc)
977+
&& sub_region != fr_static
978+
// To avoid potentially infinite recursion.
979+
{
971980
debug!(
972981
"sub universe `{sub_region_scc:?}` is not nameable \
973982
by super `{sup_region_scc:?}`, promoting to static",
974983
);
975984

976-
return self.eval_outlives(sup_region, self.universal_regions().fr_static);
985+
return self.eval_outlives(sup_region, fr_static);
977986
}
978987

979988
// Both the `sub_region` and `sup_region` consist of the union

0 commit comments

Comments
 (0)