diff --git a/crates/hir-ty/src/infer/expr.rs b/crates/hir-ty/src/infer/expr.rs index f247b517c541..fc53d64a2f98 100644 --- a/crates/hir-ty/src/infer/expr.rs +++ b/crates/hir-ty/src/infer/expr.rs @@ -1329,7 +1329,11 @@ impl<'db> InferenceContext<'db> { } None => { let ty = self.table.next_ty_var(element.into()); - self.infer_expr(element, &Expectation::has_type(ty), ExprIsRead::Yes); + self.infer_expr_suptype_coerce_never( + element, + &Expectation::has_type(ty), + ExprIsRead::Yes, + ); ty } }; diff --git a/crates/hir-ty/src/tests/never_type.rs b/crates/hir-ty/src/tests/never_type.rs index 1c5f8aa11046..e53f7503dac6 100644 --- a/crates/hir-ty/src/tests/never_type.rs +++ b/crates/hir-ty/src/tests/never_type.rs @@ -114,6 +114,21 @@ fn test() { ); } +#[test] +fn array_repeat_never_can_be_reinferred() { + check_no_mismatches( + r#" +fn test() { + let y = [return; 2]; + match y { + [(1, _), (_, false)] => {} + [_, _] => {} + } +} +"#, + ); +} + #[test] fn match_no_arm() { check_types(