rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.95k stars 12.53k forks source link

Compiler freezes on trait with generic associated type #130640

Open antonilol opened 2 hours ago

antonilol commented 2 hours ago

I tried this code:

trait What {
    type This<'a>: 'a
    where
        for<'b> Self::This<'b>: 'a + 'b;
}

impl<T> What for T {
    type This<'a> = T where T: 'a;
}

I expected to see this happen: The compiler returning with a success (probably not) or a compilation error

Instead, this happened: Compiler freezes, cpu usage shows one core of 100% usage (infinite loop?)

Meta

rustc --version --verbose:

rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-unknown-linux-gnu
release: 1.81.0
LLVM version: 18.1.7

I tried some versions between GATs stabilizing and current nightly, and all had the same behavior.

This could be a duplicate of existing similar issues, but I am not sure if that is the case.

fmease commented 2 hours ago

The next-gen solver currently fails with error: cannot normalize `for<'b> <T as What>::This<'b>: 'b` instead of hanging.