Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/infer/expr.rs')
| -rw-r--r-- | crates/hir-ty/src/infer/expr.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/crates/hir-ty/src/infer/expr.rs b/crates/hir-ty/src/infer/expr.rs index 38076fce8f..4c12786362 100644 --- a/crates/hir-ty/src/infer/expr.rs +++ b/crates/hir-ty/src/infer/expr.rs @@ -933,8 +933,24 @@ impl InferenceContext<'_> { let prev_ret_coercion = mem::replace(&mut self.return_coercion, Some(CoerceMany::new(ret_ty.clone()))); + // FIXME: We should handle async blocks like we handle closures + let expected = &Expectation::has_type(ret_ty); let (_, inner_ty) = self.with_breakable_ctx(BreakableKind::Border, None, None, |this| { - this.infer_block(tgt_expr, *id, statements, *tail, None, &Expectation::has_type(ret_ty)) + let ty = this.infer_block(tgt_expr, *id, statements, *tail, None, expected); + if let Some(target) = expected.only_has_type(&mut this.table) { + match this.coerce(Some(tgt_expr), &ty, &target) { + Ok(res) => res, + Err(_) => { + this.result.type_mismatches.insert( + tgt_expr.into(), + TypeMismatch { expected: target.clone(), actual: ty.clone() }, + ); + target + } + } + } else { + ty + } }); self.diverges = prev_diverges; |