Skip to content

Commit d4d23b2

Browse files
Replace escaping bound vars in ty/ct visiting, not binder visiting
1 parent 7768a67 commit d4d23b2

File tree

2 files changed

+44
-12
lines changed
  • compiler/rustc_next_trait_solver/src/solve

2 files changed

+44
-12
lines changed

compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,11 @@ where
10141014
return Ok(CandidateSource::ParamEnv(ParamEnvSource::NonGlobal));
10151015
}
10161016

1017-
match assumption.visit_with(&mut FindParamInClause { ecx: self, param_env }) {
1017+
match assumption.visit_with(&mut FindParamInClause {
1018+
ecx: self,
1019+
param_env,
1020+
universes: vec![],
1021+
}) {
10181022
ControlFlow::Break(Err(NoSolution)) => Err(NoSolution),
10191023
ControlFlow::Break(Ok(())) => Ok(CandidateSource::ParamEnv(ParamEnvSource::NonGlobal)),
10201024
ControlFlow::Continue(()) => Ok(CandidateSource::ParamEnv(ParamEnvSource::Global)),
@@ -1025,6 +1029,7 @@ where
10251029
struct FindParamInClause<'a, 'b, D: SolverDelegate<Interner = I>, I: Interner> {
10261030
ecx: &'a mut EvalCtxt<'b, D>,
10271031
param_env: I::ParamEnv,
1032+
universes: Vec<Option<ty::UniverseIndex>>,
10281033
}
10291034

10301035
impl<D, I> TypeVisitor<I> for FindParamInClause<'_, '_, D, I>
@@ -1035,41 +1040,59 @@ where
10351040
type Result = ControlFlow<Result<(), NoSolution>>;
10361041

10371042
fn visit_binder<T: TypeFoldable<I>>(&mut self, t: &ty::Binder<I, T>) -> Self::Result {
1038-
self.ecx.enter_forall(t.clone(), |ecx, v| {
1039-
v.visit_with(&mut FindParamInClause { ecx, param_env: self.param_env })
1040-
})
1043+
self.universes.push(None);
1044+
t.super_visit_with(self)?;
1045+
self.universes.pop();
1046+
ControlFlow::Continue(())
10411047
}
10421048

10431049
fn visit_ty(&mut self, ty: I::Ty) -> Self::Result {
1050+
let ty = self.ecx.replace_bound_vars(ty, &mut self.universes);
10441051
let Ok(ty) = self.ecx.structurally_normalize_ty(self.param_env, ty) else {
10451052
return ControlFlow::Break(Err(NoSolution));
10461053
};
10471054

1048-
if let ty::Placeholder(_) = ty.kind() {
1049-
ControlFlow::Break(Ok(()))
1055+
if let ty::Placeholder(p) = ty.kind() {
1056+
if p.universe() == ty::UniverseIndex::ROOT {
1057+
ControlFlow::Break(Ok(()))
1058+
} else {
1059+
ControlFlow::Continue(())
1060+
}
10501061
} else {
10511062
ty.super_visit_with(self)
10521063
}
10531064
}
10541065

10551066
fn visit_const(&mut self, ct: I::Const) -> Self::Result {
1067+
let ct = self.ecx.replace_bound_vars(ct, &mut self.universes);
10561068
let Ok(ct) = self.ecx.structurally_normalize_const(self.param_env, ct) else {
10571069
return ControlFlow::Break(Err(NoSolution));
10581070
};
10591071

1060-
if let ty::ConstKind::Placeholder(_) = ct.kind() {
1061-
ControlFlow::Break(Ok(()))
1072+
if let ty::ConstKind::Placeholder(p) = ct.kind() {
1073+
if p.universe() == ty::UniverseIndex::ROOT {
1074+
ControlFlow::Break(Ok(()))
1075+
} else {
1076+
ControlFlow::Continue(())
1077+
}
10621078
} else {
10631079
ct.super_visit_with(self)
10641080
}
10651081
}
10661082

10671083
fn visit_region(&mut self, r: I::Region) -> Self::Result {
10681084
match self.ecx.eager_resolve_region(r).kind() {
1069-
ty::ReStatic | ty::ReError(_) => ControlFlow::Continue(()),
1070-
ty::ReVar(_) | ty::RePlaceholder(_) => ControlFlow::Break(Ok(())),
1071-
ty::ReErased | ty::ReEarlyParam(_) | ty::ReLateParam(_) | ty::ReBound(..) => {
1072-
unreachable!()
1085+
ty::ReStatic | ty::ReError(_) | ty::ReBound(..) => ControlFlow::Continue(()),
1086+
ty::RePlaceholder(p) => {
1087+
if p.universe() == ty::UniverseIndex::ROOT {
1088+
ControlFlow::Break(Ok(()))
1089+
} else {
1090+
ControlFlow::Continue(())
1091+
}
1092+
}
1093+
ty::ReVar(_) => ControlFlow::Break(Ok(())),
1094+
ty::ReErased | ty::ReEarlyParam(_) | ty::ReLateParam(_) => {
1095+
unreachable!("unexpected region in param-env clause")
10731096
}
10741097
}
10751098
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use tracing::{debug, instrument, trace};
1919
use super::has_only_region_constraints;
2020
use crate::coherence;
2121
use crate::delegate::SolverDelegate;
22+
use crate::placeholder::BoundVarReplacer;
2223
use crate::solve::inspect::{self, ProofTreeBuilder};
2324
use crate::solve::search_graph::SearchGraph;
2425
use crate::solve::{
@@ -1232,6 +1233,14 @@ where
12321233
) -> Result<Certainty, NoSolution> {
12331234
self.delegate.is_transmutable(dst, src, assume)
12341235
}
1236+
1237+
pub(super) fn replace_bound_vars<T: TypeFoldable<I>>(
1238+
&self,
1239+
t: T,
1240+
universes: &mut Vec<Option<ty::UniverseIndex>>,
1241+
) -> T {
1242+
BoundVarReplacer::replace_bound_vars(&**self.delegate, universes, t).0
1243+
}
12351244
}
12361245

12371246
/// Eagerly replace aliases with inference variables, emitting `AliasRelate`

0 commit comments

Comments
 (0)