Skip to content

feat(ide-diagnostics): add diagnostics for invalid union patterns (E0784) #22433

Open
dotacow wants to merge 2 commits into
rust-lang:masterfrom
dotacow:master
Open

feat(ide-diagnostics): add diagnostics for invalid union patterns (E0784) #22433
dotacow wants to merge 2 commits into
rust-lang:masterfrom
dotacow:master

Conversation

@dotacow
Copy link
Copy Markdown

@dotacow dotacow commented May 23, 2026

What

Adds diagnostics to catch invalid union patterns. The diagnostics trigger when a union pattern contains multiple fields or uses the rest (..) operator.

Why

Addresses part of tracking issue #22140, resolving two FIXME comments in crates/hir-ty/src/infer/pat.rs. Aligns rust-analyzer with rustc behavior for error E0784.

How

  • Defines UnionPatMustHaveExactlyOneField and UnionPatHasRest variants in hir-ty::InferenceDiagnostic.
  • Emits diagnostics in crates/hir-ty/src/infer/pat.rs during pattern inference.
  • Bridges the data structures through crates/hir/src/diagnostics.rs.
  • Adds rendering handlers in crates/ide-diagnostics to output E0784 with the correct text messages.
  • Includes UI tests to verify text spans and diagnostic strings.

Note for reviewers:

The missing record fields FIXME (E0027) from the same code block is left for a future PR, as attempting to solve it here would be over-scoping this PR.
AI usage was declared on a per commit basis as per the contribution guidelines.

dotacow added 2 commits May 23, 2026 17:49
AI-assisted:I utilized vscode's IDE assistant Copilot.
AI-assisted: I used an LLM to guide me through the debugging process.
all code was reviewed and tested.
@rustbot rustbot added 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

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.

2 participants