Skip to content

Commit

Permalink
Add tests for uninhabited types
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Oct 21, 2020
1 parent 5a440f1 commit d415fae
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
25 changes: 25 additions & 0 deletions src/test/ui/break-diverging-value.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(never_type)]

fn loop_break_return() -> i32 {
let loop_value = loop { break return 0 }; // ok
}
Expand All @@ -10,4 +12,27 @@ fn loop_break_break() -> i32 { //~ ERROR mismatched types
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() {}
29 changes: 26 additions & 3 deletions src/test/ui/break-diverging-value.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
error[E0308]: mismatched types
--> $DIR/break-diverging-value.rs:9:26
--> $DIR/break-diverging-value.rs:11:26
|
LL | fn loop_break_break() -> i32 {
| ---------------- ^^^ expected `i32`, found `()`
| |
| 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 `()`

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

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

0 comments on commit d415fae

Please sign in to comment.