Skip to content

Commit 56e519d

Browse files
committed
Add tests for control flow in while condition
1 parent 4d65622 commit 56e519d

File tree

4 files changed

+88
-34
lines changed

4 files changed

+88
-34
lines changed

src/test/compile-fail/issue-37576.rs

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
'test_1: while break 'test_1 {}
13+
while break {}
14+
//~^ ERROR `break` or `continue` with no label
15+
16+
'test_2: while let true = break 'test_2 {}
17+
while let true = break {}
18+
//~^ ERROR `break` or `continue` with no label
19+
20+
loop { 'test_3: while break 'test_3 {} }
21+
loop { while break {} }
22+
//~^ ERROR `break` or `continue` with no label
23+
24+
loop {
25+
'test_4: while break 'test_4 {}
26+
break;
27+
}
28+
loop {
29+
while break {}
30+
//~^ ERROR `break` or `continue` with no label
31+
break;
32+
}
33+
34+
'test_5: while continue 'test_5 {}
35+
while continue {}
36+
//~^ ERROR `break` or `continue` with no label
37+
38+
'test_6: while let true = continue 'test_6 {}
39+
while let true = continue {}
40+
//~^ ERROR `break` or `continue` with no label
41+
42+
loop { 'test_7: while continue 'test_7 {} }
43+
loop { while continue {} }
44+
//~^ ERROR `break` or `continue` with no label
45+
46+
loop {
47+
'test_8: while continue 'test_8 {}
48+
continue;
49+
}
50+
loop {
51+
while continue {}
52+
//~^ ERROR `break` or `continue` with no label
53+
continue;
54+
}
55+
}

src/test/compile-fail/resolve-label.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ fn f() {
1717
}
1818
}
1919

20-
// issue #37353
21-
loop { 'w: while break 'w { } } //~ ERROR use of undeclared label
20+
loop { 'w: while break 'w { } }
2221
}
2322

2423
fn main() {}

src/test/run-make/graphviz-flowgraph/f10.dot-expected.dot

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ digraph block {
55
N3[label="local mut x"];
66
N4[label="stmt let mut x = 10;"];
77
N5[label="(dummy_node)"];
8-
N6[label="expr x"];
9-
N7[label="expr 0"];
10-
N8[label="expr x > 0"];
11-
N9[label="expr while x > 0 { x -= 1; }"];
8+
N6[label="expr while x > 0 { x -= 1; }"];
9+
N7[label="expr x"];
10+
N8[label="expr 0"];
11+
N9[label="expr x > 0"];
1212
N10[label="expr 1"];
1313
N11[label="expr x"];
1414
N12[label="expr x -= 1"];
@@ -20,17 +20,17 @@ digraph block {
2020
N2 -> N3;
2121
N3 -> N4;
2222
N4 -> N5;
23-
N5 -> N6;
24-
N6 -> N7;
23+
N5 -> N7;
2524
N7 -> N8;
2625
N8 -> N9;
27-
N8 -> N10;
26+
N9 -> N6;
27+
N9 -> N10;
2828
N10 -> N11;
2929
N11 -> N12;
3030
N12 -> N13;
3131
N13 -> N14;
3232
N14 -> N5;
33-
N9 -> N15;
33+
N6 -> N15;
3434
N15 -> N16;
3535
N16 -> N1;
3636
}

src/test/run-make/graphviz-flowgraph/f23.dot-expected.dot

+24-24
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,28 @@ digraph block {
1111
N9[label="local mut z"];
1212
N10[label="stmt let mut z = 23;"];
1313
N11[label="(dummy_node)"];
14-
N12[label="expr x"];
15-
N13[label="expr 0"];
16-
N14[label="expr x > 0"];
17-
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"];
14+
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"];
15+
N13[label="expr x"];
16+
N14[label="expr 0"];
17+
N15[label="expr x > 0"];
1818
N16[label="expr 1"];
1919
N17[label="expr x"];
2020
N18[label="expr x -= 1"];
2121
N19[label="stmt x -= 1;"];
2222
N20[label="(dummy_node)"];
23-
N21[label="expr y"];
24-
N22[label="expr 0"];
25-
N23[label="expr y > 0"];
26-
N24[label="expr while y > 0 {\l y -= 1;\l while z > 0 { z -= 1; }\l if x > 10 { return; \"unreachable\"; }\l}\l"];
23+
N21[label="expr while y > 0 {\l y -= 1;\l while z > 0 { z -= 1; }\l if x > 10 { return; \"unreachable\"; }\l}\l"];
24+
N22[label="expr y"];
25+
N23[label="expr 0"];
26+
N24[label="expr y > 0"];
2727
N25[label="expr 1"];
2828
N26[label="expr y"];
2929
N27[label="expr y -= 1"];
3030
N28[label="stmt y -= 1;"];
3131
N29[label="(dummy_node)"];
32-
N30[label="expr z"];
33-
N31[label="expr 0"];
34-
N32[label="expr z > 0"];
35-
N33[label="expr while z > 0 { z -= 1; }"];
32+
N30[label="expr while z > 0 { z -= 1; }"];
33+
N31[label="expr z"];
34+
N32[label="expr 0"];
35+
N33[label="expr z > 0"];
3636
N34[label="expr 1"];
3737
N35[label="expr z"];
3838
N36[label="expr z -= 1"];
@@ -63,35 +63,35 @@ digraph block {
6363
N8 -> N9;
6464
N9 -> N10;
6565
N10 -> N11;
66-
N11 -> N12;
67-
N12 -> N13;
66+
N11 -> N13;
6867
N13 -> N14;
6968
N14 -> N15;
70-
N14 -> N16;
69+
N15 -> N12;
70+
N15 -> N16;
7171
N16 -> N17;
7272
N17 -> N18;
7373
N18 -> N19;
7474
N19 -> N20;
75-
N20 -> N21;
76-
N21 -> N22;
75+
N20 -> N22;
7776
N22 -> N23;
7877
N23 -> N24;
79-
N23 -> N25;
78+
N24 -> N21;
79+
N24 -> N25;
8080
N25 -> N26;
8181
N26 -> N27;
8282
N27 -> N28;
8383
N28 -> N29;
84-
N29 -> N30;
85-
N30 -> N31;
84+
N29 -> N31;
8685
N31 -> N32;
8786
N32 -> N33;
88-
N32 -> N34;
87+
N33 -> N30;
88+
N33 -> N34;
8989
N34 -> N35;
9090
N35 -> N36;
9191
N36 -> N37;
9292
N37 -> N38;
9393
N38 -> N29;
94-
N33 -> N39;
94+
N30 -> N39;
9595
N39 -> N40;
9696
N40 -> N41;
9797
N41 -> N42;
@@ -105,9 +105,9 @@ digraph block {
105105
N48 -> N49;
106106
N49 -> N50;
107107
N50 -> N20;
108-
N24 -> N51;
108+
N21 -> N51;
109109
N51 -> N11;
110-
N15 -> N52;
110+
N12 -> N52;
111111
N52 -> N53;
112112
N53 -> N1;
113113
}

0 commit comments

Comments
 (0)