about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTaylor Cramer <cramertaylorj@gmail.com>2017-02-16 20:24:18 -0800
committerTaylor Cramer <cramertaylorj@gmail.com>2017-02-18 12:43:25 -0800
commit56e519dd5c8df832dfb78a180ac771de3649b12f (patch)
treed8fb976350685918cb0b1148bd5a060687741df8
parent4d65622dcd3be66ec53656c499afe7bbc8aa1ae7 (diff)
downloadrust-56e519dd5c8df832dfb78a180ac771de3649b12f.tar.gz
rust-56e519dd5c8df832dfb78a180ac771de3649b12f.zip
Add tests for control flow in while condition
-rw-r--r--src/test/compile-fail/issue-37576.rs55
-rw-r--r--src/test/compile-fail/resolve-label.rs3
-rw-r--r--src/test/run-make/graphviz-flowgraph/f10.dot-expected.dot16
-rw-r--r--src/test/run-make/graphviz-flowgraph/f23.dot-expected.dot48
4 files changed, 88 insertions, 34 deletions
diff --git a/src/test/compile-fail/issue-37576.rs b/src/test/compile-fail/issue-37576.rs
new file mode 100644
index 00000000000..e3c1ada878d
--- /dev/null
+++ b/src/test/compile-fail/issue-37576.rs
@@ -0,0 +1,55 @@
+// Copyright 2012 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 main() {
+    'test_1: while break 'test_1 {}
+    while break {}
+    //~^ ERROR `break` or `continue` with no label
+
+    'test_2: while let true = break 'test_2 {}
+    while let true = break {}
+    //~^ ERROR `break` or `continue` with no label
+
+    loop { 'test_3: while break 'test_3 {} }
+    loop { while break {} }
+    //~^ ERROR `break` or `continue` with no label
+
+    loop {
+        'test_4: while break 'test_4 {}
+        break;
+    }
+    loop {
+        while break {}
+        //~^ ERROR `break` or `continue` with no label
+        break;
+    }
+
+    'test_5: while continue 'test_5 {}
+    while continue {}
+    //~^ ERROR `break` or `continue` with no label
+
+    'test_6: while let true = continue 'test_6 {}
+    while let true = continue {}
+    //~^ ERROR `break` or `continue` with no label
+
+    loop { 'test_7: while continue 'test_7 {} }
+    loop { while continue {} }
+    //~^ ERROR `break` or `continue` with no label
+
+    loop {
+        'test_8: while continue 'test_8 {}
+        continue;
+    }
+    loop {
+        while continue {}
+        //~^ ERROR `break` or `continue` with no label
+        continue;
+    }
+}
diff --git a/src/test/compile-fail/resolve-label.rs b/src/test/compile-fail/resolve-label.rs
index ed2c3e0e9b8..6695e972f33 100644
--- a/src/test/compile-fail/resolve-label.rs
+++ b/src/test/compile-fail/resolve-label.rs
@@ -17,8 +17,7 @@ fn f() {
         }
     }
 
-    // issue #37353
-    loop { 'w: while break 'w { } } //~ ERROR use of undeclared label
+    loop { 'w: while break 'w { } }
 }
 
 fn main() {}
