mirror of https://github.com/rust-lang/rust.git
Add tests for uninhabited types
This commit is contained in:
parent
5a440f1bc2
commit
d415fae8b7
|
@ -1,3 +1,5 @@
|
||||||
|
#![feature(never_type)]
|
||||||
|
|
||||||
fn loop_break_return() -> i32 {
|
fn loop_break_return() -> i32 {
|
||||||
let loop_value = loop { break return 0 }; // ok
|
let loop_value = loop { break return 0 }; // ok
|
||||||
}
|
}
|
||||||
|
@ -10,4 +12,27 @@ fn loop_break_break() -> i32 { //~ ERROR mismatched types
|
||||||
let loop_value = loop { break break };
|
let loop_value = loop { break break };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn loop_break_return_2() -> i32 { //~ ERROR mismatched types
|
||||||
|
let loop_value = loop { break { return; () } };
|
||||||
|
//~^ ERROR `return;` in a function whose return type is not `()`
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Void {}
|
||||||
|
|
||||||
|
fn get_void() -> Void {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn loop_break_void() -> i32 { //~ ERROR mismatched types
|
||||||
|
let loop_value = loop { break get_void() };
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_never() -> ! {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn loop_break_never() -> i32 {
|
||||||
|
let loop_value = loop { break get_never() }; // ok
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,11 +1,34 @@
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/break-diverging-value.rs:9:26
|
--> $DIR/break-diverging-value.rs:11:26
|
||||||
|
|
|
|
||||||
LL | fn loop_break_break() -> i32 {
|
LL | fn loop_break_break() -> i32 {
|
||||||
| ---------------- ^^^ expected `i32`, found `()`
|
| ---------------- ^^^ expected `i32`, found `()`
|
||||||
| |
|
| |
|
||||||
| implicitly returns `()` as its body has no tail or `return` expression
|
| implicitly returns `()` as its body has no tail or `return` expression
|
||||||
|
|
||||||
error: aborting due to previous error
|
error[E0069]: `return;` in a function whose return type is not `()`
|
||||||
|
--> $DIR/break-diverging-value.rs:16:37
|
||||||
|
|
|
||||||
|
LL | let loop_value = loop { break { return; () } };
|
||||||
|
| ^^^^^^ return type is not `()`
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0308`.
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/break-diverging-value.rs:15:29
|
||||||
|
|
|
||||||
|
LL | fn loop_break_return_2() -> i32 {
|
||||||
|
| ------------------- ^^^ expected `i32`, found `()`
|
||||||
|
| |
|
||||||
|
| implicitly returns `()` as its body has no tail or `return` expression
|
||||||
|
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/break-diverging-value.rs:26:25
|
||||||
|
|
|
||||||
|
LL | fn loop_break_void() -> i32 {
|
||||||
|
| --------------- ^^^ expected `i32`, found `()`
|
||||||
|
| |
|
||||||
|
| implicitly returns `()` as its body has no tail or `return` expression
|
||||||
|
|
||||||
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
Some errors have detailed explanations: E0069, E0308.
|
||||||
|
For more information about an error, try `rustc --explain E0069`.
|
||||||
|
|
Loading…
Reference in New Issue