Skip to content

Commit f7f01dd

Browse files
Merge #4651
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>
2 parents 3689c8c + 7d0586c commit f7f01dd

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
@@ -957,7 +957,7 @@ fn main(foo: Foo) {
957957
51..107 'if tru... }': ()
958958
54..58 'true': bool
959959
59..67 '{ }': ()
960-
73..107 'if fal... }': ()
960+
73..107 'if fal... }': i32
961961
76..81 'false': bool
962962
82..107 '{ ... }': i32
963963
92..95 'foo': Foo

0 commit comments

Comments
 (0)