diff options
Diffstat (limited to 'tests/ui/recursion')
| -rw-r--r-- | tests/ui/recursion/recursion-tail-call-no-arg-leak.rs | 15 | ||||
| -rw-r--r-- | tests/ui/recursion/recursion-tail-cps.rs | 34 |
2 files changed, 49 insertions, 0 deletions
diff --git a/tests/ui/recursion/recursion-tail-call-no-arg-leak.rs b/tests/ui/recursion/recursion-tail-call-no-arg-leak.rs new file mode 100644 index 00000000000..fe10b890700 --- /dev/null +++ b/tests/ui/recursion/recursion-tail-call-no-arg-leak.rs @@ -0,0 +1,15 @@ +//! This test verifies that tail call optimization does not lead to argument slot leaks. +//! +//! Regression test for: <https://github.com/rust-lang/rust/issues/160> + +//@ run-pass + +fn inner(dummy: String, b: bool) { + if b { + return inner(dummy, false); + } +} + +pub fn main() { + inner("hi".to_string(), true); +} 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); + } +} |
