1
Fork 0

Add a test for returning inside a while loop

This commit is contained in:
varkor 2018-05-25 15:31:13 +01:00
parent a38a1ce29c
commit 03d816fd93
2 changed files with 60 additions and 10 deletions

View file

@ -11,7 +11,29 @@
#![feature(never_type)] #![feature(never_type)]
fn main() { fn main() {
let _: ! = { //~ ERROR mismatched types // The `if false` expressions are simply to
'a: while break 'a {}; // make sure we don't avoid checking everything
}; // simply because a few expressions are unreachable.
if false {
let _: ! = { //~ ERROR mismatched types
'a: while break 'a {};
};
}
if false {
let _: ! = { //~ ERROR mismatched types
while false {
break
}
};
}
if false {
let _: ! = { //~ ERROR mismatched types
while false {
return
}
};
}
} }

View file

@ -1,15 +1,43 @@
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/break-while-condition.rs:14:16 --> $DIR/break-while-condition.rs:19:20
| |
LL | let _: ! = { //~ ERROR mismatched types LL | let _: ! = { //~ ERROR mismatched types
| ________________^ | ____________________^
LL | | 'a: while break 'a {}; LL | | 'a: while break 'a {};
LL | | }; LL | | };
| |_____^ expected !, found () | |_________^ expected !, found ()
| |
= note: expected type `!` = note: expected type `!`
found type `()` found type `()`
error: aborting due to previous error error[E0308]: mismatched types
--> $DIR/break-while-condition.rs:26:13
|
LL | fn main() {
| - expected `()` because of default return type
...
LL | / while false {
LL | | break
LL | | }
| |_____________^ expected !, found ()
|
= note: expected type `!`
found type `()`
error[E0308]: mismatched types
--> $DIR/break-while-condition.rs:34:13
|
LL | fn main() {
| - expected `()` because of default return type
...
LL | / while false {
LL | | return
LL | | }
| |_____________^ expected !, found ()
|
= note: expected type `!`
found type `()`
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0308`. For more information about this error, try `rustc --explain E0308`.