]> git.lizzy.rs Git - rust.git/commitdiff
Fix error message label
authoralexey zabelin <zabelin.alex@gmail.com>
Fri, 28 Apr 2017 22:01:06 +0000 (18:01 -0400)
committeralexey zabelin <zabelin.alex@gmail.com>
Fri, 28 Apr 2017 22:01:06 +0000 (18:01 -0400)
src/librustc_typeck/check/coercion.rs
src/test/ui/coercion-missing-tail-expected-type.stderr

index 1e08d6378a94cad50be77a1279e50fd71ec1817e..57415021976b349cc10f34ae7f864cfa6ca152f2 100644 (file)
@@ -1104,7 +1104,7 @@ fn coerce_inner<'a>(&mut self,
             // Another example is `break` with no argument expression.
             assert!(expression_ty.is_nil());
             assert!(expression_ty.is_nil(), "if let hack without unit type");
-            fcx.eq_types(true, cause, expression_ty, self.merged_ty())
+            fcx.eq_types(label_expression_as_expected, cause, expression_ty, self.merged_ty())
                .map(|infer_ok| {
                    fcx.register_infer_ok_obligations(infer_ok);
                    expression_ty
@@ -1128,6 +1128,10 @@ fn coerce_inner<'a>(&mut self,
             }
             Err(err) => {
                 let (expected, found) = if label_expression_as_expected {
+                    // In the case where this is a "forced unit", like
+                    // `break`, we want to call the `()` "expected"
+                    // since it is implied by the syntax.
+                    // (Note: not all force-units work this way.)"
                     (expression_ty, self.final_ty.unwrap_or(self.expected_ty))
                 } else {
                     // Otherwise, the "expected" type for error
index 43222e36ec57e7daf0085802098491aff828a4d2..8f08ff34637707851e48ec63c00a0745e980aa6a 100644 (file)
@@ -5,7 +5,7 @@ error[E0308]: mismatched types
    |  ____________________________^
 14 | |     x + 1;
 15 | | }
-   | |_^ expected (), found i32
+   | |_^ expected i32, found ()
    |
    = note: expected type `i32`
               found type `()`