Skip to content

Commit 63f31e2

Browse files
Canonicalize effect vars in new solver
1 parent 5adddad commit 63f31e2

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

Diff for: compiler/rustc_infer/src/infer/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,10 @@ impl<'tcx> InferCtxt<'tcx> {
13351335
self.inner.borrow_mut().const_unification_table().find(var)
13361336
}
13371337

1338+
pub fn root_effect_var(&self, var: ty::EffectVid<'tcx>) -> ty::EffectVid<'tcx> {
1339+
self.inner.borrow_mut().effect_unification_table().find(var)
1340+
}
1341+
13381342
/// Resolves an int var to a rigid int type, if it was constrained to one,
13391343
/// or else the root int var in the unification table.
13401344
pub fn opportunistic_resolve_int_var(&self, vid: ty::IntVid) -> Ty<'tcx> {

Diff for: compiler/rustc_trait_selection/src/solve/canonicalize.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,16 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'_, 'tcx> {
365365
// FIXME: we should fold this ty eventually
366366
CanonicalVarKind::Const(ui, c.ty())
367367
}
368-
ty::ConstKind::Infer(ty::InferConst::EffectVar(_)) => {
369-
bug!("effect var has no universe")
368+
ty::ConstKind::Infer(ty::InferConst::EffectVar(vid)) => {
369+
assert_eq!(
370+
self.infcx.root_effect_var(vid),
371+
vid,
372+
"effect var should have been resolved"
373+
);
374+
let None = self.infcx.probe_effect_var(vid) else {
375+
bug!("effect var should have been resolved");
376+
};
377+
CanonicalVarKind::Effect
370378
}
371379
ty::ConstKind::Infer(ty::InferConst::Fresh(_)) => {
372380
bug!("fresh var during canonicalization: {c:?}")

Diff for: compiler/rustc_trait_selection/src/solve/eval_ctxt/canonical.rs

+11
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,17 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for EagerResolver<'_, 'tcx> {
382382
}
383383
}
384384
}
385+
ty::ConstKind::Infer(ty::InferConst::EffectVar(vid)) => {
386+
// FIXME: we need to fold the ty too, I think.
387+
match self.infcx.probe_effect_var(vid) {
388+
Some(c) => c.as_const(self.infcx.tcx),
389+
None => ty::Const::new_infer(
390+
self.infcx.tcx,
391+
ty::InferConst::EffectVar(self.infcx.root_effect_var(vid)),
392+
c.ty(),
393+
),
394+
}
395+
}
385396
_ => {
386397
if c.has_infer() {
387398
c.super_fold_with(self)
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// compile-flags: -Ztrait-solver=next
2+
// check-pass
3+
4+
#![feature(effects)]
5+
#![feature(const_trait_impl)]
6+
7+
#[const_trait]
8+
trait Foo {
9+
fn foo();
10+
}
11+
12+
trait Bar {}
13+
14+
impl const Foo for i32 {
15+
fn foo() {}
16+
}
17+
18+
impl<T> const Foo for T where T: Bar {
19+
fn foo() {}
20+
}
21+
22+
fn main() {}

0 commit comments

Comments
 (0)