@@ -4,10 +4,10 @@ yield point.
4
4
Erroneous code example:
5
5
6
6
``` compile_fail,E0626
7
- # #![feature(coroutines, coroutine_trait, pin )]
7
+ # #![feature(coroutines, coroutine_trait, stmt_expr_attributes )]
8
8
# use std::ops::Coroutine;
9
9
# use std::pin::Pin;
10
- let mut b = || {
10
+ let mut b = #[coroutine] || {
11
11
let a = &String::new(); // <-- This borrow...
12
12
yield (); // ...is still in scope here, when the yield occurs.
13
13
println!("{}", a);
@@ -23,10 +23,10 @@ resolve the previous example by removing the borrow and just storing
23
23
the integer by value:
24
24
25
25
```
26
- # #![feature(coroutines, coroutine_trait, pin )]
26
+ # #![feature(coroutines, coroutine_trait, stmt_expr_attributes )]
27
27
# use std::ops::Coroutine;
28
28
# use std::pin::Pin;
29
- let mut b = || {
29
+ let mut b = #[coroutine] || {
30
30
let a = 3;
31
31
yield ();
32
32
println!("{}", a);
@@ -41,10 +41,10 @@ in those cases, something like the `Rc` or `Arc` types may be useful.
41
41
This error also frequently arises with iteration:
42
42
43
43
``` compile_fail,E0626
44
- # #![feature(coroutines, coroutine_trait, pin )]
44
+ # #![feature(coroutines, coroutine_trait, stmt_expr_attributes )]
45
45
# use std::ops::Coroutine;
46
46
# use std::pin::Pin;
47
- let mut b = || {
47
+ let mut b = #[coroutine] || {
48
48
let v = vec![1,2,3];
49
49
for &x in &v { // <-- borrow of `v` is still in scope...
50
50
yield x; // ...when this yield occurs.
@@ -57,10 +57,10 @@ Such cases can sometimes be resolved by iterating "by value" (or using
57
57
` into_iter() ` ) to avoid borrowing:
58
58
59
59
```
60
- # #![feature(coroutines, coroutine_trait, pin )]
60
+ # #![feature(coroutines, coroutine_trait, stmt_expr_attributes )]
61
61
# use std::ops::Coroutine;
62
62
# use std::pin::Pin;
63
- let mut b = || {
63
+ let mut b = #[coroutine] || {
64
64
let v = vec![1,2,3];
65
65
for x in v { // <-- Take ownership of the values instead!
66
66
yield x; // <-- Now yield is OK.
@@ -72,10 +72,10 @@ Pin::new(&mut b).resume(());
72
72
If taking ownership is not an option, using indices can work too:
73
73
74
74
```
75
- # #![feature(coroutines, coroutine_trait, pin )]
75
+ # #![feature(coroutines, coroutine_trait, stmt_expr_attributes )]
76
76
# use std::ops::Coroutine;
77
77
# use std::pin::Pin;
78
- let mut b = || {
78
+ let mut b = #[coroutine] || {
79
79
let v = vec![1,2,3];
80
80
let len = v.len(); // (*)
81
81
for i in 0..len {
0 commit comments