diff --git a/compiler/rustc_infer/src/infer/context.rs b/compiler/rustc_infer/src/infer/context.rs index d1d864246b9ff..9d5b51491e5e6 100644 --- a/compiler/rustc_infer/src/infer/context.rs +++ b/compiler/rustc_infer/src/infer/context.rs @@ -521,7 +521,10 @@ impl<'a, 'tcx> ty::TypeFolder> for LowerUniverseFolder<'a, 'tcx> { match c.kind() { ty::ConstKind::Infer(ty::InferConst::Var(vid)) => { let vid = self.infcx.root_const_var(vid); - let universe = self.infcx.try_resolve_const_var(vid).unwrap_err(); + let universe = match self.infcx.try_resolve_const_var(vid) { + Ok(value) => return value.fold_with(self), + Err(universe) => universe, + }; if self.for_universe.can_name(universe) { c } else { diff --git a/compiler/rustc_next_trait_solver/src/canonical/mod.rs b/compiler/rustc_next_trait_solver/src/canonical/mod.rs index f325862102318..2adb6a19cb6c3 100644 --- a/compiler/rustc_next_trait_solver/src/canonical/mod.rs +++ b/compiler/rustc_next_trait_solver/src/canonical/mod.rs @@ -392,12 +392,10 @@ where } let infcx = self.infcx; - // FIXME: make this a debug_assert. - // Currently proof tree evaluation can unify infer vars in original - // vars while not resolving them. - // See `tests/ui/traits/next-solver/transmute-from-async-closure.rs` + // Proof tree evaluation can unify inference variables in the original + // values without eagerly resolving them. let a = infcx.shallow_resolve_const(a); - debug_assert_eq!(b, infcx.shallow_resolve_const(b)); + let b = infcx.shallow_resolve_const(b); match (a.kind(), b.kind()) { ( ty::ConstKind::Infer(ty::InferConst::Var(a_vid)), diff --git a/tests/ui/traits/next-solver/lower-universe-resolved-const-issue-159703.rs b/tests/ui/traits/next-solver/lower-universe-resolved-const-issue-159703.rs new file mode 100644 index 0000000000000..6a28115ad32f0 --- /dev/null +++ b/tests/ui/traits/next-solver/lower-universe-resolved-const-issue-159703.rs @@ -0,0 +1,16 @@ +//@ compile-flags: -Znext-solver=globally + +trait Foo {} + +struct BarType; + +impl Foo for BarType {} +//~^ ERROR missing generics for struct `BarType` + +fn a(x: &dyn Foo) { + let bar = BarType; + a(bar); + //~^ ERROR mismatched types +} + +fn main() {} diff --git a/tests/ui/traits/next-solver/lower-universe-resolved-const-issue-159703.stderr b/tests/ui/traits/next-solver/lower-universe-resolved-const-issue-159703.stderr new file mode 100644 index 0000000000000..d3658748846c6 --- /dev/null +++ b/tests/ui/traits/next-solver/lower-universe-resolved-const-issue-159703.stderr @@ -0,0 +1,40 @@ +error[E0107]: missing generics for struct `BarType` + --> $DIR/lower-universe-resolved-const-issue-159703.rs:7:30 + | +LL | impl Foo for BarType {} + | ^^^^^^^ expected 1 generic argument + | +note: struct defined here, with 1 generic parameter: `N` + --> $DIR/lower-universe-resolved-const-issue-159703.rs:5:8 + | +LL | struct BarType; + | ^^^^^^^ -------------- +help: add missing generic argument + | +LL | impl Foo for BarType {} + | +++ + +error[E0308]: mismatched types + --> $DIR/lower-universe-resolved-const-issue-159703.rs:12:7 + | +LL | a(bar); + | - ^^^ expected `&dyn Foo`, found `BarType<_>` + | | + | arguments to this function are incorrect + | + = note: expected reference `&dyn Foo` + found struct `BarType<_>` +note: function defined here + --> $DIR/lower-universe-resolved-const-issue-159703.rs:10:4 + | +LL | fn a(x: &dyn Foo) { + | ^ ----------- +help: consider borrowing here + | +LL | a(&bar); + | + + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0107, E0308. +For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/traits/next-solver/lower-universe-resolved-const-issue-159894.rs b/tests/ui/traits/next-solver/lower-universe-resolved-const-issue-159894.rs new file mode 100644 index 0000000000000..1885e177a6b60 --- /dev/null +++ b/tests/ui/traits/next-solver/lower-universe-resolved-const-issue-159894.rs @@ -0,0 +1,19 @@ +//@ check-pass +//@ compile-flags: -Znext-solver=globally + +pub struct IndexMap { + #[expect(dead_code)] + build_hasher: S, +} + +struct Guard<'a, S, const N: usize>( + #[expect(dead_code)] &'a mut IndexMap, +); + +impl IndexMap { + pub fn clear(&mut self) { + let _ = Guard(self); + } +} + +fn main() {}