about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorEric Holk <ericholk@microsoft.com>2025-03-12 16:27:52 -0700
committerEric Holk <ericholk@microsoft.com>2025-03-14 12:21:59 -0700
commit1c0916a2b3cd6c595e1c7b69a31d507f7619bb67 (patch)
tree51e37950d5efc1cee3074816313740909128b344 /tests
parentedf65e735cd871d01149131f5d050293a9f1037c (diff)
downloadrust-1c0916a2b3cd6c595e1c7b69a31d507f7619bb67.tar.gz
rust-1c0916a2b3cd6c595e1c7b69a31d507f7619bb67.zip
Preserve yield position during pretty printing
Diffstat (limited to 'tests')
-rw-r--r--tests/pretty/postfix-yield.rs15
-rw-r--r--tests/ui/coroutine/postfix-yield.rs6
2 files changed, 18 insertions, 3 deletions
diff --git a/tests/pretty/postfix-yield.rs b/tests/pretty/postfix-yield.rs
new file mode 100644
index 00000000000..f76e8142ae8
--- /dev/null
+++ b/tests/pretty/postfix-yield.rs
@@ -0,0 +1,15 @@
+// This demonstrates a proposed alternate or additional option of having yield in postfix position.
+//@ edition: 2024
+//@ pp-exact
+
+#![feature(gen_blocks, coroutines, coroutine_trait, yield_expr)]
+
+use std::ops::{Coroutine, CoroutineState};
+use std::pin::pin;
+
+fn main() {
+    let mut gn = gen { yield 1; 2.yield; (1 + 2).yield; };
+
+    let mut coro =
+        pin!(#[coroutine] |_: i32| { let x = 1.yield; (x + 2).yield; });
+}
diff --git a/tests/ui/coroutine/postfix-yield.rs b/tests/ui/coroutine/postfix-yield.rs
index 77b1c2a19d0..ff843138c8c 100644
--- a/tests/ui/coroutine/postfix-yield.rs
+++ b/tests/ui/coroutine/postfix-yield.rs
@@ -9,7 +9,7 @@ use std::ops::{Coroutine, CoroutineState};
 use std::pin::pin;
 
 fn main() {
-    // generators (i.e. yield doesn't return anything useful) 
+    // generators (i.e. yield doesn't return anything useful)
     let mut gn = gen {
         yield 1;
         2.yield;
@@ -23,8 +23,8 @@ fn main() {
     let mut coro = pin!(
         #[coroutine]
         |_: i32| {
-            let x = yield 1;
-            yield x + 2;
+            let x = 1.yield;
+            (x + 2).yield;
         }
     );