mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-30 13:06:28 +03:00
Small fixes
This commit is contained in:
@@ -97,7 +97,12 @@ fn validate_record_literal(
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
let mismatch = match self.infer.type_mismatch_for_expr(body_id) {
|
||||
Some(m) => m,
|
||||
|
||||
@@ -1009,16 +1009,12 @@ fn infer_expr_inner(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty {
|
||||
|
||||
let then_ty = self.infer_expr_inner(*then_branch, &expected);
|
||||
self.coerce(&then_ty, &expected.ty);
|
||||
match else_branch {
|
||||
Some(else_branch) => {
|
||||
let else_ty = self.infer_expr_inner(*else_branch, &expected);
|
||||
self.coerce(&else_ty, &expected.ty);
|
||||
}
|
||||
None => {
|
||||
// no else branch -> unit
|
||||
self.unify(&then_ty, &Ty::unit()); // actually coerce
|
||||
}
|
||||
|
||||
let else_ty = match else_branch {
|
||||
Some(else_branch) => self.infer_expr_inner(*else_branch, &expected),
|
||||
None => Ty::unit(),
|
||||
};
|
||||
self.coerce(&else_ty, &expected.ty);
|
||||
|
||||
expected.ty.clone()
|
||||
}
|
||||
@@ -1422,7 +1418,8 @@ fn infer_block(
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
@@ -1665,8 +1662,8 @@ fn calculate_least_upper_bound(expected_ty: Ty, actual_tys: &[Ty]) -> Ty {
|
||||
all_never = false;
|
||||
least_upper_bound = match (actual_ty, &least_upper_bound) {
|
||||
(_, Ty::Unknown)
|
||||
| (Ty::Infer(_), Ty::Infer(InferTy::TypeVar(_)))
|
||||
| (Ty::Apply(_), _) => actual_ty.clone(),
|
||||
| (Ty::Infer(_), Ty::Infer(InferTy::TypeVar(_)))
|
||||
| (Ty::Apply(_), _) => actual_ty.clone(),
|
||||
_ => least_upper_bound,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user