Skip to content

Generator example does not compile #58195

@diwic

Description

@diwic

Here's an example:

https://doc.rust-lang.org/std/ops/trait.Generator.html

Trying to compile it with nightly@play.rust-lang.org (2019-02-04) yields (heh) the following errors:

error[E0599]: no method named `resume` found for type `[generator@src/main.rs:7:25: 10:6 _]` in the current scope
error[E0698]: type inside generator must be known in this context

For reference, here's the example I'm trying to compile:

#![allow(unused)]
#![feature(generators, generator_trait)]

use std::ops::{Generator, GeneratorState};

fn main() {
    let mut generator = || {
        yield 1;
        return "foo"
    };

    match unsafe { generator.resume() } {
        GeneratorState::Yielded(1) => {}
        _ => panic!("unexpected return from resume"),
    }
    match unsafe { generator.resume() } {
        GeneratorState::Complete("foo") => {}
        _ => panic!("unexpected return from resume"),
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions