Skip to content

Comments

Fix ICE in try_to_raw_bytes when array elements have mismatched#152794

Open
reddevilmidzy wants to merge 1 commit intorust-lang:mainfrom
reddevilmidzy:mgca-print
Open

Fix ICE in try_to_raw_bytes when array elements have mismatched#152794
reddevilmidzy wants to merge 1 commit intorust-lang:mainfrom
reddevilmidzy:mgca-print

Conversation

@reddevilmidzy
Copy link
Member

@reddevilmidzy reddevilmidzy commented Feb 18, 2026

close: #152683

After #152001, suffixed integer literals preserve their own type during const lowering, so try_to_raw_bytes could call .to_u8() on a scalar with size > 1, causing an ICE. Fix by using try_to_bits(Size::from_bytes(1)).ok() instead.

r? BoxyUwU

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 18, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 18, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 18, 2026

BoxyUwU is currently at their maximum review capacity.
They may take a while to respond.

@reddevilmidzy
Copy link
Member Author

reddevilmidzy commented Feb 19, 2026

Ah, it seems like the issue is resolved in #152492, but would it be better to revert the change to try_to_raw_bytes and just add the test?

The error changes like this:

#![expect(incomplete_features)]
#![feature(adt_const_params, generic_const_parameter_types, min_generic_const_args)]
fn foo<const N: usize, const A: [u8; N]>() {}

fn main() {
    foo::<_, { [0, 1u8, 2u32, 8u64] }>();
    //~^ ERROR the constant `8` is not of type `u8`
    //~| ERROR the constant `2` is not of type `u8`
}

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]: expected int of size 1, but got size 8

3 participants