]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0627.md
Merge commit '7248d06384c6a90de58c04c1f46be88821278d8b' into sync-from-clippy
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0627.md
1 A yield expression was used outside of the generator literal.
2
3 Erroneous code example:
4
5 ```compile_fail,E0627
6 #![feature(generators, generator_trait)]
7
8 fn fake_generator() -> &'static str {
9     yield 1;
10     return "foo"
11 }
12
13 fn main() {
14     let mut generator = fake_generator;
15 }
16 ```
17
18 The error occurs because keyword `yield` can only be used inside the generator
19 literal. This can be fixed by constructing the generator correctly.
20
21 ```
22 #![feature(generators, generator_trait)]
23
24 fn main() {
25     let mut generator = || {
26         yield 1;
27         return "foo"
28     };
29 }
30 ```