diff options
Diffstat (limited to 'compiler/rustc_error_codes/src/error_codes/E0627.md')
-rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0627.md | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0627.md b/compiler/rustc_error_codes/src/error_codes/E0627.md new file mode 100644 index 000000000..21358e1e5 --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0627.md @@ -0,0 +1,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" + }; +} +``` |