]> git.lizzy.rs Git - rust.git/commitdiff
Merge #4651
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>
Fri, 29 May 2020 21:07:43 +0000 (21:07 +0000)
committerGitHub <noreply@github.com>
Fri, 29 May 2020 21:07:43 +0000 (21:07 +0000)
4651: Use first match branch in case of type mismatch, not last r=kjeremy a=flodiebold

The comment says this was intentional, but I do agree with #4304 that it makes
more sense the other way around (for if/else as well).

Fixes #4304.

Co-authored-by: Florian Diebold <florian.diebold@freiheit.com>
crates/ra_hir_ty/src/infer/coerce.rs
crates/ra_hir_ty/src/tests/simple.rs

index 2ee9adb16425c8063a1c44831193bcced58cc46d..32c7c57cd61a3be0561d59436b391eb6fda0ec77 100644 (file)
@@ -45,9 +45,7 @@ pub(super) fn coerce_merge_branch(&mut self, ty1: &Ty, ty2: &Ty) -> Ty {
                 self.coerce_merge_branch(&ptr_ty1, &ptr_ty2)
             } else {
                 mark::hit!(coerce_merge_fail_fallback);
-                // For incompatible types, we use the latter one as result
-                // to be better recovery for `if` without `else`.
-                ty2.clone()
+                ty1.clone()
             }
         }
     }
index f1db3416049fcdeed5d0c3b6a2b49e21a4a4f909..839491b9e28cb13dec6fdb683af207656658eab5 100644 (file)
@@ -957,7 +957,7 @@ fn main(foo: Foo) {
     51..107 'if tru...     }': ()
     54..58 'true': bool
     59..67 '{      }': ()
-    73..107 'if fal...     }': ()
+    73..107 'if fal...     }': i32
     76..81 'false': bool
     82..107 '{     ...     }': i32
     92..95 'foo': Foo