Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/hir-ty/src/infer/expr.rs12
-rw-r--r--crates/hir-ty/src/tests/simple.rs13
2 files changed, 21 insertions, 4 deletions
diff --git a/crates/hir-ty/src/infer/expr.rs b/crates/hir-ty/src/infer/expr.rs
index db3303607b..50bc70f4ee 100644
--- a/crates/hir-ty/src/infer/expr.rs
+++ b/crates/hir-ty/src/infer/expr.rs
@@ -1336,14 +1336,18 @@ impl<'db> InferenceContext<'_, 'db> {
ExprIsRead::Yes,
);
let usize = self.types.usize;
- match self.body[repeat] {
+ let len = match self.body[repeat] {
Expr::Underscore => {
self.write_expr_ty(repeat, usize);
+ self.table.next_const_var()
}
- _ => _ = self.infer_expr(repeat, &Expectation::HasType(usize), ExprIsRead::Yes),
- }
+ _ => {
+ self.infer_expr(repeat, &Expectation::HasType(usize), ExprIsRead::Yes);
+ consteval::eval_to_const(repeat, self)
+ }
+ };
- (elem_ty, consteval::eval_to_const(repeat, self))
+ (elem_ty, len)
}
};
// Try to evaluate unevaluated constant, and insert variable if is not possible.
diff --git a/crates/hir-ty/src/tests/simple.rs b/crates/hir-ty/src/tests/simple.rs
index 478411f5a8..2e107b2c59 100644
--- a/crates/hir-ty/src/tests/simple.rs
+++ b/crates/hir-ty/src/tests/simple.rs
@@ -3943,3 +3943,16 @@ fn foo() {
"#]],
);
}
+
+#[test]
+fn infer_array_size() {
+ check_no_mismatches(
+ r#"
+fn foo(a: [u8; 3]) {}
+
+fn bar() {
+ foo([0; _]);
+}
+ "#,
+ );
+}