@@ -4,10 +4,10 @@ yield point.
44Erroneous code example:
55
66``` compile_fail,E0626
7- # #![feature(coroutines, coroutine_trait, pin )]
7+ # #![feature(coroutines, coroutine_trait, stmt_expr_attributes )]
88# use std::ops::Coroutine;
99# use std::pin::Pin;
10- let mut b = || {
10+ let mut b = #[coroutine] || {
1111 let a = &String::new(); // <-- This borrow...
1212 yield (); // ...is still in scope here, when the yield occurs.
1313 println!("{}", a);
@@ -23,10 +23,10 @@ resolve the previous example by removing the borrow and just storing
2323the integer by value:
2424
2525```
26- # #![feature(coroutines, coroutine_trait, pin )]
26+ # #![feature(coroutines, coroutine_trait, stmt_expr_attributes )]
2727# use std::ops::Coroutine;
2828# use std::pin::Pin;
29- let mut b = || {
29+ let mut b = #[coroutine] || {
3030 let a = 3;
3131 yield ();
3232 println!("{}", a);
@@ -41,10 +41,10 @@ in those cases, something like the `Rc` or `Arc` types may be useful.
4141This error also frequently arises with iteration:
4242
4343``` compile_fail,E0626
44- # #![feature(coroutines, coroutine_trait, pin )]
44+ # #![feature(coroutines, coroutine_trait, stmt_expr_attributes )]
4545# use std::ops::Coroutine;
4646# use std::pin::Pin;
47- let mut b = || {
47+ let mut b = #[coroutine] || {
4848 let v = vec![1,2,3];
4949 for &x in &v { // <-- borrow of `v` is still in scope...
5050 yield x; // ...when this yield occurs.
@@ -57,10 +57,10 @@ Such cases can sometimes be resolved by iterating "by value" (or using
5757` into_iter() ` ) to avoid borrowing:
5858
5959```
60- # #![feature(coroutines, coroutine_trait, pin )]
60+ # #![feature(coroutines, coroutine_trait, stmt_expr_attributes )]
6161# use std::ops::Coroutine;
6262# use std::pin::Pin;
63- let mut b = || {
63+ let mut b = #[coroutine] || {
6464 let v = vec![1,2,3];
6565 for x in v { // <-- Take ownership of the values instead!
6666 yield x; // <-- Now yield is OK.
@@ -72,10 +72,10 @@ Pin::new(&mut b).resume(());
7272If taking ownership is not an option, using indices can work too:
7373
7474```
75- # #![feature(coroutines, coroutine_trait, pin )]
75+ # #![feature(coroutines, coroutine_trait, stmt_expr_attributes )]
7676# use std::ops::Coroutine;
7777# use std::pin::Pin;
78- let mut b = || {
78+ let mut b = #[coroutine] || {
7979 let v = vec![1,2,3];
8080 let len = v.len(); // (*)
8181 for i in 0..len {
0 commit comments