Skip to content

Commit d415fae

Browse files
committed
Add tests for uninhabited types
1 parent 5a440f1 commit d415fae

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

src/test/ui/break-diverging-value.rs

+25
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![feature(never_type)]
2+
13
fn loop_break_return() -> i32 {
24
let loop_value = loop { break return 0 }; // ok
35
}
@@ -10,4 +12,27 @@ fn loop_break_break() -> i32 { //~ ERROR mismatched types
1012
let loop_value = loop { break break };
1113
}
1214

15+
fn loop_break_return_2() -> i32 { //~ ERROR mismatched types
16+
let loop_value = loop { break { return; () } };
17+
//~^ ERROR `return;` in a function whose return type is not `()`
18+
}
19+
20+
enum Void {}
21+
22+
fn get_void() -> Void {
23+
panic!()
24+
}
25+
26+
fn loop_break_void() -> i32 { //~ ERROR mismatched types
27+
let loop_value = loop { break get_void() };
28+
}
29+
30+
fn get_never() -> ! {
31+
panic!()
32+
}
33+
34+
fn loop_break_never() -> i32 {
35+
let loop_value = loop { break get_never() }; // ok
36+
}
37+
1338
fn main() {}
+26-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
11
error[E0308]: mismatched types
2-
--> $DIR/break-diverging-value.rs:9:26
2+
--> $DIR/break-diverging-value.rs:11:26
33
|
44
LL | fn loop_break_break() -> i32 {
55
| ---------------- ^^^ expected `i32`, found `()`
66
| |
77
| implicitly returns `()` as its body has no tail or `return` expression
88

9-
error: aborting due to previous error
9+
error[E0069]: `return;` in a function whose return type is not `()`
10+
--> $DIR/break-diverging-value.rs:16:37
11+
|
12+
LL | let loop_value = loop { break { return; () } };
13+
| ^^^^^^ return type is not `()`
14+
15+
error[E0308]: mismatched types
16+
--> $DIR/break-diverging-value.rs:15:29
17+
|
18+
LL | fn loop_break_return_2() -> i32 {
19+
| ------------------- ^^^ expected `i32`, found `()`
20+
| |
21+
| implicitly returns `()` as its body has no tail or `return` expression
22+
23+
error[E0308]: mismatched types
24+
--> $DIR/break-diverging-value.rs:26:25
25+
|
26+
LL | fn loop_break_void() -> i32 {
27+
| --------------- ^^^ expected `i32`, found `()`
28+
| |
29+
| implicitly returns `()` as its body has no tail or `return` expression
30+
31+
error: aborting due to 4 previous errors
1032

11-
For more information about this error, try `rustc --explain E0308`.
33+
Some errors have detailed explanations: E0069, E0308.
34+
For more information about an error, try `rustc --explain E0069`.

0 commit comments

Comments
 (0)