Skip to content

Commit 625c929

Browse files
authored
Rollup merge of rust-lang#96719 - mbartlett21:patch-4, r=Dylan-DPC
Fix the generator example for `pin!()` The previous generator example is not actually self-referential, since the reference is created after the yield. CC rust-lang#93178 (tracking issue)
2 parents 7372bf8 + 6d523e9 commit 625c929

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

library/core/src/pin.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1006,9 +1006,10 @@ impl<P, U> DispatchFromDyn<Pin<U>> for Pin<P> where P: DispatchFromDyn<U> {}
10061006
/// // Allow generator to be self-referential (not `Unpin`)
10071007
/// // vvvvvv so that locals can cross yield points.
10081008
/// static || {
1009-
/// let foo = String::from("foo"); // --+
1010-
/// yield 0; // | <- crosses yield point!
1011-
/// println!("{}", &foo); // <----------+
1009+
/// let foo = String::from("foo");
1010+
/// let foo_ref = &foo; // ------+
1011+
/// yield 0; // | <- crosses yield point!
1012+
/// println!("{foo_ref}"); // <--+
10121013
/// yield foo.len();
10131014
/// }
10141015
/// }

0 commit comments

Comments
 (0)