Closed
Description
Obviously this shouldn't actually work, due to the state type being infinitely sized (at least not without become
/TCO for generators), but it should generate an error similar to recursive types.
Program:
#![feature(generators, conservative_impl_trait, generator_trait)]
use std::ops::{Generator, GeneratorState};
fn foo() -> impl Generator<Yield = (), Return = ()> {
|| {
let mut gen = foo();
let mut r = gen.resume();
while let GeneratorState::Yielded(v) = r {
yield v;
r = gen.resume();
}
}
}
fn main() {
foo();
}
Output:
Compiling playground v0.0.1 (file:///playground)
thread 'rustc' has overflowed its stack
fatal runtime error: stack overflow
error: Could not compile `playground`.
To learn more, run the command again with --verbose.
Expected (something like):
Compiling playground v0.0.1 (file:///playground)
error[E0072]: recursive type `Foo` has infinite size
--> src/main.rs:1:1
|
1 | struct Foo(Foo);
| ^^^^^^^^^^^----^
| | |
| | recursive without indirection
| recursive type has infinite size
|
= help: insert indirection (e.g., a `Box`, `Rc`, or `&`) at some point to make `Foo` representable
error: aborting due to previous error
error: Could not compile `playground`.
To learn more, run the command again with --verbose.