From 813c41362b3588ab336b57ac6e2f1e0eb3f305e2 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Sun, 11 Mar 2012 20:17:27 -0700 Subject: [PATCH] A few tests for infinite loops --- src/test/compile-fail/loop-does-not-diverge.rs | 13 +++++++++++++ src/test/run-pass/loop-diverges.rs | 10 ++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/test/compile-fail/loop-does-not-diverge.rs create mode 100644 src/test/run-pass/loop-diverges.rs diff --git a/src/test/compile-fail/loop-does-not-diverge.rs b/src/test/compile-fail/loop-does-not-diverge.rs new file mode 100644 index 00000000000..3d2d70fbab8 --- /dev/null +++ b/src/test/compile-fail/loop-does-not-diverge.rs @@ -0,0 +1,13 @@ +// error-pattern:some control paths may return +/* Make sure a loop{} with a break in it can't be + the tailexpr in the body of a diverging function */ +fn forever() -> ! { + loop { + break; + } + ret 42; +} + +fn main() { + if (1 == 2) { forever(); } +} \ No newline at end of file diff --git a/src/test/run-pass/loop-diverges.rs b/src/test/run-pass/loop-diverges.rs new file mode 100644 index 00000000000..909a15a17c9 --- /dev/null +++ b/src/test/run-pass/loop-diverges.rs @@ -0,0 +1,10 @@ +/* Make sure a loop{} can be the tailexpr in the body +of a diverging function */ + +fn forever() -> ! { + loop{} +} + +fn main() { + if (1 == 2) { forever(); } +} \ No newline at end of file