From 03d816fd934a19d3fdb27080add61b1dddbaad86 Mon Sep 17 00:00:00 2001 From: varkor Date: Fri, 25 May 2018 15:31:13 +0100 Subject: [PATCH] Add a test for returning inside a while loop --- src/test/ui/break-while-condition.rs | 28 ++++++++++++++-- src/test/ui/break-while-condition.stderr | 42 ++++++++++++++++++++---- 2 files changed, 60 insertions(+), 10 deletions(-) diff --git a/src/test/ui/break-while-condition.rs b/src/test/ui/break-while-condition.rs index cc5d17e42d5..5949b299893 100644 --- a/src/test/ui/break-while-condition.rs +++ b/src/test/ui/break-while-condition.rs @@ -11,7 +11,29 @@ #![feature(never_type)] fn main() { - let _: ! = { //~ ERROR mismatched types - 'a: while break 'a {}; - }; + // 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 + } + }; + } } diff --git a/src/test/ui/break-while-condition.stderr b/src/test/ui/break-while-condition.stderr index 5abf60c86d3..e3564297bf2 100644 --- a/src/test/ui/break-while-condition.stderr +++ b/src/test/ui/break-while-condition.stderr @@ -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 () +LL | let _: ! = { //~ ERROR mismatched types + | ____________________^ +LL | | 'a: while break 'a {}; +LL | | }; + | |_________^ 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`.