Auto merge of #115850 - compiler-errors:effect-canon, r=fee1-dead · rust-lang/rust@915c8af (original) (raw)
File tree
4 files changed
lines changed
- rustc_trait_selection/src/solve
- tests/ui/traits/new-solver
4 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1335,6 +1335,10 @@ impl<'tcx> InferCtxt<'tcx> { | ||
1335 | 1335 | self.inner.borrow_mut().const_unification_table().find(var) |
1336 | 1336 | } |
1337 | 1337 | |
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 | + | |
1338 | 1342 | /// Resolves an int var to a rigid int type, if it was constrained to one, |
1339 | 1343 | /// or else the root int var in the unification table. |
1340 | 1344 | pub fn opportunistic_resolve_int_var(&self, vid: ty::IntVid) -> Ty<'tcx> { |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -365,8 +365,16 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'_, 'tcx> { | ||
365 | 365 | // FIXME: we should fold this ty eventually |
366 | 366 | CanonicalVarKind::Const(ui, c.ty()) |
367 | 367 | } |
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 | |
370 | 378 | } |
371 | 379 | ty::ConstKind::Infer(ty::InferConst::Fresh(_)) => { |
372 | 380 | bug!("fresh var during canonicalization: {c:?}") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -382,6 +382,17 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for EagerResolver<'_, 'tcx> { | ||
382 | 382 | } |
383 | 383 | } |
384 | 384 | } |
385 | + ty::ConstKind::Infer(ty::InferConst::EffectVar(vid)) => { | |
386 | +debug_assert_eq!(c.ty(), self.infcx.tcx.types.bool); | |
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 | +self.infcx.tcx.types.bool, | |
393 | +), | |
394 | +} | |
395 | +} | |
385 | 396 | _ => { |
386 | 397 | if c.has_infer() { |
387 | 398 | c.super_fold_with(self) |
Original file line number | Diff line number | Diff 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() {} |