Add a test for returning inside a while loop
This commit is contained in:
parent
a38a1ce29c
commit
03d816fd93
2 changed files with 60 additions and 10 deletions
|
@ -11,7 +11,29 @@
|
|||
#![feature(never_type)]
|
||||
|
||||
fn main() {
|
||||
// The `if false` expressions are simply to
|
||||
// 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
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,43 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/break-while-condition.rs:14:16
|
||||
--> $DIR/break-while-condition.rs:19:20
|
||||
|
|
||||
LL | let _: ! = { //~ ERROR mismatched types
|
||||
| ________________^
|
||||
| ____________________^
|
||||
LL | | 'a: while break 'a {};
|
||||
LL | | };
|
||||
| |_____^ expected !, found ()
|
||||
| |_________^ expected !, found ()
|
||||
|
|
||||
= note: expected 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`.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue