You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let single_u64:&[u64] = &[0xDEAD_BEEF_DEAD_BEEF];let bools:&[bool] = unsafe{ std::mem::transmute(single_u64)};assert_eq!(bools.len(),64);
but this is not true, because transmute does not change slice length.
this contains UB: Every integral value except 0 or 1 cannot be bool.
this also contains error-prone: bool's alignment is 1-byte, which may be surprizing if user thought bool is 1-bit (formally size_of::<[T; N]>() == size_of::<[bool; N * size_of::<T>]>()).
Lint Name
transmute_slice_to_bool_slice
Category
correctness, suspicious
Advantage
Removes potential UB.
Prevents error-prone.
Drawbacks
No response
Example
let single_u64:&[u64] = &[0xDEAD_BEEF_DEAD_BEEF];let bools:&[bool] = unsafe{ std::mem::transmute(single_u64)};
What it does
consider following example:
but this is not true, because transmute does not change slice length.
this contains UB: Every integral value except
0
or1
cannot bebool
.this also contains error-prone:
bool
's alignment is 1-byte, which may be surprizing if user thought bool is 1-bit (formallysize_of::<[T; N]>() == size_of::<[bool; N * size_of::<T>]>()
).Lint Name
transmute_slice_to_bool_slice
Category
correctness, suspicious
Advantage
Drawbacks
No response
Example
may be written as:
but miri reports this code as an UB.
The text was updated successfully, but these errors were encountered: