Skip to content

Commit 03d816f

Browse files
committed
Add a test for returning inside a while loop
1 parent a38a1ce commit 03d816f

File tree

2 files changed

+60
-10
lines changed

2 files changed

+60
-10
lines changed

src/test/ui/break-while-condition.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,29 @@
1111
#![feature(never_type)]
1212

1313
fn main() {
14-
let _: ! = { //~ ERROR mismatched types
15-
'a: while break 'a {};
16-
};
14+
// The `if false` expressions are simply to
15+
// make sure we don't avoid checking everything
16+
// simply because a few expressions are unreachable.
17+
18+
if false {
19+
let _: ! = { //~ ERROR mismatched types
20+
'a: while break 'a {};
21+
};
22+
}
23+
24+
if false {
25+
let _: ! = { //~ ERROR mismatched types
26+
while false {
27+
break
28+
}
29+
};
30+
}
31+
32+
if false {
33+
let _: ! = { //~ ERROR mismatched types
34+
while false {
35+
return
36+
}
37+
};
38+
}
1739
}
Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,43 @@
11
error[E0308]: mismatched types
2-
--> $DIR/break-while-condition.rs:14:16
2+
--> $DIR/break-while-condition.rs:19:20
33
|
4-
LL | let _: ! = { //~ ERROR mismatched types
5-
| ________________^
6-
LL | | 'a: while break 'a {};
7-
LL | | };
8-
| |_____^ expected !, found ()
4+
LL | let _: ! = { //~ ERROR mismatched types
5+
| ____________________^
6+
LL | | 'a: while break 'a {};
7+
LL | | };
8+
| |_________^ expected !, found ()
99
|
1010
= note: expected type `!`
1111
found type `()`
1212

13-
error: aborting due to previous error
13+
error[E0308]: mismatched types
14+
--> $DIR/break-while-condition.rs:26:13
15+
|
16+
LL | fn main() {
17+
| - expected `()` because of default return type
18+
...
19+
LL | / while false {
20+
LL | | break
21+
LL | | }
22+
| |_____________^ expected !, found ()
23+
|
24+
= note: expected type `!`
25+
found type `()`
26+
27+
error[E0308]: mismatched types
28+
--> $DIR/break-while-condition.rs:34:13
29+
|
30+
LL | fn main() {
31+
| - expected `()` because of default return type
32+
...
33+
LL | / while false {
34+
LL | | return
35+
LL | | }
36+
| |_____________^ expected !, found ()
37+
|
38+
= note: expected type `!`
39+
found type `()`
40+
41+
error: aborting due to 3 previous errors
1442

1543
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)