Skip to content

Commit 9544ee1

Browse files
committed
reviews + rebase
1 parent baa0ebc commit 9544ee1

File tree

9 files changed

+58
-64
lines changed

9 files changed

+58
-64
lines changed

compiler/rustc_infer/src/infer/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,6 @@ impl<'tcx> InferCtxt<'tcx> {
10311031
_ => {}
10321032
}
10331033

1034-
// FIXME(tree_universes): leaking placeholders
10351034
self.enter_forall(predicate, |ty::SubtypePredicate { a_is_expected, a, b }| {
10361035
Ok(self.at(cause, param_env).sub_exp(DefineOpaqueTypes::No, a_is_expected, a, b))
10371036
})
@@ -1042,7 +1041,6 @@ impl<'tcx> InferCtxt<'tcx> {
10421041
cause: &traits::ObligationCause<'tcx>,
10431042
predicate: ty::PolyRegionOutlivesPredicate<'tcx>,
10441043
) {
1045-
// FIXME(tree_universes): leaking placeholders
10461044
self.enter_forall(predicate, |ty::OutlivesPredicate(r_a, r_b)| {
10471045
let origin = SubregionOrigin::from_obligation_cause(cause, || {
10481046
RelateRegionParamBound(cause.span)

compiler/rustc_infer/src/infer/relate/higher_ranked.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
4949
debug!("b_prime={:?}", sup_prime);
5050

5151
// Compare types now that bound regions have been replaced.
52-
// FIXME(tree_universes): leaked universes
5352
let result = self.sub(sub_is_expected).relate(sub_prime, sup_prime);
5453
if result.is_ok() {
5554
debug!("OK result={result:?}");
@@ -70,7 +69,7 @@ impl<'tcx> InferCtxt<'tcx> {
7069
/// This is the first step of checking subtyping when higher-ranked things are involved.
7170
/// For more details visit the relevant sections of the [rustc dev guide].
7271
///
73-
/// `enter_forall` should be preferred over this method.
72+
/// fn `enter_forall` should be preferred over this method.
7473
///
7574
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html
7675
#[instrument(level = "debug", skip(self), ret)]
@@ -111,21 +110,25 @@ impl<'tcx> InferCtxt<'tcx> {
111110
}
112111

113112
/// Replaces all bound variables (lifetimes, types, and constants) bound by
114-
/// `binder` with placeholder variables in a new universe. This means that the
115-
/// new placeholders can only be named by inference variables created after
116-
/// this method has been called.
113+
/// `binder` with placeholder variables in a new universe and then calls the
114+
/// closure `f` with the instantiated value. The new placeholders can only be
115+
/// named by inference variables inside of the closure `f` or afterwards.
117116
///
118117
/// This is the first step of checking subtyping when higher-ranked things are involved.
119118
/// For more details visit the relevant sections of the [rustc dev guide].
120119
///
121-
/// This method should be preferred over `enter_forall_and_leak_universe`.
120+
/// This method should be preferred over `fn enter_forall_and_leak_universe`.
122121
///
123122
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html
124123
#[instrument(level = "debug", skip(self, f))]
125124
pub fn enter_forall<T, U>(&self, forall: ty::Binder<'tcx, T>, f: impl FnOnce(T) -> U) -> U
126125
where
127126
T: TypeFoldable<TyCtxt<'tcx>> + Copy,
128127
{
128+
// FIXME: currently we do nothing to prevent placeholders with the new universe being
129+
// used after exiting `f`. For example region subtyping can result in outlive constraints
130+
// that name placeholders created in this function. Nested goals from type relations can
131+
// also contain placeholders created by this function.
129132
let value = self.enter_forall_and_leak_universe(forall);
130133
debug!("?value");
131134
f(value)

compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,6 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
480480
self.infcx.enter_forall(kind, |kind| {
481481
let goal = goal.with(self.tcx(), ty::Binder::dummy(kind));
482482
self.add_goal(GoalSource::Misc, goal);
483-
// FIXME(tree_universes): leaking universes
484483
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
485484
})
486485
}

compiler/rustc_trait_selection/src/solve/eval_ctxt/select.rs

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ impl<'tcx> InferCtxtSelectExt<'tcx> for InferCtxt<'tcx> {
3131
) -> SelectionResult<'tcx, Selection<'tcx>> {
3232
assert!(self.next_trait_solver());
3333

34-
// FIXME(tree_universes): leaking universes?
3534
self.enter_forall(obligation.predicate, |pred| {
3635
let trait_goal = Goal::new(self.tcx, obligation.param_env, pred);
3736

compiler/rustc_trait_selection/src/solve/trait_goals.rs

-1
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,6 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
999999
constituent_tys(ecx, goal.predicate.self_ty())?
10001000
.into_iter()
10011001
.map(|ty| {
1002-
// FIXME(tree_universes): leaking universes
10031002
ecx.enter_forall(ty, |ty| {
10041003
goal.with(ecx.tcx(), goal.predicate.with_self_ty(ecx.tcx(), ty))
10051004
})

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4621,7 +4621,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
46214621
let ocx = ObligationCtxt::new(self);
46224622
self.enter_forall(pred, |pred| {
46234623
let pred = ocx.normalize(&ObligationCause::dummy(), param_env, pred);
4624-
// FIXME(tree_universes): universe leakage
46254624
ocx.register_obligation(Obligation::new(
46264625
self.tcx,
46274626
ObligationCause::dummy(),

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2042,7 +2042,6 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
20422042
for (obligation_arg, impl_arg) in
20432043
std::iter::zip(obligation_trait_ref.args, impl_trait_ref.args)
20442044
{
2045-
// FIXME(tree_universes): universe leakage
20462045
if let Err(terr) =
20472046
ocx.eq(&ObligationCause::dummy(), param_env, impl_arg, obligation_arg)
20482047
{

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+48-49
Original file line numberDiff line numberDiff line change
@@ -665,64 +665,63 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
665665

666666
self.infcx.probe(|_snapshot| {
667667
let poly_trait_predicate = self.infcx.resolve_vars_if_possible(obligation.predicate);
668-
let placeholder_trait_predicate =
669-
self.infcx.enter_forall_and_leak_universe(poly_trait_predicate);
670-
671-
let self_ty = placeholder_trait_predicate.self_ty();
672-
let principal_trait_ref = match self_ty.kind() {
673-
ty::Dynamic(data, ..) => {
674-
if data.auto_traits().any(|did| did == obligation.predicate.def_id()) {
675-
debug!(
676-
"assemble_candidates_from_object_ty: matched builtin bound, \
668+
self.infcx.enter_forall(poly_trait_predicate, |placeholder_trait_predicate| {
669+
let self_ty = placeholder_trait_predicate.self_ty();
670+
let principal_trait_ref = match self_ty.kind() {
671+
ty::Dynamic(data, ..) => {
672+
if data.auto_traits().any(|did| did == obligation.predicate.def_id()) {
673+
debug!(
674+
"assemble_candidates_from_object_ty: matched builtin bound, \
677675
pushing candidate"
678-
);
679-
candidates.vec.push(BuiltinObjectCandidate);
680-
return;
681-
}
676+
);
677+
candidates.vec.push(BuiltinObjectCandidate);
678+
return;
679+
}
682680

683-
if let Some(principal) = data.principal() {
684-
if !self.infcx.tcx.features().object_safe_for_dispatch {
685-
principal.with_self_ty(self.tcx(), self_ty)
686-
} else if self.tcx().check_is_object_safe(principal.def_id()) {
687-
principal.with_self_ty(self.tcx(), self_ty)
681+
if let Some(principal) = data.principal() {
682+
if !self.infcx.tcx.features().object_safe_for_dispatch {
683+
principal.with_self_ty(self.tcx(), self_ty)
684+
} else if self.tcx().check_is_object_safe(principal.def_id()) {
685+
principal.with_self_ty(self.tcx(), self_ty)
686+
} else {
687+
return;
688+
}
688689
} else {
690+
// Only auto trait bounds exist.
689691
return;
690692
}
691-
} else {
692-
// Only auto trait bounds exist.
693+
}
694+
ty::Infer(ty::TyVar(_)) => {
695+
debug!("assemble_candidates_from_object_ty: ambiguous");
696+
candidates.ambiguous = true; // could wind up being an object type
693697
return;
694698
}
695-
}
696-
ty::Infer(ty::TyVar(_)) => {
697-
debug!("assemble_candidates_from_object_ty: ambiguous");
698-
candidates.ambiguous = true; // could wind up being an object type
699-
return;
700-
}
701-
_ => return,
702-
};
703-
704-
debug!(?principal_trait_ref, "assemble_candidates_from_object_ty");
705-
706-
// Count only those upcast versions that match the trait-ref
707-
// we are looking for. Specifically, do not only check for the
708-
// correct trait, but also the correct type parameters.
709-
// For example, we may be trying to upcast `Foo` to `Bar<i32>`,
710-
// but `Foo` is declared as `trait Foo: Bar<u32>`.
711-
let candidate_supertraits = util::supertraits(self.tcx(), principal_trait_ref)
712-
.enumerate()
713-
.filter(|&(_, upcast_trait_ref)| {
714-
self.infcx.probe(|_| {
715-
self.match_normalize_trait_ref(
716-
obligation,
717-
upcast_trait_ref,
718-
placeholder_trait_predicate.trait_ref,
719-
)
720-
.is_ok()
699+
_ => return,
700+
};
701+
702+
debug!(?principal_trait_ref, "assemble_candidates_from_object_ty");
703+
704+
// Count only those upcast versions that match the trait-ref
705+
// we are looking for. Specifically, do not only check for the
706+
// correct trait, but also the correct type parameters.
707+
// For example, we may be trying to upcast `Foo` to `Bar<i32>`,
708+
// but `Foo` is declared as `trait Foo: Bar<u32>`.
709+
let candidate_supertraits = util::supertraits(self.tcx(), principal_trait_ref)
710+
.enumerate()
711+
.filter(|&(_, upcast_trait_ref)| {
712+
self.infcx.probe(|_| {
713+
self.match_normalize_trait_ref(
714+
obligation,
715+
upcast_trait_ref,
716+
placeholder_trait_predicate.trait_ref,
717+
)
718+
.is_ok()
719+
})
721720
})
722-
})
723-
.map(|(idx, _)| ObjectCandidate(idx));
721+
.map(|(idx, _)| ObjectCandidate(idx));
724722

725-
candidates.vec.extend(candidate_supertraits);
723+
candidates.vec.extend(candidate_supertraits);
724+
})
726725
})
727726
}
728727

compiler/rustc_type_ir/src/region_kind.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ pub enum RegionKind<I: Interner> {
163163
/// A placeholder region -- the higher-ranked version of `ReLateParam`.
164164
/// Should not exist outside of type inference.
165165
///
166-
/// Used when instantiating a `forall` binder via
167-
/// `infcx.enter_forall` and `infcx.enter_forall_and_leak_universe`.
166+
/// Used when instantiating a `forall` binder via `infcx.enter_forall`.
168167
RePlaceholder(I::PlaceholderRegion),
169168

170169
/// Erased region, used by trait selection, in MIR and during codegen.

0 commit comments

Comments
 (0)