diff options
author | Kirill Bulatov <[email protected]> | 2019-08-26 21:00:35 +0100 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2019-08-26 21:00:35 +0100 |
commit | 4adfdea1ad5aca393fa5bb9ff40fdc05827fcd56 (patch) | |
tree | 1ffe483a008c2d43441d7f04ef0b006823faf5f0 /crates/ra_hir/src | |
parent | 590aed2eec869a1b64c5d3c07a26dd59c669004b (diff) |
Small fixes
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/expr/validation.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 21 |
2 files changed, 15 insertions, 13 deletions
diff --git a/crates/ra_hir/src/expr/validation.rs b/crates/ra_hir/src/expr/validation.rs index c99c9c869..c8ae19869 100644 --- a/crates/ra_hir/src/expr/validation.rs +++ b/crates/ra_hir/src/expr/validation.rs | |||
@@ -97,7 +97,12 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
97 | } | 97 | } |
98 | } | 98 | } |
99 | 99 | ||
100 | fn validate_results_in_tail_expr(&mut self, body_id: ExprId, id: ExprId, db: &impl HirDatabase) { | 100 | fn validate_results_in_tail_expr( |
101 | &mut self, | ||
102 | body_id: ExprId, | ||
103 | id: ExprId, | ||
104 | db: &impl HirDatabase, | ||
105 | ) { | ||
101 | // the mismatch will be on the whole block currently | 106 | // the mismatch will be on the whole block currently |
102 | let mismatch = match self.infer.type_mismatch_for_expr(body_id) { | 107 | let mismatch = match self.infer.type_mismatch_for_expr(body_id) { |
103 | Some(m) => m, | 108 | Some(m) => m, |
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 | } |