Skip to content

Commit 8594375

Browse files
committed
s/generator/coroutine/
1 parent b577f84 commit 8594375

File tree

13 files changed

+79
-77
lines changed

13 files changed

+79
-77
lines changed

alloc/src/boxed.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,7 +2106,7 @@ impl<T: ?Sized, A: Allocator> AsMut<T> for Box<T, A> {
21062106
#[stable(feature = "pin", since = "1.33.0")]
21072107
impl<T: ?Sized, A: Allocator> Unpin for Box<T, A> where A: 'static {}
21082108

2109-
#[unstable(feature = "generator_trait", issue = "43122")]
2109+
#[unstable(feature = "coroutine_trait", issue = "43122")]
21102110
impl<G: ?Sized + Coroutine<R> + Unpin, R, A: Allocator> Coroutine<R> for Box<G, A>
21112111
where
21122112
A: 'static,
@@ -2119,7 +2119,7 @@ where
21192119
}
21202120
}
21212121

2122-
#[unstable(feature = "generator_trait", issue = "43122")]
2122+
#[unstable(feature = "coroutine_trait", issue = "43122")]
21232123
impl<G: ?Sized + Coroutine<R>, R, A: Allocator> Coroutine<R> for Pin<Box<G, A>>
21242124
where
21252125
A: 'static,

alloc/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
//
170170
// Language features:
171171
// tidy-alphabetical-start
172-
#![cfg_attr(not(test), feature(generator_trait))]
172+
#![cfg_attr(not(test), feature(coroutine_trait))]
173173
#![cfg_attr(test, feature(panic_update_hook))]
174174
#![cfg_attr(test, feature(test))]
175175
#![feature(allocator_internals)]

alloc/tests/autotraits.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ fn test_btree_map() {
1414
//
1515
// We test autotraits in this convoluted way, instead of a straightforward
1616
// `require_send_sync::<TypeIWantToTest>()`, because the interaction with
17-
// generators exposes some current limitations in rustc's ability to prove a
18-
// lifetime bound on the erased generator witness types. See the above link.
17+
// coroutines exposes some current limitations in rustc's ability to prove a
18+
// lifetime bound on the erased coroutine witness types. See the above link.
1919
//
2020
// A typical way this would surface in real code is:
2121
//

core/src/iter/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,11 @@ pub use self::traits::Iterator;
391391
pub use self::range::Step;
392392

393393
#[unstable(
394-
feature = "iter_from_generator",
394+
feature = "iter_from_coroutine",
395395
issue = "43122",
396-
reason = "generators are unstable"
396+
reason = "coroutines are unstable"
397397
)]
398-
pub use self::sources::from_generator;
398+
pub use self::sources::from_coroutine;
399399
#[stable(feature = "iter_empty", since = "1.2.0")]
400400
pub use self::sources::{empty, Empty};
401401
#[stable(feature = "iter_from_fn", since = "1.34.0")]

core/src/iter/sources.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
mod empty;
2+
mod from_coroutine;
23
mod from_fn;
3-
mod from_generator;
44
mod once;
55
mod once_with;
66
mod repeat;
@@ -27,11 +27,11 @@ pub use self::repeat_with::{repeat_with, RepeatWith};
2727
pub use self::from_fn::{from_fn, FromFn};
2828

2929
#[unstable(
30-
feature = "iter_from_generator",
30+
feature = "iter_from_coroutine",
3131
issue = "43122",
32-
reason = "generators are unstable"
32+
reason = "coroutines are unstable"
3333
)]
34-
pub use self::from_generator::from_generator;
34+
pub use self::from_coroutine::from_coroutine;
3535

3636
#[stable(feature = "iter_successors", since = "1.34.0")]
3737
pub use self::successors::{successors, Successors};

core/src/iter/sources/from_generator.rs renamed to core/src/iter/sources/from_coroutine.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::fmt;
22
use crate::ops::{Coroutine, CoroutineState};
33
use crate::pin::Pin;
44

