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.rs25
1 files changed, 16 insertions, 9 deletions
diff --git a/crates/hir-ty/src/infer/expr.rs b/crates/hir-ty/src/infer/expr.rs
index f307584843..d7c6691ea0 100644
--- a/crates/hir-ty/src/infer/expr.rs
+++ b/crates/hir-ty/src/infer/expr.rs
@@ -874,9 +874,15 @@ impl<'a> InferenceContext<'a> {
},
Expr::Underscore => {
// Underscore expressions may only appear in assignee expressions,
- // which are handled by `infer_assignee_expr()`, so any underscore
- // expression reaching this branch is an error.
- self.err_ty()
+ // which are handled by `infer_assignee_expr()`.
+ // Any other underscore expression is an error, we render a specialized diagnostic
+ // to let the user know what type is expected though.
+ let expected = expected.to_option(&mut self.table).unwrap_or_else(|| self.err_ty());
+ self.push_diagnostic(InferenceDiagnostic::TypedHole {
+ expr: tgt_expr,
+ expected: expected.clone(),
+ });
+ expected
}
};
// use a new type variable if we got unknown here
@@ -1001,12 +1007,13 @@ impl<'a> InferenceContext<'a> {
}
&Array::Repeat { initializer, repeat } => {
self.infer_expr_coerce(initializer, &Expectation::has_type(elem_ty.clone()));
- self.infer_expr(
- repeat,
- &Expectation::HasType(
- TyKind::Scalar(Scalar::Uint(UintTy::Usize)).intern(Interner),
- ),
- );
+ let usize = TyKind::Scalar(Scalar::Uint(UintTy::Usize)).intern(Interner);
+ match self.body[repeat] {
+ Expr::Underscore => {
+ self.write_expr_ty(repeat, usize);
+ }
+ _ => _ = self.infer_expr(repeat, &Expectation::HasType(usize)),
+ }
(
elem_ty,