diff --git a/src/test/run-make/graphviz-flowgraph/f10.dot-expected.dot b/src/test/run-make/graphviz-flowgraph/f10.dot-expected.dot
index a3b531b1e2f..07b9c744a71 100644
--- a/src/test/run-make/graphviz-flowgraph/f10.dot-expected.dot
+++ b/src/test/run-make/graphviz-flowgraph/f10.dot-expected.dot
@@ -5,10 +5,10 @@ digraph block {
     N3[label="local mut x"];
     N4[label="stmt let mut x = 10;"];
     N5[label="(dummy_node)"];
-    N6[label="expr x"];
-    N7[label="expr 0"];
-    N8[label="expr x > 0"];
-    N9[label="expr while x > 0 { x -= 1; }"];
+    N6[label="expr while x > 0 { x -= 1; }"];
+    N7[label="expr x"];
+    N8[label="expr 0"];
+    N9[label="expr x > 0"];
     N10[label="expr 1"];
     N11[label="expr x"];
     N12[label="expr x -= 1"];
@@ -20,17 +20,17 @@ digraph block {
     N2 -> N3;
     N3 -> N4;
     N4 -> N5;
-    N5 -> N6;
-    N6 -> N7;
+    N5 -> N7;
     N7 -> N8;
     N8 -> N9;
-    N8 -> N10;
+    N9 -> N6;
+    N9 -> N10;
     N10 -> N11;
     N11 -> N12;
     N12 -> N13;
     N13 -> N14;
     N14 -> N5;
-    N9 -> N15;
+    N6 -> N15;
     N15 -> N16;
     N16 -> N1;
 }
diff --git a/src/test/run-make/graphviz-flowgraph/f23.dot-expected.dot b/src/test/run-make/graphviz-flowgraph/f23.dot-expected.dot
index f152977438c..c8bfcd6510b 100644
--- a/src/test/run-make/graphviz-flowgraph/f23.dot-expected.dot
+++ b/src/test/run-make/graphviz-flowgraph/f23.dot-expected.dot
@@ -11,28 +11,28 @@ digraph block {
     N9[label="local mut z"];
     N10[label="stmt let mut z = 23;"];
     N11[label="(dummy_node)"];
-    N12[label="expr x"];
-    N13[label="expr 0"];
-    N14[label="expr x > 0"];
-    N15[label="expr while x > 0 {\l    x -= 1;\l    while y > 0 {\l        y -= 1;\l        while z > 0 { z -= 1; }\l        if x > 10 { return; \"unreachable\"; }\l    }\l}\l"];
+    N12[label="expr while x > 0 {\l    x -= 1;\l    while y > 0 {\l        y -= 1;\l        while z > 0 { z -= 1; }\l        if x > 10 { return; \"unreachable\"; }\l    }\l}\l"];
+    N13[label="expr x"];
+    N14[label="expr 0"];
+    N15[label="expr x > 0"];
     N16[label="expr 1"];
     N17[label="expr x"];
     N18[label="expr x -= 1"];
     N19[label="stmt x -= 1;"];
     N20[label="(dummy_node)"];
-    N21[label="expr y"];
-    N22[label="expr 0"];
-    N23[label="expr y > 0"];
-    N24[label="expr while y > 0 {\l    y -= 1;\l    while z > 0 { z -= 1; }\l    if x > 10 { return; \"unreachable\"; }\l}\l"];
+    N21[label="expr while y > 0 {\l    y -= 1;\l    while z > 0 { z -= 1; }\l    if x > 10 { return; \"unreachable\"; }\l}\l"];
+    N22[label="expr y"];
+    N23[label="expr 0"];
+    N24[label="expr y > 0"];
     N25[label="expr 1"];
     N26[label="expr y"];
     N27[label="expr y -= 1"];
     N28[label="stmt y -= 1;"];
     N29[label="(dummy_node)"];
-    N30[label="expr z"];
-    N31[label="expr 0"];
-    N32[label="expr z > 0"];
-    N33[label="expr while z > 0 { z -= 1; }"];
+    N30[label="expr while z > 0 { z -= 1; }"];
+    N31[label="expr z"];
+    N32[label="expr 0"];
+    N33[label="expr z > 0"];
     N34[label="expr 1"];
     N35[label="expr z"];
     N36[label="expr z -= 1"];
@@ -63,35 +63,35 @@ digraph block {
     N8 -> N9;
     N9 -> N10;
     N10 -> N11;
-    N11 -> N12;
-    N12 -> N13;
+    N11 -> N13;
     N13 -> N14;
     N14 -> N15;
-    N14 -> N16;
+    N15 -> N12;
+    N15 -> N16;
     N16 -> N17;
     N17 -> N18;
     N18 -> N19;
     N19 -> N20;
-    N20 -> N21;
-    N21 -> N22;
+    N20 -> N22;
     N22 -> N23;
     N23 -> N24;
-    N23 -> N25;
+    N24 -> N21;
+    N24 -> N25;
     N25 -> N26;
     N26 -> N27;
     N27 -> N28;
     N28 -> N29;
-    N29 -> N30;
-    N30 -> N31;
+    N29 -> N31;
     N31 -> N32;
     N32 -> N33;
-    N32 -> N34;
+    N33 -> N30;
+    N33 -> N34;
     N34 -> N35;
     N35 -> N36;
     N36 -> N37;
     N37 -> N38;
     N38 -> N29;
-    N33 -> N39;
+    N30 -> N39;
     N39 -> N40;
     N40 -> N41;
     N41 -> N42;
@@ -105,9 +105,9 @@ digraph block {
     N48 -> N49;
     N49 -> N50;
     N50 -> N20;
-    N24 -> N51;
+    N21 -> N51;
     N51 -> N11;
-    N15 -> N52;
+    N12 -> N52;
     N52 -> N53;
     N53 -> N1;
 }