Skip to content

Conversation

@Delta17920
Copy link
Contributor

@Delta17920 Delta17920 commented Jan 5, 2026

This PR fixes an internal compiler error in rustc_transmute where initializing an Assume field (like alignment) with a non-scalar constant (like a struct) caused a panic.

The fix updates from_const to use try_to_scalar() instead of assuming the value is always a leaf. It now gracefully returns None for invalid types, allowing the compiler to report standard "missing field initialiser" errors instead of crashing.

Fixes #150506

@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 Jan 5, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 5, 2026

r? @lcnr

rustbot has assigned @lcnr.
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

@BoxyUwU
Copy link
Member

BoxyUwU commented Jan 5, 2026

r? BoxyUwU

@rustbot rustbot assigned BoxyUwU and unassigned lcnr Jan 5, 2026
@Delta17920 Delta17920 force-pushed the fix-transmute-valtree-ice branch 2 times, most recently from 9d8c47b to c474d8d Compare January 5, 2026 17:46
.find(|(_, field_def)| name == field_def.name)
.unwrap_or_else(|| panic!("There were no fields named `{name}`."));
fields[field_idx].to_leaf() == ScalarInt::TRUE
match fields[field_idx].try_to_scalar() {
Copy link
Member

Choose a reason for hiding this comment

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

I think .try_to_leaf() == Some(ScalarInt::TRUE) ought to work

Copy link
Member

Choose a reason for hiding this comment

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

or ah, you care about seaprating "non value" from false i guess

Copy link
Member

Choose a reason for hiding this comment

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

i guess try_to_leaf should still work though and remove the Scalar::Int

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to use try_to_leaf() as requested. Thanks for the tip!

@Delta17920 Delta17920 force-pushed the fix-transmute-valtree-ice branch from c474d8d to e603055 Compare January 6, 2026 04:39
@BoxyUwU
Copy link
Member

BoxyUwU commented Jan 6, 2026

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jan 6, 2026

📌 Commit e603055 has been approved by BoxyUwU

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 6, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jan 6, 2026
…ce, r=BoxyUwU

Fix ICE when transmute Assume field is invalid

This PR fixes an internal compiler error in `rustc_transmute` where initializing an `Assume` field (like `alignment`) with a non-scalar constant (like a struct) caused a panic.

The fix updates `from_const` to use `try_to_scalar()` instead of assuming the value is always a leaf. It now gracefully returns `None` for invalid types, allowing the compiler to report standard "missing field initialiser" errors instead of crashing.

Fixes rust-lang#150506
bors added a commit that referenced this pull request Jan 6, 2026
…uwer

Rollup of 11 pull requests

Successful merges:

 - #144113 (Impls and impl items inherit `dead_code` lint level of the corresponding traits and trait items)
 - #148339 (naked functions: emit `.private_extern` on macos)
 - #149880 (rustc_codegen_llvm: update alignment for double on AIX)
 - #150122 (Refactor function names of `rustc_ast_lowering`)
 - #150412 (use PIDFD_GET_INFO ioctl when available)
 - #150670 (THIR pattern building: Move all `thir::Pat` creation into `rustc_mir_build::thir::pattern`)
 - #150695 (MGCA: pretty printing for struct expressions and tuple calls )
 - #150698 (Improve comment clarity in candidate_may_shadow)
 - #150706 (Update wasm-component-ld)
 - #150707 (Fix ICE when transmute Assume field is invalid)
 - #150708 (Enable merge queue in new bors)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jan 6, 2026
Rollup of 11 pull requests

Successful merges:

 - #144113 (Impls and impl items inherit `dead_code` lint level of the corresponding traits and trait items)
 - #148339 (naked functions: emit `.private_extern` on macos)
 - #149880 (rustc_codegen_llvm: update alignment for double on AIX)
 - #150122 (Refactor function names of `rustc_ast_lowering`)
 - #150412 (use PIDFD_GET_INFO ioctl when available)
 - #150670 (THIR pattern building: Move all `thir::Pat` creation into `rustc_mir_build::thir::pattern`)
 - #150695 (MGCA: pretty printing for struct expressions and tuple calls )
 - #150698 (Improve comment clarity in candidate_may_shadow)
 - #150706 (Update wasm-component-ld)
 - #150707 (Fix ICE when transmute Assume field is invalid)
 - #150708 (Enable merge queue in new bors)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jan 6, 2026
…uwer

Rollup of 10 pull requests

Successful merges:

 - #144113 (Impls and impl items inherit `dead_code` lint level of the corresponding traits and trait items)
 - #149880 (rustc_codegen_llvm: update alignment for double on AIX)
 - #150122 (Refactor function names of `rustc_ast_lowering`)
 - #150412 (use PIDFD_GET_INFO ioctl when available)
 - #150670 (THIR pattern building: Move all `thir::Pat` creation into `rustc_mir_build::thir::pattern`)
 - #150695 (MGCA: pretty printing for struct expressions and tuple calls )
 - #150698 (Improve comment clarity in candidate_may_shadow)
 - #150706 (Update wasm-component-ld)
 - #150707 (Fix ICE when transmute Assume field is invalid)
 - #150708 (Enable merge queue in new bors)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 58b1130 into rust-lang:main Jan 6, 2026
11 checks passed
@rustbot rustbot added this to the 1.94.0 milestone Jan 6, 2026
rust-timer added a commit that referenced this pull request Jan 6, 2026
Rollup merge of #150707 - Delta17920:fix-transmute-valtree-ice, r=BoxyUwU

Fix ICE when transmute Assume field is invalid

This PR fixes an internal compiler error in `rustc_transmute` where initializing an `Assume` field (like `alignment`) with a non-scalar constant (like a struct) caused a panic.

The fix updates `from_const` to use `try_to_scalar()` instead of assuming the value is always a leaf. It now gracefully returns `None` for invalid types, allowing the compiler to report standard "missing field initialiser" errors instead of crashing.

Fixes #150506
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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: valtree: expected leaf, got Value

5 participants