From d415fae8b76cddbcd7825cb6642186a833453b3c Mon Sep 17 00:00:00 2001 From: varkor Date: Wed, 21 Oct 2020 22:52:41 +0100 Subject: [PATCH] Add tests for uninhabited types --- src/test/ui/break-diverging-value.rs | 25 ++++++++++++++++++++ src/test/ui/break-diverging-value.stderr | 29 +++++++++++++++++++++--- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/test/ui/break-diverging-value.rs b/src/test/ui/break-diverging-value.rs index 0498580c7bd..0117abeb105 100644 --- a/src/test/ui/break-diverging-value.rs +++ b/src/test/ui/break-diverging-value.rs @@ -1,3 +1,5 @@ +#![feature(never_type)] + fn loop_break_return() -> i32 { 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 }; } +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() {} diff --git a/src/test/ui/break-diverging-value.stderr b/src/test/ui/break-diverging-value.stderr index 78a8d78ed34..de3f9bd778a 100644 --- a/src/test/ui/break-diverging-value.stderr +++ b/src/test/ui/break-diverging-value.stderr @@ -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 `()` -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`.