Skip to content

fix: const eval cast of single-variant enum - #23185

Open
hlsxx wants to merge 1 commit into
rust-lang:masterfrom
hlsxx:enum-dicr-evaluation
Open

fix: const eval cast of single-variant enum#23185
hlsxx wants to merge 1 commit into
rust-lang:masterfrom
hlsxx:enum-dicr-evaluation

Conversation

@hlsxx

@hlsxx hlsxx commented Aug 18, 2026

Copy link
Copy Markdown

Single-variant enum incorrectly evaluated to 0. The fix computes the discriminant via const_eval_discriminant in the IntToInt casting.

Fixes #23148)

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

@ChayimFriedman2 ChayimFriedman2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This isn't the correct way to fix that. It should be fixed during MIR lowering, see the corresponding code in rustc: https://github.com/rust-lang/rust/blob/e71c0f1e3395b10a8c331317be1a5c107bdf7b2e/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs#L125-L163.

View changes since this 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FP expected [i32; 0], found [i32; 4] wrong array size infer

3 participants