Skip to content

Reject extra fields in MGCA struct const arguments#157886

Open
Shourya742 wants to merge 2 commits into
rust-lang:mainfrom
Shourya742:2026-06-14-reject-extra-field-mgca-adt-const
Open

Reject extra fields in MGCA struct const arguments#157886
Shourya742 wants to merge 2 commits into
rust-lang:mainfrom
Shourya742:2026-06-14-reject-extra-field-mgca-adt-const

Conversation

@Shourya742

@Shourya742 Shourya742 commented Jun 14, 2026

Copy link
Copy Markdown
Member

closes: #154538

r? @BoxyUwU

@rustbot

rustbot commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

HIR ty lowering was modified

cc @fmease

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 14, 2026
@rustbot

rustbot commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

r? @davidtwco

rustbot has assigned @davidtwco.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 22 candidates

@rustbot rustbot assigned BoxyUwU and unassigned davidtwco Jun 14, 2026
Comment on lines +2594 to +2603
for init in inits {
if !variant_def.fields.iter().any(|field_def| field_def.name == init.field.name) {
let err = tcx.dcx().struct_span_err(
init.field.span,
format!("struct expression has no field named `{}`", init.field),
);
return ty::Const::new_error(tcx, err.emit());
}
}

@Shourya742 Shourya742 Jun 14, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Currently, lower_const_arg_struct handled missing and duplicate initializers, but it did not check for extra fields. This checkd for fields that do not exist on the target variant.

View changes since the review

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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ICE]: mgca: type_of called on const argument's anon const before the const argument was lowered

4 participants