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>
This commit is contained in:
bors[bot] 2020-05-29 21:07:43 +00:00 committed by GitHub
commit f7f01dd5f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 4 deletions

View file

@ -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()
}
}
}

View 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