Skip to content

Commit

Permalink
Rollup merge of #96719 - mbartlett21:patch-4, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Fix the generator example for `pin!()`

The previous generator example is not actually self-referential, since the reference is created after the yield.

CC #93178 (tracking issue)
  • Loading branch information
Dylan-DPC authored Jun 20, 2022
2 parents 7372bf8 + 6d523e9 commit 625c929
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions library/core/src/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,9 +1006,10 @@ impl<P, U> DispatchFromDyn<Pin<U>> for Pin<P> where P: DispatchFromDyn<U> {}
/// // Allow generator to be self-referential (not `Unpin`)
/// // vvvvvv so that locals can cross yield points.
/// static || {
/// let foo = String::from("foo"); // --+
/// yield 0; // | <- crosses yield point!
/// println!("{}", &foo); // <----------+
/// let foo = String::from("foo");
/// let foo_ref = &foo; // ------+
/// yield 0; // | <- crosses yield point!
/// println!("{foo_ref}"); // <--+
/// yield foo.len();
/// }
/// }
Expand Down

0 comments on commit 625c929

Please sign in to comment.