Skip to content

Detect invalid discriminants/repr combinations early - #166602

Open
oli-obk wants to merge 1 commit into
rust-lang:mainfrom
oli-obk:push-wkovklroprqv
Open

oli-obk wants to merge 1 commit into
rust-lang:mainfrom
oli-obk:push-wkovklroprqv

Conversation

@oli-obk

@oli-obk oli-obk commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

and reset the representation to repr(u128) which should work mostly without further diagnostics issues. Could also pick i128 to avoid negative discriminant errors.

fixes #144501

I considered actually tracking the error taint in AdtDef, but I don't think that's necessary for now

Also reset the representation to something the rest of the compiler can process, even if diagnostics may surprisingly talk about repr(u128) now.
@rustbot

rustbot commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

This PR changes a file inside tests/crashes. If a crash was fixed, please move into the corresponding ui subdir and add 'Fixes #' to the PR description to autoclose the issue upon merge.

@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 Nov 26, 2026
@rustbot

rustbot commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

r? @TaKO8Ki

rustbot has assigned @TaKO8Ki.
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 79 candidates
  • Random selection from 19 candidates

@oli-obk

oli-obk commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

cc @RalfJung

);
}
err.emit();
// Pick a permissive value so the rest of the compiler can just keep going.

@RalfJung RalfJung Nov 27, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// Pick a permissive value so the rest of the compiler can just keep going.
// Pick a permissive value so the rest of the compiler can just keep going.
// (Ideally we'd taint this ADT so we didn't have to pick a type here and
// we'd 100% avoid invalid follow-up errors, but that would be a rather big refactor.)

View changes since the review

@RalfJung

Copy link
Copy Markdown
Member

Could also pick i128 to avoid negative discriminant errors.

Yeah I think that would be preferable.

Any discriminants that have a fixed type, like i32::MAX, will error either way, right? That's not great but definitely better than ICEs.

This branch has not been deployed

No deployments
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: layout.ty.discriminant_for_variant(tcx, idx).unwrap().val != u128::from(idx.as_u32()

4 participants