mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 00:03:43 +00:00
Reword E0626 to mention static coroutine
This commit is contained in:
parent
92c6c03805
commit
023b583f6a
@ -1,4 +1,4 @@
|
|||||||
This error occurs because a borrow in a coroutine persists across a
|
This error occurs because a borrow in a movable coroutine persists across a
|
||||||
yield point.
|
yield point.
|
||||||
|
|
||||||
Erroneous code example:
|
Erroneous code example:
|
||||||
@ -15,19 +15,35 @@ let mut b = #[coroutine] || {
|
|||||||
Pin::new(&mut b).resume(());
|
Pin::new(&mut b).resume(());
|
||||||
```
|
```
|
||||||
|
|
||||||
At present, it is not permitted to have a yield that occurs while a
|
Coroutines may be either unmarked, or marked with `static`. If it is unmarked,
|
||||||
borrow is still in scope. To resolve this error, the borrow must
|
then the coroutine is considered "movable". At present, it is not permitted to
|
||||||
either be "contained" to a smaller scope that does not overlap the
|
have a yield in a movable coroutine that occurs while a borrow is still in
|
||||||
yield or else eliminated in another way. So, for example, we might
|
scope. To resolve this error, the coroutine may be marked `static`:
|
||||||
resolve the previous example by removing the borrow and just storing
|
|
||||||
the integer by value:
|
```
|
||||||
|
# #![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
|
||||||
|
# use std::ops::Coroutine;
|
||||||
|
# use std::pin::Pin;
|
||||||
|
let mut b = #[coroutine] static || { // <-- note the static keyword
|
||||||
|
let a = &String::from("hello, world");
|
||||||
|
yield ();
|
||||||
|
println!("{}", a);
|
||||||
|
};
|
||||||
|
let mut b = std::pin::pin!(b);
|
||||||
|
b.as_mut().resume(());
|
||||||
|
```
|
||||||
|
|
||||||
|
If the coroutine must remain movable, for example to be used as `Unpin`
|
||||||
|
without pinning it on the stack or in an allocation, we can alternatively
|
||||||
|
resolve the previous example by removing the borrow and just storing the
|
||||||
|
type by value:
|
||||||
|
|
||||||
```
|
```
|
||||||
# #![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
|
# #![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
|
||||||
# use std::ops::Coroutine;
|
# use std::ops::Coroutine;
|
||||||
# use std::pin::Pin;
|
# use std::pin::Pin;
|
||||||
let mut b = #[coroutine] || {
|
let mut b = #[coroutine] || {
|
||||||
let a = 3;
|
let a = String::from("hello, world");
|
||||||
yield ();
|
yield ();
|
||||||
println!("{}", a);
|
println!("{}", a);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user