Skip to content

Generator example does not compile #58195

Closed
@diwic

Description

@diwic
Contributor

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"),
    }
}

Activity

taiki-e

taiki-e commented on Feb 5, 2019

@taiki-e
Member

The implementation of Generator has been changed in #55704.

The nightly document has the latest example: https://doc.rust-lang.org/nightly/std/ops/trait.Generator.html

added
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
on Feb 6, 2019
diwic

diwic commented on Feb 6, 2019

@diwic
ContributorAuthor

Thanks for the info! And sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @estebank@diwic@taiki-e

        Issue actions

          Generator example does not compile · Issue #58195 · rust-lang/rust