Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #22804 from ChayimFriedman2/array-repeat-closure
fix: Only write anon const ty in parent's inference result if it doesn't have its own inference
| -rw-r--r-- | crates/hir-ty/src/infer.rs | 3 | ||||
| -rw-r--r-- | crates/hir-ty/src/tests/regression.rs | 10 |
2 files changed, 12 insertions, 1 deletions
diff --git a/crates/hir-ty/src/infer.rs b/crates/hir-ty/src/infer.rs index 8c70461ff6..d103bacb8f 100644 --- a/crates/hir-ty/src/infer.rs +++ b/crates/hir-ty/src/infer.rs @@ -2011,9 +2011,10 @@ impl<'body, 'db> InferenceContext<'body, 'db> { && let GeneralConstId::AnonConstId(konst) = konst.def.0 { self.defined_anon_consts.borrow_mut().push(konst); + } else { + self.write_expr_ty(expr, expected_ty); } - self.write_expr_ty(expr, expected_ty); // FIXME: Report an error if needed. konst.unwrap_or_else(|_| self.table.next_const_var(Span::Dummy)) } diff --git a/crates/hir-ty/src/tests/regression.rs b/crates/hir-ty/src/tests/regression.rs index dcb79f042b..dc88231187 100644 --- a/crates/hir-ty/src/tests/regression.rs +++ b/crates/hir-ty/src/tests/regression.rs @@ -2983,3 +2983,13 @@ fn migrations_preserve_index() { "#, ); } + +#[test] +fn array_repeat_closure() { + check( + r#" +fn f() {[_; || ()]} + // ^^^^^^^^^^ expected (), got [{unknown}; _] + "#, + ); +} |