Repository: rust-analyzer/rust-analyzer (rust)

Issue:
Autocompletion on Match arms has Inversed
Hello!

I believe autocompletion in Match statements has inverted. I'll explain:

![image](https://user-images.githubusercontent.com/31973761/80988943-18220300-8de9-11ea-88a6-7eeb871a41b9.png)


Here, we have some Match with some Enum being returned on the first Arm. Rustc has therefore decided that each arm is of type `Repo`, and that therefore, my other arms are in a failure state, as they do not have such a return type. If this is true, and with no other code present, then RA should agree with `x` now being of the type `Repo`, but it's still typed as `()`. 

Now, if I do this...
![image](https://user-images.githubusercontent.com/31973761/80989129-5d463500-8de9-11ea-94fd-52e3fac3df37.png)

The RA now says that X is of type `Repo`, when Rustc actually thinks this Match should return a  `()`!

I realize this is only an error case, and filling these arms up with `todo` or `unreachable` essentially makes them be in agreement, but going bottom up is a little counter intuitive. Personally, it interrupts how I program, since I frequently make match arms at the top, fill in one branch, and then live with the errors but with the type checking until I'm ready to go back.

Side note: this has nothing to do with the `_` match. the follow demonstrates that:

![image](https://user-images.githubusercontent.com/31973761/80989400-bd3cdb80-8de9-11ea-8b09-a6e81d7e14a6.png)

I also feel like this wasn't the case before the update this morning? But not positively sure.

Thanks for all the great work all!

Pull request description:
Use first match branch in case of type mismatch, not last
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.

Patch:
diff --git a/crates/ra_hir_ty/src/infer/coerce.rs b/crates/ra_hir_ty/src/infer/coerce.rs
index 2ee9adb164..32c7c57cd6 100644
--- a/crates/ra_hir_ty/src/infer/coerce.rs
+++ b/crates/ra_hir_ty/src/infer/coerce.rs
@@ -45,9 +45,7 @@ impl<'a> InferenceContext<'a> {
                 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()
             }
         }
     }


Test patch:
diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs
index fd2208af28..daa9cc953f 100644
--- a/crates/ra_hir_ty/src/tests/simple.rs
+++ b/crates/ra_hir_ty/src/tests/simple.rs
@@ -937,7 +937,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