Skip to content

fix: Emit diagnostic for rest array patterns without fixed-length arrays#22424

Merged
lnicola merged 1 commit into
rust-lang:masterfrom
Abusalah0:diag-array-pattern-without-fixed-length
May 23, 2026
Merged

fix: Emit diagnostic for rest array patterns without fixed-length arrays#22424
lnicola merged 1 commit into
rust-lang:masterfrom
Abusalah0:diag-array-pattern-without-fixed-length

Conversation

@Abusalah0
Copy link
Copy Markdown
Contributor

@Abusalah0 Abusalah0 commented May 23, 2026

Emit a diagnostic when pattern-matching on arrays without a fixed length. This adds an InferenceDiagnostic::ArrayPatternWithoutFixedLength, converts it into a hir-level diagnostic, and renders it in ide-diagnostics.

Why

The codebase contains a FIXME in crates/hir-ty/src/infer/pat.rs describing this missing
diagnostic. Producing a user-facing error clarifies the analyzer's behavior and prevents
surprising inference results.

Refs: rust-analyzer issue #22140

How

  • Added ArrayPatternWithoutFixedLength to crates/hir-ty/src/infer.rs.
  • Emitted the diagnostic at the FIXME site in crates/hir-ty/src/infer/pat.rs.
  • Added conversion to AnyDiagnostic in crates/hir/src/diagnostics.rs.
  • Implemented a handler in crates/ide-diagnostics/src/handlers/array_pattern_without_fixed_length.rs and registered it in crates/ide-diagnostics/src/lib.rs.
  • Added focused tests in crates/ide-diagnostics covering both non-fixed-length (error) and fixed-length (no error) cases.

Notes for reviewers

  • Change is narrowly scoped to pattern inference; it should not alter other analyses.
  • Commit includes AI usage disclosure per CONTRIBUTING.md.

Add a new inference diagnostic for rest array patterns on arrays whose length is not known to be fixed, plumb it through hir and ide-diagnostics, and add handler tests.

AI-assisted: Changes were prepared with GitHub Copilot (GPT-5.3-Codex), then reviewed and validated with local tests.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 23, 2026
@lnicola lnicola added this pull request to the merge queue May 23, 2026
Merged via the queue into rust-lang:master with commit 608f881 May 23, 2026
18 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants