about summary refs log tree commit diff
path: root/library/core/src
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2023-10-19 21:46:28 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2023-10-20 21:14:01 +0000
commite96ce20b34789d29e925425da6cf138927b80a79 (patch)
tree4032e01ddd5137d1ee98b69277953f2962bbf14b /library/core/src
parent60956837cfbf22bd8edd80f57a856e141f7deb8c (diff)
downloadrust-e96ce20b34789d29e925425da6cf138927b80a79.tar.gz
rust-e96ce20b34789d29e925425da6cf138927b80a79.zip
s/generator/coroutine/
Diffstat (limited to 'library/core/src')
-rw-r--r--library/core/src/iter/mod.rs6
-rw-r--r--library/core/src/iter/sources.rs8
-rw-r--r--library/core/src/iter/sources/from_coroutine.rs (renamed from library/core/src/iter/sources/from_generator.rs)26
-rw-r--r--library/core/src/iter/sources/once_with.rs2
-rw-r--r--library/core/src/mem/maybe_uninit.rs2
-rw-r--r--library/core/src/ops/coroutine.rs (renamed from library/core/src/ops/generator.rs)78
-rw-r--r--library/core/src/ops/mod.rs6
-rw-r--r--library/core/src/pin.rs14
-rw-r--r--library/core/src/sync/exclusive.rs2
9 files changed, 73 insertions, 71 deletions
diff --git a/library/core/src/iter/mod.rs b/library/core/src/iter/mod.rs
index ca977d1ef82..937a149acaa 100644
--- a/library/core/src/iter/mod.rs
+++ b/library/core/src/iter/mod.rs
@@ -391,11 +391,11 @@ pub use self::traits::Iterator;
 pub use self::range::Step;
 
 #[unstable(
-    feature = "iter_from_generator",
+    feature = "iter_from_coroutine",
     issue = "43122",
-    reason = "generators are unstable"
+    reason = "coroutines are unstable"
 )]
-pub use self::sources::from_generator;
+pub use self::sources::from_coroutine;
 #[stable(feature = "iter_empty", since = "1.2.0")]
 pub use self::sources::{empty, Empty};
 #[stable(feature = "iter_from_fn", since = "1.34.0")]
diff --git a/library/core/src/iter/sources.rs b/library/core/src/iter/sources.rs
index 3ec426a3ad9..56c1f86079a 100644
--- a/library/core/src/iter/sources.rs
+++ b/library/core/src/iter/sources.rs
@@ -1,6 +1,6 @@
 mod empty;
+mod from_coroutine;
 mod from_fn;
-mod from_generator;
 mod once;
 mod once_with;
 mod repeat;
@@ -27,11 +27,11 @@ pub use self::repeat_with::{repeat_with, RepeatWith};
 pub use self::from_fn::{from_fn, FromFn};
 
 #[unstable(
-    feature = "iter_from_generator",
+    feature = "iter_from_coroutine",
     issue = "43122",
-    reason = "generators are unstable"
+    reason = "coroutines are unstable"
 )]
-pub use self::from_generator::from_generator;
+pub use self::from_coroutine::from_coroutine;
 
 #[stable(feature = "iter_successors", since = "1.34.0")]
 pub use self::successors::{successors, Successors};
diff --git a/library/core/src/iter/sources/from_generator.rs b/library/core/src/iter/sources/from_coroutine.rs
index b512f4f162c..bf413b24d41 100644
--- a/library/core/src/iter/sources/from_generator.rs
+++ b/library/core/src/iter/sources/from_coroutine.rs
@@ -2,7 +2,7 @@ use crate::fmt;
 use crate::ops::{Coroutine, CoroutineState};
 use crate::pin::Pin;
 
-/// Creates a new iterator where each iteration calls the provided generator.
+/// Creates a new iterator where each iteration calls the provided coroutine.
 ///
 /// Similar to [`iter::from_fn`].
 ///
@@ -11,10 +11,10 @@ use crate::pin::Pin;
 /// # Examples
 ///
 /// ```
-/// #![feature(generators)]
-/// #![feature(iter_from_generator)]
+/// #![feature(coroutines)]
+/// #![feature(iter_from_coroutine)]
 ///
-/// let it = std::iter::from_generator(|| {
+/// let it = std::iter::from_coroutine(|| {
 ///     yield 1;
 ///     yield 2;
 ///     yield 3;
@@ -23,22 +23,22 @@ use crate::pin::Pin;
 /// assert_eq!(v, [1, 2, 3]);
 /// ```
 #[inline]
-#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
-pub fn from_generator<G: Coroutine<Return = ()> + Unpin>(generator: G) -> FromCoroutine<G> {
-    FromCoroutine(generator)
+#[unstable(feature = "iter_from_coroutine", issue = "43122", reason = "coroutines are unstable")]
+pub fn from_coroutine<G: Coroutine<Return = ()> + Unpin>(coroutine: G) -> FromCoroutine<G> {
+    FromCoroutine(coroutine)
 }
 
-/// An iterator over the values yielded by an underlying generator.
+/// An iterator over the values yielded by an underlying coroutine.
 ///
-/// This `struct` is created by the [`iter::from_generator()`] function. See its documentation for
+/// This `struct` is created by the [`iter::from_coroutine()`] function. See its documentation for
 /// more.
 ///
-/// [`iter::from_generator()`]: from_generator
-#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
+/// [`iter::from_coroutine()`]: from_coroutine
+#[unstable(feature = "iter_from_coroutine", issue = "43122", reason = "coroutines are unstable")]
 #[derive(Clone)]
 pub struct FromCoroutine<G>(G);
 
-#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
+#[unstable(feature = "iter_from_coroutine", issue = "43122", reason = "coroutines are unstable")]
 impl<G: Coroutine<Return = ()> + Unpin> Iterator for FromCoroutine<G> {
     type Item = G::Yield;
 
@@ -50,7 +50,7 @@ impl<G: Coroutine<Return = ()> + Unpin> Iterator for FromCoroutine<G> {
     }
 }
 
-#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
+#[unstable(feature = "iter_from_coroutine", issue = "43122", reason = "coroutines are unstable")]
 impl<G> fmt::Debug for FromCoroutine<G> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         f.debug_struct("FromCoroutine").finish()
diff --git a/library/core/src/iter/sources/once_with.rs b/library/core/src/iter/sources/once_with.rs
index 9309a06c8cf..8b31ab2ff90 100644
--- a/library/core/src/iter/sources/once_with.rs
+++ b/library/core/src/iter/sources/once_with.rs
@@ -4,7 +4,7 @@ use crate::iter::{FusedIterator, TrustedLen};
 /// Creates an iterator that lazily generates a value exactly once by invoking
 /// the provided closure.
 ///
-/// This is commonly used to adapt a single value generator into a [`chain()`] of
+/// This is commonly used to adapt a single value coroutine into a [`chain()`] of
 /// other kinds of iteration. Maybe you have an iterator that covers almost
 /// everything, but you need an extra special case. Maybe you have a function
 /// which works on iterators, but you only need to process one value.
diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs
index 6274a916f3e..855bb1675c5 100644
--- a/library/core/src/mem/maybe_uninit.rs
+++ b/library/core/src/mem/maybe_uninit.rs
@@ -242,7 +242,7 @@ use crate::slice;
 /// the same size, alignment, and ABI as `T`; it's just that the way `MaybeUninit` implements that
 /// guarantee may evolve.
 #[stable(feature = "maybe_uninit", since = "1.36.0")]
-// Lang item so we can wrap other types in it. This is useful for generators.
+// Lang item so we can wrap other types in it. This is useful for coroutines.
 #[lang = "maybe_uninit"]
 #[derive(Copy)]
 #[repr(transparent)]
diff --git a/library/core/src/ops/generator.rs b/library/core/src/ops/coroutine.rs
index f1fe55760ad..4847c052712 100644
--- a/library/core/src/ops/generator.rs
+++ b/library/core/src/ops/coroutine.rs
@@ -1,120 +1,122 @@
 use crate::marker::Unpin;
 use crate::pin::Pin;
 
-/// The result of a generator resumption.
+/// The result of a coroutine resumption.
 ///
 /// This enum is returned from the `Coroutine::resume` method and indicates the
-/// possible return values of a generator. Currently this corresponds to either
+/// possible return values of a coroutine. Currently this corresponds to either
 /// a suspension point (`Yielded`) or a termination point (`Complete`).
 #[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
-#[lang = "generator_state"]
-#[unstable(feature = "generator_trait", issue = "43122")]
+#[cfg_attr(bootstrap, lang = "generator_state")]
+#[cfg_attr(not(bootstrap), lang = "coroutine_state")]
+#[unstable(feature = "coroutine_trait", issue = "43122")]
 pub enum CoroutineState<Y, R> {
-    /// The generator suspended with a value.
+    /// The coroutine suspended with a value.
     ///
-    /// This state indicates that a generator has been suspended, and typically
+    /// This state indicates that a coroutine has been suspended, and typically
     /// corresponds to a `yield` statement. The value provided in this variant
-    /// corresponds to the expression passed to `yield` and allows generators to
+    /// corresponds to the expression passed to `yield` and allows coroutines to
     /// provide a value each time they yield.
     Yielded(Y),
 
-    /// The generator completed with a return value.
+    /// The coroutine completed with a return value.
     ///
-    /// This state indicates that a generator has finished execution with the
-    /// provided value. Once a generator has returned `Complete` it is
+    /// This state indicates that a coroutine has finished execution with the
+    /// provided value. Once a coroutine has returned `Complete` it is
     /// considered a programmer error to call `resume` again.
     Complete(R),
 }
 
-/// The trait implemented by builtin generator types.
+/// The trait implemented by builtin coroutine types.
 ///
 /// Coroutines, also commonly referred to as coroutines, are currently an
-/// experimental language feature in Rust. Added in [RFC 2033] generators are
+/// experimental language feature in Rust. Added in [RFC 2033] coroutines are
 /// currently intended to primarily provide a building block for async/await
 /// syntax but will likely extend to also providing an ergonomic definition for
 /// iterators and other primitives.
 ///
-/// The syntax and semantics for generators is unstable and will require a
+/// The syntax and semantics for coroutines is unstable and will require a
 /// further RFC for stabilization. At this time, though, the syntax is
 /// closure-like:
 ///
 /// ```rust
-/// #![feature(generators, generator_trait)]
+/// #![feature(coroutines, coroutine_trait)]
 ///
 /// use std::ops::{Coroutine, CoroutineState};
 /// use std::pin::Pin;
 ///
 /// fn main() {
-///     let mut generator = || {
+///     let mut coroutine = || {
 ///         yield 1;
 ///         "foo"
 ///     };
 ///
-///     match Pin::new(&mut generator).resume(()) {
+///     match Pin::new(&mut coroutine).resume(()) {
 ///         CoroutineState::Yielded(1) => {}
 ///         _ => panic!("unexpected return from resume"),
 ///     }
-///     match Pin::new(&mut generator).resume(()) {
+///     match Pin::new(&mut coroutine).resume(()) {
 ///         CoroutineState::Complete("foo") => {}
 ///         _ => panic!("unexpected return from resume"),
 ///     }
 /// }
 /// ```
 ///
-/// More documentation of generators can be found in the [unstable book].
+/// More documentation of coroutines can be found in the [unstable book].
 ///
 /// [RFC 2033]: https://github.com/rust-lang/rfcs/pull/2033
-/// [unstable book]: ../../unstable-book/language-features/generators.html
-#[lang = "generator"]
-#[unstable(feature = "generator_trait", issue = "43122")]
+/// [unstable book]: ../../unstable-book/language-features/coroutines.html
+#[cfg_attr(bootstrap, lang = "generator")]
+#[cfg_attr(not(bootstrap), lang = "coroutine")]
+#[unstable(feature = "coroutine_trait", issue = "43122")]
 #[fundamental]
 pub trait Coroutine<R = ()> {
-    /// The type of value this generator yields.
+    /// The type of value this coroutine yields.
     ///
     /// This associated type corresponds to the `yield` expression and the
-    /// values which are allowed to be returned each time a generator yields.
-    /// For example an iterator-as-a-generator would likely have this type as
+    /// values which are allowed to be returned each time a coroutine yields.
+    /// For example an iterator-as-a-coroutine would likely have this type as
     /// `T`, the type being iterated over.
     type Yield;
 
-    /// The type of value this generator returns.
+    /// The type of value this coroutine returns.
     ///
-    /// This corresponds to the type returned from a generator either with a
-    /// `return` statement or implicitly as the last expression of a generator
+    /// This corresponds to the type returned from a coroutine either with a
+    /// `return` statement or implicitly as the last expression of a coroutine
     /// literal. For example futures would use this as `Result<T, E>` as it
     /// represents a completed future.
     type Return;
 
-    /// Resumes the execution of this generator.
+    /// Resumes the execution of this coroutine.
     ///
-    /// This function will resume execution of the generator or start execution
-    /// if it hasn't already. This call will return back into the generator's
+    /// This function will resume execution of the coroutine or start execution
+    /// if it hasn't already. This call will return back into the coroutine's
     /// last suspension point, resuming execution from the latest `yield`. The
-    /// generator will continue executing until it either yields or returns, at
+    /// coroutine will continue executing until it either yields or returns, at
     /// which point this function will return.
     ///
     /// # Return value
     ///
     /// The `CoroutineState` enum returned from this function indicates what
-    /// state the generator is in upon returning. If the `Yielded` variant is
-    /// returned then the generator has reached a suspension point and a value
+    /// state the coroutine is in upon returning. If the `Yielded` variant is
+    /// returned then the coroutine has reached a suspension point and a value
     /// has been yielded out. Coroutines in this state are available for
     /// resumption at a later point.
     ///
-    /// If `Complete` is returned then the generator has completely finished
-    /// with the value provided. It is invalid for the generator to be resumed
+    /// If `Complete` is returned then the coroutine has completely finished
+    /// with the value provided. It is invalid for the coroutine to be resumed
     /// again.
     ///
     /// # Panics
     ///
     /// This function may panic if it is called after the `Complete` variant has
-    /// been returned previously. While generator literals in the language are
+    /// been returned previously. While coroutine literals in the language are
     /// guaranteed to panic on resuming after `Complete`, this is not guaranteed
     /// for all implementations of the `Coroutine` trait.
     fn resume(self: Pin<&mut Self>, arg: R) -> CoroutineState<Self::Yield, Self::Return>;
 }
 
-#[unstable(feature = "generator_trait", issue = "43122")]
+#[unstable(feature = "coroutine_trait", issue = "43122")]
 impl<G: ?Sized + Coroutine<R>, R> Coroutine<R> for Pin<&mut G> {
     type Yield = G::Yield;
     type Return = G::Return;
@@ -124,7 +126,7 @@ impl<G: ?Sized + Coroutine<R>, R> Coroutine<R> for Pin<&mut G> {
     }
 }
 
-#[unstable(feature = "generator_trait", issue = "43122")]
+#[unstable(feature = "coroutine_trait", issue = "43122")]
 impl<G: ?Sized + Coroutine<R> + Unpin, R> Coroutine<R> for &mut G {
     type Yield = G::Yield;
     type Return = G::Return;
diff --git a/library/core/src/ops/mod.rs b/library/core/src/ops/mod.rs
index eb972e9f6c5..fd8271b1344 100644
--- a/library/core/src/ops/mod.rs
+++ b/library/core/src/ops/mod.rs
@@ -141,10 +141,10 @@
 mod arith;
 mod bit;
 mod control_flow;
+mod coroutine;
 mod deref;
 mod drop;
 mod function;
-mod generator;
 mod index;
 mod index_range;
 mod range;
@@ -198,8 +198,8 @@ pub use self::try_trait::Residual;
 
 pub(crate) use self::try_trait::{ChangeOutputType, NeverShortCircuit};
 
-#[unstable(feature = "generator_trait", issue = "43122")]
-pub use self::generator::{Coroutine, CoroutineState};
+#[unstable(feature = "coroutine_trait", issue = "43122")]
+pub use self::coroutine::{Coroutine, CoroutineState};
 
 #[unstable(feature = "coerce_unsized", issue = "18598")]
 pub use self::unsize::CoerceUnsized;
diff --git a/library/core/src/pin.rs b/library/core/src/pin.rs
index 14344e3890b..322b455841b 100644
--- a/library/core/src/pin.rs
+++ b/library/core/src/pin.rs
@@ -1088,14 +1088,14 @@ impl<P, U> DispatchFromDyn<Pin<U>> for Pin<P> where P: DispatchFromDyn<U> {}
 /// ### With `Coroutine`s
 ///
 /// ```rust
-/// #![feature(generators, generator_trait)]
+/// #![feature(coroutines, coroutine_trait)]
 /// use core::{
 ///     ops::{Coroutine, CoroutineState},
 ///     pin::pin,
 /// };
 ///
-/// fn generator_fn() -> impl Coroutine<Yield = usize, Return = ()> /* not Unpin */ {
-///  // Allow generator to be self-referential (not `Unpin`)
+/// fn coroutine_fn() -> impl Coroutine<Yield = usize, Return = ()> /* not Unpin */ {
+///  // Allow coroutine to be self-referential (not `Unpin`)
 ///  // vvvvvv        so that locals can cross yield points.
 ///     static || {
 ///         let foo = String::from("foo");
@@ -1107,16 +1107,16 @@ impl<P, U> DispatchFromDyn<Pin<U>> for Pin<P> where P: DispatchFromDyn<U> {}
 /// }
 ///
 /// fn main() {
-///     let mut generator = pin!(generator_fn());
-///     match generator.as_mut().resume(()) {
+///     let mut coroutine = pin!(coroutine_fn());
+///     match coroutine.as_mut().resume(()) {
 ///         CoroutineState::Yielded(0) => {},
 ///         _ => unreachable!(),
 ///     }
-///     match generator.as_mut().resume(()) {
+///     match coroutine.as_mut().resume(()) {
 ///         CoroutineState::Yielded(3) => {},
 ///         _ => unreachable!(),
 ///     }
-///     match generator.resume(()) {
+///     match coroutine.resume(()) {
 ///         CoroutineState::Yielded(_) => unreachable!(),
 ///         CoroutineState::Complete(()) => {},
 ///     }
diff --git a/library/core/src/sync/exclusive.rs b/library/core/src/sync/exclusive.rs
index 5aa45610197..fa02dd52e00 100644
--- a/library/core/src/sync/exclusive.rs
+++ b/library/core/src/sync/exclusive.rs
@@ -206,7 +206,7 @@ where
     }
 }
 
-#[unstable(feature = "generator_trait", issue = "43122")] // also #98407
+#[unstable(feature = "coroutine_trait", issue = "43122")] // also #98407
 impl<R, G> Coroutine<R> for Exclusive<G>
 where
     G: Coroutine<R> + ?Sized,