Skip to content

fix: reinfer never type in array repeat expressions - #23232

Open
phpont wants to merge 1 commit into
rust-lang:masterfrom
phpont:fix/23177-array-repeat-never
Open

fix: reinfer never type in array repeat expressions#23232
phpont wants to merge 1 commit into
rust-lang:masterfrom
phpont:fix/23177-array-repeat-never

Conversation

@phpont

@phpont phpont commented Aug 25, 2026

Copy link
Copy Markdown

Array repeat expressions could produce false-positive type mismatches when the initializer diverged and the element type still had to be inferred from later context.

The issue was that infer_expr could constrain the fresh inference variable to ! too early. I switched this path to the existing infer_expr_suptype_coerce_never helper, which also matches how rustc handles the never-type coercion in this case.

I also added a minimal regression test next to the existing never-type reinference tests.

Fixes #23177

Tests:

  • cargo test -p hir-ty
  • cargo clippy -p hir-ty --all-targets -- --cap-lints warn
  • cargo lint
  • cargo test

AI disclosure: AI was used to help investigate and review the change. I wrote the implementation and ran the validation manually.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FP expected !, found ({unknown}, {unknown})

2 participants