Skip to content

Unhelpful "overflow evaluating the requirement" error for infinitely recursive generators #46415

Closed
@Popog

Description

@Popog

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.

playground link

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-coroutinesArea: CoroutinesA-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions