diff options
Diffstat (limited to 'crates/ra_hir/src/ty/infer.rs')
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index b310bf6bd..d01063766 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs | |||
@@ -987,14 +987,21 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
987 | let then_ty = self.infer_expr(*then_branch, expected); | 987 | let then_ty = self.infer_expr(*then_branch, expected); |
988 | match else_branch { | 988 | match else_branch { |
989 | Some(else_branch) => { | 989 | Some(else_branch) => { |
990 | self.infer_expr(*else_branch, expected); | 990 | let else_ty = self.infer_expr(*else_branch, expected); |
991 | if Self::is_never(&then_ty) { | ||
992 | tested_by!(if_never); | ||
993 | else_ty | ||
994 | } else { | ||
995 | tested_by!(if_else_never); | ||
996 | then_ty | ||
997 | } | ||
991 | } | 998 | } |
992 | None => { | 999 | None => { |
993 | // no else branch -> unit | 1000 | // no else branch -> unit |
994 | self.unify(&then_ty, &Ty::unit()); // actually coerce | 1001 | self.unify(&then_ty, &Ty::unit()); // actually coerce |
1002 | then_ty | ||
995 | } | 1003 | } |
996 | }; | 1004 | } |
997 | then_ty | ||
998 | } | 1005 | } |
999 | Expr::Block { statements, tail } => self.infer_block(statements, *tail, expected), | 1006 | Expr::Block { statements, tail } => self.infer_block(statements, *tail, expected), |
1000 | Expr::TryBlock { body } => { | 1007 | Expr::TryBlock { body } => { |