Rollup merge of #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 #93178 (tracking issue)
This commit is contained in:
Dylan DPC 2022-06-20 14:56:36 +02:00 committed by GitHub
commit 625c929a9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 3 deletions

View File

@ -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`) /// // Allow generator to be self-referential (not `Unpin`)
/// // vvvvvv so that locals can cross yield points. /// // vvvvvv so that locals can cross yield points.
/// static || { /// static || {
/// let foo = String::from("foo"); // --+ /// let foo = String::from("foo");
/// yield 0; // | <- crosses yield point! /// let foo_ref = &foo; // ------+
/// println!("{}", &foo); // <----------+ /// yield 0; // | <- crosses yield point!
/// println!("{foo_ref}"); // <--+
/// yield foo.len(); /// yield foo.len();
/// } /// }
/// } /// }