Open memoryruins opened 3 years ago
This isn't exclusive to GATs, the following code produces the same bug on stable:
trait Trait<T> {
type Type;
}
impl<T> Trait<T> for u8 {
type Type = T;
}
struct S<T: Trait<Self>>(Option<T::Type>);
fn main() {
S::<u8>(None); // this line and `cargo build` required for a cycle error
}
If you get rid of Self
, I can reproduce at least as far back as 1.22.0 (error with rustc
, no error with rustc --emit=metadata
).
trait Trait<T> {
type Type;
}
impl<T> Trait<T> for u8 {
type Type = T;
}
struct S<T: Trait<S<T>>>(Option<T::Type>);
fn main() {
S::<u8>(None); // this line and `cargo build` required for a cycle error
}
I expected to see this happen:
An error about a cycle, overflowing requirements, or recursive type of infinite size with a diagnostic underlining the definition of
S
and usageS::<u8>(None);
Instead, this happened:
A cycle is detected only when optimizing MIR for
main
, thus this goes uncaught duringcargo check
. The diagnostic only underlines the function name.Meta
rustc --version --verbose
: