Fix ICE in try_to_raw_bytes when array elements have mismatched#152794
Fix ICE in try_to_raw_bytes when array elements have mismatched#152794reddevilmidzy wants to merge 1 commit intorust-lang:mainfrom
try_to_raw_bytes when array elements have mismatched#152794Conversation
|
|
|
Ah, it seems like the issue is resolved in #152492, but would it be better to revert the change to 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`
} |
|
Hmm, I would expect it to still be possible to get this ICE somehow even with #152492 🤔 I'm not sure exactly what that would look like though. The underlying problem here remains that we assume nested valtrees are correct for the parent valtree's type. Even if we check in wfcheck whether this is the case or not diagnostics will still need to handle such illformed valtrees correctly and I expect diagnostics to be calling this function |
|
Though there's also #152906 which may have interactions here 🤔 Though probably not... |
#![expect(incomplete_features)]
#![feature(adt_const_params, min_generic_const_args)]
struct ArrWrap<const N: [u8; 1]>;
fn main() {
let _: ArrWrap<{ [1_u8] }>
= ArrWrap::<{ [1_u16] }>;
}does this ICE even with #152492? |
|
@rustbot author |
#152492 did not cover this case (ICE occurred even when 152492 was applied), and this PR seems to solve it. |
That makes sense, thanks! |
8b56fa0 to
2c70889
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
| // `&str` can be interpreted as raw bytes | ||
| ty::Str => {} | ||
| // `&[u8]` can be interpreted as raw bytes | ||
| ty::Slice(slice_ty) if *slice_ty == tcx.types.u8 => {} |
There was a problem hiding this comment.
these checks for tcx.types.u8 are effectively meaningless under mGCA i think.
| let iterator = self | ||
| .to_branch() | ||
| .into_iter() | ||
| .map(|ct| ct.try_to_leaf()?.try_to_bits(Size::from_bytes(1)).ok().map(|b| b as u8)); |
There was a problem hiding this comment.
can you instead check that the type of the of the element ty::Value is u8 then call to_u8? I expect we don't want to let this function succeed for an array of 1-byte sized ADTs wrapping a u8
close: #152683
After #152001, suffixed integer literals preserve their own type during const lowering, so
try_to_raw_bytescould call.to_u8()on a scalar with size > 1, causing an ICE. Fix by usingtry_to_bits(Size::from_bytes(1)).ok()instead.r? BoxyUwU