Skip to content

Commit 3afe1ca

Browse files
authored
Rollup merge of #146717 - amandasystems:remove-placeholder-hack, r=lcnr
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. I'm afraid we may want r? `@lcnr` for this one too. I am sorry, but at least it should be easier to review.
2 parents f28730f + 2ed5373 commit 3afe1ca

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-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: 15 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,22 @@ 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+
//
977+
// Avoid infinite recursion if `sub_region` is already `'static`
978+
if sub_region != fr_static
979+
&& !self.can_name_all_placeholders(sup_region_scc, sub_region_scc)
980+
{
971981
debug!(
972982
"sub universe `{sub_region_scc:?}` is not nameable \
973983
by super `{sup_region_scc:?}`, promoting to static",
974984
);
975985

976-
return self.eval_outlives(sup_region, self.universal_regions().fr_static);
986+
return self.eval_outlives(sup_region, fr_static);
977987
}
978988

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

0 commit comments

Comments
 (0)