Skip to content

Commit

Permalink
Replace all uses of generator in markdown documentation with `corou…
Browse files Browse the repository at this point in the history
…tine`
  • Loading branch information
oli-obk committed Oct 20, 2023
1 parent 6fa47e1 commit 258af95
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 52 deletions.
12 changes: 6 additions & 6 deletions compiler/rustc_error_codes/src/error_codes/E0626.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
This error occurs because a borrow in a generator persists across a
This error occurs because a borrow in a coroutine persists across a
yield point.

Erroneous code example:

```compile_fail,E0626
# #![feature(generators, generator_trait, pin)]
# #![feature(coroutines, coroutine_trait, pin)]
# use std::ops::Coroutine;
# use std::pin::Pin;
let mut b = || {
Expand All @@ -23,7 +23,7 @@ resolve the previous example by removing the borrow and just storing
the integer by value:

```
# #![feature(generators, generator_trait, pin)]
# #![feature(coroutines, coroutine_trait, pin)]
# use std::ops::Coroutine;
# use std::pin::Pin;
let mut b = || {
Expand All @@ -41,7 +41,7 @@ in those cases, something like the `Rc` or `Arc` types may be useful.
This error also frequently arises with iteration:

```compile_fail,E0626
# #![feature(generators, generator_trait, pin)]
# #![feature(coroutines, coroutine_trait, pin)]
# use std::ops::Coroutine;
# use std::pin::Pin;
let mut b = || {
Expand All @@ -57,7 +57,7 @@ Such cases can sometimes be resolved by iterating "by value" (or using
`into_iter()`) to avoid borrowing:

```
# #![feature(generators, generator_trait, pin)]
# #![feature(coroutines, coroutine_trait, pin)]
# use std::ops::Coroutine;
# use std::pin::Pin;
let mut b = || {
Expand All @@ -72,7 +72,7 @@ Pin::new(&mut b).resume(());
If taking ownership is not an option, using indices can work too:

```
# #![feature(generators, generator_trait, pin)]
# #![feature(coroutines, coroutine_trait, pin)]
# use std::ops::Coroutine;
# use std::pin::Pin;
let mut b = || {
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_error_codes/src/error_codes/E0627.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
A yield expression was used outside of the generator literal.
A yield expression was used outside of the coroutine literal.

Erroneous code example:

```compile_fail,E0627
#![feature(generators, generator_trait)]
#![feature(coroutines, coroutine_trait)]
fn fake_generator() -> &'static str {
fn fake_coroutine() -> &'static str {
yield 1;
return "foo"
}
fn main() {
let mut generator = fake_generator;
let mut coroutine = fake_coroutine;
}
```

The error occurs because keyword `yield` can only be used inside the generator
literal. This can be fixed by constructing the generator correctly.
The error occurs because keyword `yield` can only be used inside the coroutine
literal. This can be fixed by constructing the coroutine correctly.

```
#![feature(generators, generator_trait)]
#![feature(coroutines, coroutine_trait)]
fn main() {
let mut generator = || {
let mut coroutine = || {
yield 1;
return "foo"
};
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_error_codes/src/error_codes/E0628.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
More than one parameter was used for a generator.
More than one parameter was used for a coroutine.

Erroneous code example:

```compile_fail,E0628
#![feature(generators, generator_trait)]
#![feature(coroutines, coroutine_trait)]
fn main() {
let generator = |a: i32, b: i32| {
// error: too many parameters for a generator
let coroutine = |a: i32, b: i32| {
// error: too many parameters for a coroutine
// Allowed only 0 or 1 parameter
yield a;
};
}
```

At present, it is not permitted to pass more than one explicit
parameter for a generator.This can be fixed by using
at most 1 parameter for the generator. For example, we might resolve
parameter for a coroutine.This can be fixed by using
at most 1 parameter for the coroutine. For example, we might resolve
the previous example by passing only one parameter.

```
#![feature(generators, generator_trait)]
#![feature(coroutines, coroutine_trait)]
fn main() {
let generator = |a: i32| {
let coroutine = |a: i32| {
yield a;
};
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_error_codes/src/error_codes/E0698.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#### Note: this error code is no longer emitted by the compiler.

When using generators (or async) all type variables must be bound so a
generator can be constructed.
When using coroutines (or async) all type variables must be bound so a
coroutine can be constructed.

Erroneous code example:

Expand All @@ -15,7 +15,7 @@ async fn foo() {

In the above example `T` is unknowable by the compiler.
To fix this you must bind `T` to a concrete type such as `String`
so that a generator can then be constructed:
so that a coroutine can then be constructed:

```edition2018
async fn bar<T>() -> () {}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_error_codes/src/error_codes/E0727.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ A `yield` clause was used in an `async` context.
Erroneous code example:

```compile_fail,E0727,edition2018
#![feature(generators)]
#![feature(coroutines)]
fn main() {
let generator = || {
let coroutine = || {
async {
yield;
}
Expand All @@ -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(generators)]
#![feature(coroutines)]
fn main() {
let generator = || {
let coroutine = || {
yield;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The tracking issue for this feature is: [#87417]

------------------------

Allows using the `#[track_caller]` attribute on closures and generators.
Calls made to the closure or generator will have caller information
Allows using the `#[track_caller]` attribute on closures and coroutines.
Calls made to the closure or coroutine will have caller information
available through `std::panic::Location::caller()`, just like using
`#[track_caller]` on a function.
18 changes: 9 additions & 9 deletions src/doc/unstable-book/src/the-unstable-book.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@ each one organized by a "feature flag." That is, when using an unstable
feature of Rust, you must use a flag, like this:

```rust
#![feature(generators, generator_trait)]
#![feature(coroutines, coroutine_trait)]

use std::ops::{Generator, GeneratorState};
use std::ops::{Coroutine, CoroutineState};
use std::pin::Pin;

fn main() {
let mut generator = || {
let mut coroutine = || {
yield 1;
return "foo"
};

match Pin::new(&mut generator).resume(()) {
GeneratorState::Yielded(1) => {}
match Pin::new(&mut coroutine).resume(()) {
CoroutineState::Yielded(1) => {}
_ => panic!("unexpected value from resume"),
}
match Pin::new(&mut generator).resume(()) {
GeneratorState::Complete("foo") => {}
match Pin::new(&mut coroutine).resume(()) {
CoroutineState::Complete("foo") => {}
_ => panic!("unexpected value from resume"),
}
}
```

The `generators` feature [has a chapter][generators] describing how to use it.
The `coroutines` feature [has a chapter][coroutines] describing how to use it.

[generators]: language-features/generators.md
[coroutines]: language-features/coroutines.md

Because this documentation relates to unstable features, we make no guarantees
that what is contained here is accurate or up to date. It's developed on a
Expand Down
24 changes: 12 additions & 12 deletions tests/run-coverage/yield.coverage
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
LL| |#![feature(generators, generator_trait)]
LL| |#![feature(coroutines, coroutine_trait)]
LL| |#![allow(unused_assignments)]
LL| |
LL| |use std::ops::{Generator, GeneratorState};
LL| |use std::ops::{Coroutine, CoroutineState};
LL| |use std::pin::Pin;
LL| |
LL| 1|fn main() {
LL| 1| let mut generator = || {
LL| 1| let mut coroutine = || {
LL| 1| yield 1;
LL| 1| return "foo";
LL| 1| };
LL| |
LL| 1| match Pin::new(&mut generator).resume(()) {
LL| 1| GeneratorState::Yielded(1) => {}
LL| 1| match Pin::new(&mut coroutine).resume(()) {
LL| 1| CoroutineState::Yielded(1) => {}
LL| 0| _ => panic!("unexpected value from resume"),
LL| | }
LL| 1| match Pin::new(&mut generator).resume(()) {
LL| 1| GeneratorState::Complete("foo") => {}
LL| 1| match Pin::new(&mut coroutine).resume(()) {
LL| 1| CoroutineState::Complete("foo") => {}
LL| 0| _ => panic!("unexpected value from resume"),
LL| | }
LL| |
LL| 1| let mut generator = || {
LL| 1| let mut coroutine = || {
LL| 1| yield 1;
LL| 1| yield 2;
LL| 0| yield 3;
LL| 0| return "foo";
LL| 0| };
LL| |
LL| 1| match Pin::new(&mut generator).resume(()) {
LL| 1| GeneratorState::Yielded(1) => {}
LL| 1| match Pin::new(&mut coroutine).resume(()) {
LL| 1| CoroutineState::Yielded(1) => {}
LL| 0| _ => panic!("unexpected value from resume"),
LL| | }
LL| 1| match Pin::new(&mut generator).resume(()) {
LL| 1| GeneratorState::Yielded(2) => {}
LL| 1| match Pin::new(&mut coroutine).resume(()) {
LL| 1| CoroutineState::Yielded(2) => {}
LL| 0| _ => panic!("unexpected value from resume"),
LL| | }
LL| 1|}
Expand Down

0 comments on commit 258af95

Please sign in to comment.