add normalization test with field with diverging alias

Another example from https://github.com/rust-lang/trait-system-refactor-initiative/issues/139
and which was likely fixed by https://github.com/rust-lang/rust/pull/140672 as well.
This commit is contained in:
Rémy Rakic
2026-05-06 19:04:58 +02:00
parent e2ea0ba07a
commit 4922210ea6
3 changed files with 54 additions and 0 deletions
@@ -0,0 +1,9 @@
error[E0275]: overflow evaluating the requirement `<u8 as Trait>::Diverges<u8> == _`
--> $DIR/normalize-diverging-alias-in-struct.rs:21:12
|
LL | field: Box<<u8 as Trait>::Diverges<u8>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0275`.
@@ -0,0 +1,18 @@
error[E0271]: type mismatch resolving `<u8 as Trait>::Diverges<u8> normalizes-to _`
--> $DIR/normalize-diverging-alias-in-struct.rs:21:12
|
LL | field: Box<<u8 as Trait>::Diverges<u8>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ
error[E0271]: type mismatch resolving `<u8 as Trait>::Diverges<u8> normalizes-to _`
--> $DIR/normalize-diverging-alias-in-struct.rs:21:12
|
LL | field: Box<<u8 as Trait>::Diverges<u8>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ
|
note: required by a bound in `Box`
--> $SRC_DIR/alloc/src/boxed.rs:LL:COL
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0271`.
@@ -0,0 +1,27 @@
// Ensure that structs with fields whose types contain diverging aliases are properly caught with
// both solvers.
// MCVE from https://github.com/rust-lang/trait-system-refactor-initiative/issues/139#issuecomment-2703127026.
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@ [next] compile-flags: -Znext-solver
#![feature(rustc_attrs)]
#![rustc_no_implicit_bounds]
trait Trait {
type Diverges<D: Trait>;
}
impl<T> Trait for T {
type Diverges<D: Trait> = D::Diverges<D>;
}
struct Foo {
field: Box<<u8 as Trait>::Diverges<u8>>,
//[current]~^ ERROR: overflow evaluating the requirement `<u8 as Trait>::Diverges<u8> == _`
//[next]~^^ ERROR: type mismatch resolving `<u8 as Trait>::Diverges<u8> normalizes-to _`
//[next]~| ERROR: type mismatch resolving `<u8 as Trait>::Diverges<u8> normalizes-to _`
}
fn main() {}