Skip to content

Commit 7d0586c

Browse files
committed
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.
1 parent 190a059 commit 7d0586c

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

crates/ra_hir_ty/src/infer/coerce.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ impl<'a> InferenceContext<'a> {
4545
self.coerce_merge_branch(&ptr_ty1, &ptr_ty2)
4646
} else {
4747
mark::hit!(coerce_merge_fail_fallback);
48-
// For incompatible types, we use the latter one as result
49-
// to be better recovery for `if` without `else`.
50-
ty2.clone()
48+
ty1.clone()
5149
}
5250
}
5351
}

crates/ra_hir_ty/src/tests/simple.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ fn main(foo: Foo) {
937937
51..107 'if tru... }': ()
938938
54..58 'true': bool
939939
59..67 '{ }': ()
940-
73..107 'if fal... }': ()
940+
73..107 'if fal... }': i32
941941
76..81 'false': bool
942942
82..107 '{ ... }': i32
943943
92..95 'foo': Foo

0 commit comments

Comments
 (0)