5-
/// Creates a new iterator where each iteration calls the provided generator.
5+
/// Creates a new iterator where each iteration calls the provided coroutine.
66
///
77
/// Similar to [`iter::from_fn`].
88
///
@@ -11,10 +11,10 @@ use crate::pin::Pin;
1111
/// # Examples
1212
///
1313
/// ```
14-
/// #![feature(generators)]
15-
/// #![feature(iter_from_generator)]
14+
/// #![feature(coroutines)]
15+
/// #![feature(iter_from_coroutine)]
1616
///
17-
/// let it = std::iter::from_generator(|| {
17+
/// let it = std::iter::from_coroutine(|| {
1818
/// yield 1;
1919
/// yield 2;
2020
/// yield 3;
@@ -23,22 +23,22 @@ use crate::pin::Pin;
2323
/// assert_eq!(v, [1, 2, 3]);
2424
/// ```
2525
#[inline]
26-
#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
27-
pub fn from_generator<G: Coroutine<Return = ()> + Unpin>(generator: G) -> FromCoroutine<G> {
28-
FromCoroutine(generator)
26+
#[unstable(feature = "iter_from_coroutine", issue = "43122", reason = "coroutines are unstable")]
27+
pub fn from_coroutine<G: Coroutine<Return = ()> + Unpin>(coroutine: G) -> FromCoroutine<G> {
28+
FromCoroutine(coroutine)
2929
}
3030

31-
/// An iterator over the values yielded by an underlying generator.
31+
/// An iterator over the values yielded by an underlying coroutine.
3232
///
33-
/// This `struct` is created by the [`iter::from_generator()`] function. See its documentation for
33+
/// This `struct` is created by the [`iter::from_coroutine()`] function. See its documentation for
3434
/// more.
3535
///
36-
/// [`iter::from_generator()`]: from_generator
37-
#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
36+
/// [`iter::from_coroutine()`]: from_coroutine
37+
#[unstable(feature = "iter_from_coroutine", issue = "43122", reason = "coroutines are unstable")]
3838
#[derive(Clone)]
3939
pub struct FromCoroutine<G>(G);
4040

41-
#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
41+
#[unstable(feature = "iter_from_coroutine", issue = "43122", reason = "coroutines are unstable")]
4242
impl<G: Coroutine<Return = ()> + Unpin> Iterator for FromCoroutine<G> {
4343
type Item = G::Yield;
4444

@@ -50,7 +50,7 @@ impl<G: Coroutine<Return = ()> + Unpin> Iterator for FromCoroutine<G> {
5050
}
5151
}
5252

53-
#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
53+
#[unstable(feature = "iter_from_coroutine", issue = "43122", reason = "coroutines are unstable")]
5454
impl<G> fmt::Debug for FromCoroutine<G> {
5555
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5656
f.debug_struct("FromCoroutine").finish()

core/src/iter/sources/once_with.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::iter::{FusedIterator, TrustedLen};
44
/// Creates an iterator that lazily generates a value exactly once by invoking
55
/// the provided closure.
66
///
7-
/// This is commonly used to adapt a single value generator into a [`chain()`] of
7+
/// This is commonly used to adapt a single value coroutine into a [`chain()`] of
88
/// other kinds of iteration. Maybe you have an iterator that covers almost
99
/// everything, but you need an extra special case. Maybe you have a function
1010
/// which works on iterators, but you only need to process one value.

core/src/mem/maybe_uninit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ use crate::slice;
242242
/// the same size, alignment, and ABI as `T`; it's just that the way `MaybeUninit` implements that
243243
/// guarantee may evolve.
244244
#[stable(feature = "maybe_uninit", since = "1.36.0")]
245-
// Lang item so we can wrap other types in it. This is useful for generators.
245+
// Lang item so we can wrap other types in it. This is useful for coroutines.
246246
#[lang = "maybe_uninit"]
247247
#[derive(Copy)]
248248
#[repr(transparent)]

core/src/ops/generator.rs renamed to core/src/ops/coroutine.rs

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,122 @@
11
use crate::marker::Unpin;
22
use crate::pin::Pin;
33

4-
/// The result of a generator resumption.
4+
/// The result of a coroutine resumption.
55
///
66
/// This enum is returned from the `Coroutine::resume` method and indicates the
7-
/// possible return values of a generator. Currently this corresponds to either
7+
/// possible return values of a coroutine. Currently this corresponds to either
88
/// a suspension point (`Yielded`) or a termination point (`Complete`).
99
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
10-
#[lang = "generator_state"]
11-
#[unstable(feature = "generator_trait", issue = "43122")]
10+
#[cfg_attr(bootstrap, lang = "generator_state")]
11+
#[cfg_attr(not(bootstrap), lang = "coroutine_state")]
12+
#[unstable(feature = "coroutine_trait", issue = "43122")]
1213
pub enum CoroutineState<Y, R> {
13-
/// The generator suspended with a value.
14+
/// The coroutine suspended with a value.
1415
///
15-
/// This state indicates that a generator has been suspended, and typically
16+
/// This state indicates that a coroutine has been suspended, and typically
1617
/// corresponds to a `yield` statement. The value provided in this variant
17-
/// corresponds to the expression passed to `yield` and allows generators to
18+
/// corresponds to the expression passed to `yield` and allows coroutines to
1819
/// provide a value each time they yield.
1920
Yielded(Y),
2021

21-
/// The generator completed with a return value.
22+
/// The coroutine completed with a return value.
2223
///
23-
/// This state indicates that a generator has finished execution with the
24-
/// provided value. Once a generator has returned `Complete` it is
24+
/// This state indicates that a coroutine has finished execution with the
25+
/// provided value. Once a coroutine has returned `Complete` it is
2526
/// considered a programmer error to call `resume` again.
2627
Complete(R),
2728
}
2829

29-
/// The trait implemented by builtin generator types.
30+
/// The trait implemented by builtin coroutine types.
3031
///
3132
/// Coroutines, also commonly referred to as coroutines, are currently an
32-
/// experimental language feature in Rust. Added in [RFC 2033] generators are
33+
/// experimental language feature in Rust. Added in [RFC 2033] coroutines are
3334
/// currently intended to primarily provide a building block for async/await
3435
/// syntax but will likely extend to also providing an ergonomic definition for
3536
/// iterators and other primitives.
3637
///
37-
/// The syntax and semantics for generators is unstable and will require a
38+
/// The syntax and semantics for coroutines is unstable and will require a
3839
/// further RFC for stabilization. At this time, though, the syntax is
3940
/// closure-like:
4041
///
4142
/// ```rust
42-
/// #![feature(generators, generator_trait)]
43+
/// #![feature(coroutines, coroutine_trait)]
4344
///
4445
/// use std::ops::{Coroutine, CoroutineState};
4546
/// use std::pin::Pin;
4647
///
4748
/// fn main() {
48-
/// let mut generator = || {
49+
/// let mut coroutine = || {
4950
/// yield 1;
5051
/// "foo"
5152
/// };
5253
///
53-
/// match Pin::new(&mut generator).resume(()) {
54+
/// match Pin::new(&mut coroutine).resume(()) {
5455
/// CoroutineState::Yielded(1) => {}
5556
/// _ => panic!("unexpected return from resume"),
5657
/// }
57-
/// match Pin::new(&mut generator).resume(()) {
58+
/// match Pin::new(&mut coroutine).resume(()) {
5859
/// CoroutineState::Complete("foo") => {}
5960
/// _ => panic!("unexpected return from resume"),
6061
/// }
6162
/// }
6263
/// ```
6364
///
64-
/// More documentation of generators can be found in the [unstable book].
65+
/// More documentation of coroutines can be found in the [unstable book].
6566
///
6667
/// [RFC 2033]: https://github.com/rust-lang/rfcs/pull/2033
67-
/// [unstable book]: ../../unstable-book/language-features/generators.html
68-
#[lang = "generator"]
69-
#[unstable(feature = "generator_trait", issue = "43122")]
68+
/// [unstable book]: ../../unstable-book/language-features/coroutines.html
69+
#[cfg_attr(bootstrap, lang = "generator")]
70+
#[cfg_attr(not(bootstrap), lang = "coroutine")]
71+
#[unstable(feature = "coroutine_trait", issue = "43122")]
7072
#[fundamental]
7173
pub trait Coroutine<R = ()> {
72-
/// The type of value this generator yields.
74+
/// The type of value this coroutine yields.
7375
///
7476
/// This associated type corresponds to the `yield` expression and the
75-
/// values which are allowed to be returned each time a generator yields.
76-
/// For example an iterator-as-a-generator would likely have this type as
77+
/// values which are allowed to be returned each time a coroutine yields.
78+
/// For example an iterator-as-a-coroutine would likely have this type as
7779
/// `T`, the type being iterated over.
7880
type Yield;
7981

80-
/// The type of value this generator returns.
82+
/// The type of value this coroutine returns.
8183
///
82-
/// This corresponds to the type returned from a generator either with a
83-
/// `return` statement or implicitly as the last expression of a generator
84+
/// This corresponds to the type returned from a coroutine either with a
85+
/// `return` statement or implicitly as the last expression of a coroutine
8486
/// literal. For example futures would use this as `Result<T, E>` as it
8587
/// represents a completed future.
8688
type Return;
8789

88-
/// Resumes the execution of this generator.
90+
/// Resumes the execution of this coroutine.
8991
///
90-
/// This function will resume execution of the generator or start execution
91-
/// if it hasn't already. This call will return back into the generator's
92+
/// This function will resume execution of the coroutine or start execution
93+
/// if it hasn't already. This call will return back into the coroutine's
9294
/// last suspension point, resuming execution from the latest `yield`. The
93-
/// generator will continue executing until it either yields or returns, at
95+
/// coroutine will continue executing until it either yields or returns, at
9496
/// which point this function will return.
9597
///
9698
/// # Return value
9799
///
98100
/// The `CoroutineState` enum returned from this function indicates what
99-
/// state the generator is in upon returning. If the `Yielded` variant is
100-
/// returned then the generator has reached a suspension point and a value
101+
/// state the coroutine is in upon returning. If the `Yielded` variant is
102+
/// returned then the coroutine has reached a suspension point and a value
101103
/// has been yielded out. Coroutines in this state are available for
102104
/// resumption at a later point.
103105
///
104-
/// If `Complete` is returned then the generator has completely finished
105-
/// with the value provided. It is invalid for the generator to be resumed
106+
/// If `Complete` is returned then the coroutine has completely finished
107+
/// with the value provided. It is invalid for the coroutine to be resumed
106108
/// again.
107109
///
108110
/// # Panics
109111
///
110112
/// This function may panic if it is called after the `Complete` variant has
111-
/// been returned previously. While generator literals in the language are
113+
/// been returned previously. While coroutine literals in the language are
112114
/// guaranteed to panic on resuming after `Complete`, this is not guaranteed
113115
/// for all implementations of the `Coroutine` trait.
114116
fn resume(self: Pin<&mut Self>, arg: R) -> CoroutineState<Self::Yield, Self::Return>;
115117
}
116118

117-
#[unstable(feature = "generator_trait", issue = "43122")]
119+
#[unstable(feature = "coroutine_trait", issue = "43122")]
118120
impl<G: ?Sized + Coroutine<R>, R> Coroutine<R> for Pin<&mut G> {
119121
type Yield = G::Yield;
120122
type Return = G::Return;
@@ -124,7 +126,7 @@ impl<G: ?Sized + Coroutine<R>, R> Coroutine<R> for Pin<&mut G> {
124126
}
125127
}
126128

127-
#[unstable(feature = "generator_trait", issue = "43122")]
129+
#[unstable(feature = "coroutine_trait", issue = "43122")]
128130
impl<G: ?Sized + Coroutine<R> + Unpin, R> Coroutine<R> for &mut G {
129131
type Yield = G::Yield;
130132
type Return = G::Return;

core/src/ops/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@
141141
mod arith;
142142
mod bit;
143143
mod control_flow;
144+
mod coroutine;
144145
mod deref;
145146
mod drop;
146147
mod function;
147-
mod generator;
148148
mod index;
149149
mod index_range;
150150
mod range;
@@ -198,8 +198,8 @@ pub use self::try_trait::Residual;
198198

199199
pub(crate) use self::try_trait::{ChangeOutputType, NeverShortCircuit};
200200

201-
#[unstable(feature = "generator_trait", issue = "43122")]
202-
pub use self::generator::{Coroutine, CoroutineState};
201+
#[unstable(feature = "coroutine_trait", issue = "43122")]
202+
pub use self::coroutine::{Coroutine, CoroutineState};
203203

204204
#[unstable(feature = "coerce_unsized", issue = "18598")]
205205
pub use self::unsize::CoerceUnsized;

0 commit comments

Comments
 (0)