]> git.lizzy.rs Git - rust.git/commitdiff
Add a test for returning inside a while loop
authorvarkor <github@varkor.com>
Fri, 25 May 2018 14:31:13 +0000 (15:31 +0100)
committervarkor <github@varkor.com>
Fri, 25 May 2018 15:53:32 +0000 (16:53 +0100)
src/test/ui/break-while-condition.rs
src/test/ui/break-while-condition.stderr

index cc5d17e42d52bcec181514e5011ab6b19d89c4f6..5949b299893240248b2dd2f76283b18049e3fa7e 100644 (file)
 #![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
+            }
+        };
+    }
 }
index 5abf60c86d306db7052be26034288cf8f9491df7..e3564297bf2efe667d2377131d0d307ab49f0abe 100644 (file)
@@ -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`.