about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-06-20 14:56:36 +0200
committerGitHub <noreply@github.com>2022-06-20 14:56:36 +0200
commit625c929a9fecc7fbaf7142faaab787ba8125a62f (patch)
treedebb10ee57f2166e2655a2821fa12939775d0e17
parent7372bf88ee17088023590f73fee380db97ee68e0 (diff)
parent6d523e9a75fe55eae708d6e606a492f9c891af34 (diff)
downloadrust-625c929a9fecc7fbaf7142faaab787ba8125a62f.tar.gz
rust-625c929a9fecc7fbaf7142faaab787ba8125a62f.zip
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)
-rw-r--r--library/core/src/pin.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/library/core/src/pin.rs b/library/core/src/pin.rs
index 720317b05e0..ccef35b4532 100644
--- a/library/core/src/pin.rs
+++ b/library/core/src/pin.rs
@@ -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();
 ///     }
 /// }