about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-01-20 22:03:33 +0000
committerbors <bors@rust-lang.org>2016-01-20 22:03:33 +0000
commit4bb9d453cf9640b08d97543cd5ed9ded52fd757f (patch)
tree2e2212a267eac77105bb5f5112383c05803fffe4 /src/test
parent0b77e50b41f03651abaa1f7ebf47c0d244bfdefd (diff)
parent8877cca190b4ddf3386092fa3bb84431b9d6cabd (diff)
downloadrust-4bb9d453cf9640b08d97543cd5ed9ded52fd757f.tar.gz
rust-4bb9d453cf9640b08d97543cd5ed9ded52fd757f.zip
Auto merge of #30945 - nagisa:mir-optional-block-dest, r=nikomatsakis
As an attempt to make loop body destination be optional, author implemented a pretty self contained
change and deemed it to be (much) uglier than the alternative of just keeping the unit temporary.
Having the temporary created lazily also has a nice property of not figuring in the MIR of
functions which do not use loops of any sort.

r? @nikomatsakis
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/loop-does-not-diverge.rs1
-rw-r--r--src/test/compile-fail/loop-proper-liveness.rs42
-rw-r--r--src/test/compile-fail/loop-properly-diverging-2.rs16
-rw-r--r--src/test/compile-fail/loop-properly-diverging.rs15
4 files changed, 73 insertions, 1 deletions
diff --git a/src/test/compile-fail/loop-does-not-diverge.rs b/src/test/compile-fail/loop-does-not-diverge.rs
index cd320ba148a..451b30629b6 100644
--- a/src/test/compile-fail/loop-does-not-diverge.rs
+++ b/src/test/compile-fail/loop-does-not-diverge.rs
@@ -18,5 +18,4 @@ fn forever() -> ! {
 }
 
 fn main() {
-  if 1 == 2 { forever(); }
 }
diff --git a/src/test/compile-fail/loop-proper-liveness.rs b/src/test/compile-fail/loop-proper-liveness.rs
new file mode 100644
index 00000000000..e411313c273
--- /dev/null
+++ b/src/test/compile-fail/loop-proper-liveness.rs
@@ -0,0 +1,42 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn test1() {
+    // In this test the outer 'a loop may terminate without `x` getting initialised. Although the
+    // `x = loop { ... }` statement is reached, the value itself ends up never being computed and
+    // thus leaving `x` uninit.
+    let x: i32;
+    'a: loop {
+        x = loop { break 'a };
+    }
+    println!("{:?}", x); //~ ERROR use of possibly uninitialized variable
+}
+
+// test2 and test3 should not fail.
+fn test2() {
+    // In this test the `'a` loop will never terminate thus making the use of `x` unreachable.
+    let x: i32;
+    'a: loop {
+        x = loop { continue 'a };
+    }
+    println!("{:?}", x);
+}
+
+fn test3() {
+    let x: i32;
+    // Similarly, the use of variable `x` is unreachable.
+    'a: loop {
+        x = loop { return };
+    }
+    println!("{:?}", x);
+}
+
+fn main() {
+}
diff --git a/src/test/compile-fail/loop-properly-diverging-2.rs b/src/test/compile-fail/loop-properly-diverging-2.rs
new file mode 100644
index 00000000000..c22091ce63c
--- /dev/null
+++ b/src/test/compile-fail/loop-properly-diverging-2.rs
@@ -0,0 +1,16 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn forever2() -> i32 {
+  let x: i32 = loop { break }; //~ ERROR mismatched types
+  x
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/loop-properly-diverging.rs b/src/test/compile-fail/loop-properly-diverging.rs
new file mode 100644
index 00000000000..01dfbcc1b9e
--- /dev/null
+++ b/src/test/compile-fail/loop-properly-diverging.rs
@@ -0,0 +1,15 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn forever2() -> ! { //~ ERROR computation may converge in a function marked as diverging
+  loop { break }
+}
+
+fn main() {}