Error code E0627

A yield expression was used outside of the coroutine literal.

Erroneous code example:

#![feature(coroutines, coroutine_trait)]

fn fake_coroutine() -> &'static str {
    yield 1;
    return "foo"
}

fn main() {
    let mut coroutine = fake_coroutine;
}

The error occurs because keyword yield can only be used inside the coroutine literal. This can be fixed by constructing the coroutine correctly.

#![feature(coroutines, coroutine_trait)]

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