summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_error_codes/src/error_codes/E0627.md
blob: 21358e1e567dce08806878c048f9eb8861117197 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
A yield expression was used outside of the generator literal.

Erroneous code example:

```compile_fail,E0627
#![feature(generators, generator_trait)]

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

fn main() {
    let mut generator = fake_generator;
}
```

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

```
#![feature(generators, generator_trait)]

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