Compiler goes out of memory


#1

This little snippet enables an infinite recursion and after several minutes the compiler crashes with an out of memory error:

enum A {
B(A, A)
}

I believe this should be captured before? Sorry if that is already known, I stumbled about it today and was suprised for a moment. :slight_smile:


#2

after trying in playpen I found this error

error: recursive type `A` has infinite size [--explain E0072]
 --> <anon>:1:1
1 |> enum A {
  |> ^
help: insert indirection (e.g., a `Box`, `Rc`, or `&`) at some point to make `A` representable

#3

Iā€™m on Windows with Rust 1.8. I get this (with cargo run):

D:\Rust-Stuff\poly>cargo run
Compiling poly v0.1.0 (file:///D:/Rust-Stuff/poly)
fatal runtime error: out of memory
Could not compile poly.

To learn more, run the command again with --verbose.

But it took over a minute.


#4

Looks like this is indeed a bug in the stable compiler, which is fixed in nightly: https://github.com/rust-lang/rust/issues/33180.

Looks like the original issue is https://github.com/rust-lang/rust/issues/32326