about summary refs log tree commit diff
path: root/compiler/rustc_error_codes
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-04-11 13:15:34 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-04-24 08:05:29 +0000
commitaef0f4024aec24fd7e53dbc51883457e44fe17ce (patch)
tree25a26930a8cc3441951ba159f1a632092df41655 /compiler/rustc_error_codes
parenta589632dad58c2669b7984019efb59917a16ac67 (diff)
downloadrust-aef0f4024aec24fd7e53dbc51883457e44fe17ce.tar.gz
rust-aef0f4024aec24fd7e53dbc51883457e44fe17ce.zip
Error on using `yield` without also using `#[coroutine]` on the closure
And suggest adding the `#[coroutine]` to the closure
Diffstat (limited to 'compiler/rustc_error_codes')
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0626.md20
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0627.md6
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0628.md8
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0727.md8
4 files changed, 21 insertions, 21 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0626.md b/compiler/rustc_error_codes/src/error_codes/E0626.md
index e2534415d83..28d543350ff 100644
--- a/compiler/rustc_error_codes/src/error_codes/E0626.md
+++ b/compiler/rustc_error_codes/src/error_codes/E0626.md
@@ -4,10 +4,10 @@ yield point.
 Erroneous code example:
 
 ```compile_fail,E0626
-# #![feature(coroutines, coroutine_trait, pin)]
+# #![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
 # use std::ops::Coroutine;
 # use std::pin::Pin;
-let mut b = || {
+let mut b = #[coroutine] || {
     let a = &String::new(); // <-- This borrow...
     yield (); // ...is still in scope here, when the yield occurs.
     println!("{}", a);
@@ -23,10 +23,10 @@ resolve the previous example by removing the borrow and just storing
 the integer by value:
 
 ```
-# #![feature(coroutines, coroutine_trait, pin)]
+# #![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
 # use std::ops::Coroutine;
 # use std::pin::Pin;
-let mut b = || {
+let mut b = #[coroutine] || {
     let a = 3;
     yield ();
     println!("{}", a);
@@ -41,10 +41,10 @@ in those cases, something like the `Rc` or `Arc` types may be useful.
 This error also frequently arises with iteration:
 
 ```compile_fail,E0626
-# #![feature(coroutines, coroutine_trait, pin)]
+# #![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
 # use std::ops::Coroutine;
 # use std::pin::Pin;
-let mut b = || {
+let mut b = #[coroutine] || {
   let v = vec![1,2,3];
   for &x in &v { // <-- borrow of `v` is still in scope...
     yield x; // ...when this yield occurs.
@@ -57,10 +57,10 @@ Such cases can sometimes be resolved by iterating "by value" (or using
 `into_iter()`) to avoid borrowing:
 
 ```
-# #![feature(coroutines, coroutine_trait, pin)]
+# #![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
 # use std::ops::Coroutine;
 # use std::pin::Pin;
-let mut b = || {
+let mut b = #[coroutine] || {
   let v = vec![1,2,3];
   for x in v { // <-- Take ownership of the values instead!
     yield x; // <-- Now yield is OK.
@@ -72,10 +72,10 @@ Pin::new(&mut b).resume(());
 If taking ownership is not an option, using indices can work too:
 
 ```
-# #![feature(coroutines, coroutine_trait, pin)]
+# #![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
 # use std::ops::Coroutine;
 # use std::pin::Pin;
-let mut b = || {
+let mut b = #[coroutine] || {
   let v = vec![1,2,3];
   let len = v.len(); // (*)
   for i in 0..len {
diff --git a/compiler/rustc_error_codes/src/error_codes/E0627.md b/compiler/rustc_error_codes/src/error_codes/E0627.md
index 5d366f78fc5..da2e2d355a1 100644
--- a/compiler/rustc_error_codes/src/error_codes/E0627.md
+++ b/compiler/rustc_error_codes/src/error_codes/E0627.md
@@ -3,7 +3,7 @@ A yield expression was used outside of the coroutine literal.
 Erroneous code example:
 
 ```compile_fail,E0627
-#![feature(coroutines, coroutine_trait)]
+#![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
 
 fn fake_coroutine() -> &'static str {
     yield 1;
@@ -19,10 +19,10 @@ 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)]
+#![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
 
 fn main() {
-    let mut coroutine = || {
+    let mut coroutine = #[coroutine] || {
         yield 1;
         return "foo"
     };
diff --git a/compiler/rustc_error_codes/src/error_codes/E0628.md b/compiler/rustc_error_codes/src/error_codes/E0628.md
index ce19bcd56cc..d0d387cf6c7 100644
--- a/compiler/rustc_error_codes/src/error_codes/E0628.md
+++ b/compiler/rustc_error_codes/src/error_codes/E0628.md
@@ -3,10 +3,10 @@ More than one parameter was used for a coroutine.
 Erroneous code example:
 
 ```compile_fail,E0628
-#![feature(coroutines, coroutine_trait)]
+#![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
 
 fn main() {
-    let coroutine = |a: i32, b: i32| {
+    let coroutine = #[coroutine] |a: i32, b: i32| {
         // error: too many parameters for a coroutine
         // Allowed only 0 or 1 parameter
         yield a;
@@ -20,10 +20,10 @@ at most 1 parameter for the coroutine. For example, we might resolve
 the previous example by passing only one parameter.
 
 ```
-#![feature(coroutines, coroutine_trait)]
+#![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
 
 fn main() {
-    let coroutine = |a: i32| {
+    let coroutine = #[coroutine] |a: i32| {
         yield a;
     };
 }
diff --git a/compiler/rustc_error_codes/src/error_codes/E0727.md b/compiler/rustc_error_codes/src/error_codes/E0727.md
index fde35885c92..7754186508f 100644
--- a/compiler/rustc_error_codes/src/error_codes/E0727.md
+++ b/compiler/rustc_error_codes/src/error_codes/E0727.md
@@ -3,10 +3,10 @@ A `yield` clause was used in an `async` context.
 Erroneous code example:
 
 ```compile_fail,E0727,edition2018
-#![feature(coroutines)]
+#![feature(coroutines, stmt_expr_attributes)]
 
 fn main() {
-    let coroutine = || {
+    let coroutine = #[coroutine] || {
         async {
             yield;
         }
@@ -20,10 +20,10 @@ which is not yet supported.
 To fix this error, you have to move `yield` out of the `async` block:
 
 ```edition2018
-#![feature(coroutines)]
+#![feature(coroutines, stmt_expr_attributes)]
 
 fn main() {
-    let coroutine = || {
+    let coroutine = #[coroutine] || {
         yield;
     };
 }