diff options
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 0aa993067..812990426 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs | |||
@@ -1009,16 +1009,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1009 | 1009 | ||
1010 | let then_ty = self.infer_expr_inner(*then_branch, &expected); | 1010 | let then_ty = self.infer_expr_inner(*then_branch, &expected); |
1011 | self.coerce(&then_ty, &expected.ty); | 1011 | self.coerce(&then_ty, &expected.ty); |
1012 | match else_branch { | 1012 | |
1013 | Some(else_branch) => { | 1013 | let else_ty = match else_branch { |
1014 | let else_ty = self.infer_expr_inner(*else_branch, &expected); | 1014 | Some(else_branch) => self.infer_expr_inner(*else_branch, &expected), |
1015 | self.coerce(&else_ty, &expected.ty); | 1015 | None => Ty::unit(), |
1016 | } | ||
1017 | None => { | ||
1018 | // no else branch -> unit | ||
1019 | self.unify(&then_ty, &Ty::unit()); // actually coerce | ||
1020 | } | ||
1021 | }; | 1016 | }; |
1017 | self.coerce(&else_ty, &expected.ty); | ||
1022 | 1018 | ||
1023 | expected.ty.clone() | 1019 | expected.ty.clone() |
1024 | } | 1020 | } |
@@ -1422,7 +1418,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1422 | } | 1418 | } |
1423 | } | 1419 | } |
1424 | } | 1420 | } |
1425 | let ty = if let Some(expr) = tail { self.infer_expr_inner(expr, expected) } else { Ty::unit() }; | 1421 | let ty = |
1422 | if let Some(expr) = tail { self.infer_expr_inner(expr, expected) } else { Ty::unit() }; | ||
1426 | ty | 1423 | ty |
1427 | } | 1424 | } |
1428 | 1425 | ||
@@ -1665,8 +1662,8 @@ fn calculate_least_upper_bound(expected_ty: Ty, actual_tys: &[Ty]) -> Ty { | |||
1665 | all_never = false; | 1662 | all_never = false; |
1666 | least_upper_bound = match (actual_ty, &least_upper_bound) { | 1663 | least_upper_bound = match (actual_ty, &least_upper_bound) { |
1667 | (_, Ty::Unknown) | 1664 | (_, Ty::Unknown) |
1668 | | (Ty::Infer(_), Ty::Infer(InferTy::TypeVar(_))) | 1665 | | (Ty::Infer(_), Ty::Infer(InferTy::TypeVar(_))) |
1669 | | (Ty::Apply(_), _) => actual_ty.clone(), | 1666 | | (Ty::Apply(_), _) => actual_ty.clone(), |
1670 | _ => least_upper_bound, | 1667 | _ => least_upper_bound, |
1671 | } | 1668 | } |
1672 | } | 1669 | } |