aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2020-05-29 15:03:06 +0100
committerFlorian Diebold <[email protected]>2020-05-29 15:04:56 +0100
commit7d0586cb15000193941f93d4b5281e56ef751edd (patch)
tree84d3847e805b43b641ec7db04f78064835c1ee07 /crates/ra_hir_ty
parent190a0595a478d059fdd95a179fe38d59cb6379be (diff)
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.
Diffstat (limited to 'crates/ra_hir_ty')
-rw-r--r--crates/ra_hir_ty/src/infer/coerce.rs4
-rw-r--r--crates/ra_hir_ty/src/tests/simple.rs2
2 files changed, 2 insertions, 4 deletions
diff --git a/crates/ra_hir_ty/src/infer/coerce.rs b/crates/ra_hir_ty/src/infer/coerce.rs
index 2ee9adb16..32c7c57cd 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> {
45 self.coerce_merge_branch(&ptr_ty1, &ptr_ty2) 45 self.coerce_merge_branch(&ptr_ty1, &ptr_ty2)
46 } else { 46 } else {
47 mark::hit!(coerce_merge_fail_fallback); 47 mark::hit!(coerce_merge_fail_fallback);
48 // For incompatible types, we use the latter one as result 48 ty1.clone()
49 // to be better recovery for `if` without `else`.
50 ty2.clone()
51 } 49 }
52 } 50 }
53 } 51 }
diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs
index fd2208af2..daa9cc953 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) {
937 51..107 'if tru... }': () 937 51..107 'if tru... }': ()
938 54..58 'true': bool 938 54..58 'true': bool
939 59..67 '{ }': () 939 59..67 '{ }': ()
940 73..107 'if fal... }': () 940 73..107 'if fal... }': i32
941 76..81 'false': bool 941 76..81 'false': bool
942 82..107 '{ ... }': i32 942 82..107 '{ ... }': i32
943 92..95 'foo': Foo 943 92..95 'foo': Foo