]> git.lizzy.rs Git - rust.git/commitdiff
Use `diverges` instead of `!`-type
authorvarkor <github@varkor.com>
Thu, 22 Oct 2020 22:12:46 +0000 (23:12 +0100)
committervarkor <github@varkor.com>
Thu, 22 Oct 2020 22:12:46 +0000 (23:12 +0100)
compiler/rustc_typeck/src/check/expr.rs
src/test/ui/break-diverging-value.rs
src/test/ui/break-diverging-value.stderr

index 15820d367c0a669c7998c2c571f45b9db9c85195..dce3be9399dd60e8d8f2ae6f35e89c7dfcb61ead 100644 (file)
@@ -630,7 +630,7 @@ fn check_expr_break(
             // If we encountered a `break`, then (no surprise) it may be possible to break from the
             // loop... unless the value being returned from the loop diverges itself, e.g.
             // `break return 5` or `break loop {}`.
-            ctxt.may_break |= !e_ty.is_never();
+            ctxt.may_break |= !self.diverges.get().is_always();
 
             // the type of a `break` is always `!`, since it diverges
             tcx.types.never
index 0117abeb105cfd026563a5d4a74fc9d8a367ec14..d070fddaffc195d58775446dcd3c44e8a9cef561 100644 (file)
@@ -12,9 +12,8 @@ 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 `()`
+fn loop_break_return_2() -> i32 {
+    let loop_value = loop { break { return 0; () } }; // ok
 }
 
 enum Void {}
index de3f9bd778a9dd0e0cc36a3c201d28ceb9bb0dc2..69edcd240800222081f7eddcaeb9b55107101345 100644 (file)
@@ -6,29 +6,14 @@ LL | fn loop_break_break() -> i32 {
    |    |
    |    implicitly returns `()` as its body has no tail or `return` expression
 
-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
+  --> $DIR/break-diverging-value.rs:25: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
+error: aborting due to 2 previous errors
 
-Some errors have detailed explanations: E0069, E0308.
-For more information about an error, try `rustc --explain E0069`.
+For more information about this error, try `rustc --explain E0308`.