Skip to content

ide-diagnostics: emit error for duplicate field in record expression#22235

Merged
ChayimFriedman2 merged 2 commits intorust-lang:masterfrom
MavenRain:fixme-duplicate-field-diagnostic
May 4, 2026
Merged

ide-diagnostics: emit error for duplicate field in record expression#22235
ChayimFriedman2 merged 2 commits intorust-lang:masterfrom
MavenRain:fixme-duplicate-field-diagnostic

Conversation

@MavenRain
Copy link
Copy Markdown
Contributor

@MavenRain MavenRain commented May 1, 2026

Resolves a FIXME at hir-ty/src/infer/expr.rs that allowed record expressions like S { foo: 1, foo: 2 } to type-check with no error.

Adds an InferenceDiagnostic::DuplicateField variant, plumbs the cooked diagnostic through hir, and renders it as RustcHardError E0062 ("field specified more than once").

Tests: struct literal positive, enum variant literal positive, single-occurrence negative, no-conflict with the existing no-such-field path.

Part of #22140.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 1, 2026
@rustbot

This comment has been minimized.

Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please squash and change the issue link like rustbot has said, then LGTM.

View changes since this review

@ChayimFriedman2
Copy link
Copy Markdown
Contributor

You will also need to rebase against master.

@MavenRain MavenRain force-pushed the fixme-duplicate-field-diagnostic branch from 716b99f to 8c7e4d9 Compare May 1, 2026 08:43
@rustbot

This comment has been minimized.

Resolves a FIXME at hir-ty/src/infer/expr.rs that allowed
record expressions like `S { foo: 1, foo: 2 }` to type-check
with no error. Adds an InferenceDiagnostic::DuplicateField
variant, plumbs the cooked diagnostic through hir, and renders
it as RustcHardError E0062 ("field specified more than once").

Tests: struct literal positive, enum variant literal positive,
single-occurrence negative, no-conflict with the existing
no-such-field path.

Part of rust-lang#22140.
@MavenRain MavenRain force-pushed the fixme-duplicate-field-diagnostic branch from 8c7e4d9 to 5e757fd Compare May 3, 2026 10:20
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 3, 2026

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Comment thread crates/hir/src/diagnostics.rs Outdated
#[derive(Debug)]
pub struct DuplicateField {
pub field: InFile<AstPtr<Either<ast::RecordExprField, ast::RecordPatField>>>,
pub variant: VariantId,
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 May 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be hir::Variant. Do not expose hir-ty types outside hir.

View changes since the review

  Per review: do not expose hir-ty/hir-def types outside hir. Convert
  the lower-level VariantId to the public Variant wrapper at the
  inference-diagnostic boundary.
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChayimFriedman2 ChayimFriedman2 enabled auto-merge May 4, 2026 02:56
@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue May 4, 2026
Merged via the queue into rust-lang:master with commit 13bbf74 May 4, 2026
18 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 4, 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