mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 22:24:14 +00:00
Small fixes
This commit is contained in:
parent
590aed2eec
commit
4adfdea1ad
2 changed files with 15 additions and 13 deletions
|
@ -97,7 +97,12 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validate_results_in_tail_expr(&mut self, body_id: ExprId, id: ExprId, db: &impl HirDatabase) {
|
fn validate_results_in_tail_expr(
|
||||||
|
&mut self,
|
||||||
|
body_id: ExprId,
|
||||||
|
id: ExprId,
|
||||||
|
db: &impl HirDatabase,
|
||||||
|
) {
|
||||||
// the mismatch will be on the whole block currently
|
// the mismatch will be on the whole block currently
|
||||||
let mismatch = match self.infer.type_mismatch_for_expr(body_id) {
|
let mismatch = match self.infer.type_mismatch_for_expr(body_id) {
|
||||||
Some(m) => m,
|
Some(m) => m,
|
||||||
|
|
|
@ -1009,16 +1009,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
||||||
|
|
||||||
let then_ty = self.infer_expr_inner(*then_branch, &expected);
|
let then_ty = self.infer_expr_inner(*then_branch, &expected);
|
||||||
self.coerce(&then_ty, &expected.ty);
|
self.coerce(&then_ty, &expected.ty);
|
||||||
match else_branch {
|
|
||||||
Some(else_branch) => {
|
let else_ty = match else_branch {
|
||||||
let else_ty = self.infer_expr_inner(*else_branch, &expected);
|
Some(else_branch) => self.infer_expr_inner(*else_branch, &expected),
|
||||||
self.coerce(&else_ty, &expected.ty);
|
None => Ty::unit(),
|
||||||
}
|
|
||||||
None => {
|
|
||||||
// no else branch -> unit
|
|
||||||
self.unify(&then_ty, &Ty::unit()); // actually coerce
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
self.coerce(&else_ty, &expected.ty);
|
||||||
|
|
||||||
expected.ty.clone()
|
expected.ty.clone()
|
||||||
}
|
}
|
||||||
|
@ -1422,7 +1418,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let ty = if let Some(expr) = tail { self.infer_expr_inner(expr, expected) } else { Ty::unit() };
|
let ty =
|
||||||
|
if let Some(expr) = tail { self.infer_expr_inner(expr, expected) } else { Ty::unit() };
|
||||||
ty
|
ty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue