about summary refs log tree commit diff
path: root/tests/ui/recursion/recursion-tail-cps.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-07-13 15:32:13 +0000
committerbors <bors@rust-lang.org>2025-07-13 15:32:13 +0000
commit56835d7ac14da9f966e1ff39fd9ffd2e29b764d1 (patch)
tree74bf7603a760a610352e6f0fa88668b71cb6d8a2 /tests/ui/recursion/recursion-tail-cps.rs
parent7e310f4b9a3f166d833ed09cf1d1ff96ab84b72c (diff)
parent3ff549f6d33ac15df8307025ee068cada8b1e021 (diff)
downloadrust-56835d7ac14da9f966e1ff39fd9ffd2e29b764d1.tar.gz
rust-56835d7ac14da9f966e1ff39fd9ffd2e29b764d1.zip
Auto merge of #143888 - matthiaskrgr:rollup-fv9x7kf, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#143301 (`tests/ui`: A New Order [26/N])
 - rust-lang/rust#143519 (Check assoc consts and tys later like assoc fns)
 - rust-lang/rust#143554 (slice: Mark `rotate_left`, `rotate_right` unstably const)
 - rust-lang/rust#143634 (interpret/allocation: expose init + write_wildcards on a range)
 - rust-lang/rust#143685 (Resolve: merge `source_bindings` and `target_bindings` into `bindings`)
 - rust-lang/rust#143734 (Refactor resolve resolution bindings)
 - rust-lang/rust#143774 (constify `From` and `Into`)
 - rust-lang/rust#143785 (Add --compile-time-deps argument for x check)
 - rust-lang/rust#143786 (Fix fallback for CI_JOB_NAME)
 - rust-lang/rust#143825 (clippy: fix test filtering when TESTNAME is empty)
 - rust-lang/rust#143826 (Fix command trace)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'tests/ui/recursion/recursion-tail-cps.rs')
-rw-r--r--tests/ui/recursion/recursion-tail-cps.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/ui/recursion/recursion-tail-cps.rs b/tests/ui/recursion/recursion-tail-cps.rs
new file mode 100644
index 00000000000..9014be0ce98
--- /dev/null
+++ b/tests/ui/recursion/recursion-tail-cps.rs
@@ -0,0 +1,34 @@
+//! Verify that mutually recursive functions use CPS to avoid overflowing the stack.
+
+//@ run-pass
+
+fn checktrue(rs: bool) -> bool {
+    assert!(rs);
+    return true;
+}
+
+pub fn main() {
+    let k = checktrue;
+    evenk(42, k);
+    oddk(45, k);
+}
+
+fn evenk(n: isize, k: fn(bool) -> bool) -> bool {
+    println!("evenk");
+    println!("{}", n);
+    if n == 0 {
+        return k(true);
+    } else {
+        return oddk(n - 1, k);
+    }
+}
+
+fn oddk(n: isize, k: fn(bool) -> bool) -> bool {
+    println!("oddk");
+    println!("{}", n);
+    if n == 0 {
+        return k(false);
+    } else {
+        return evenk(n - 1, k);
+    }
+}