Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: transmute: implement FromBytes and AsBytes for inhabited ZSTs

This is useful when using types that may or may not be empty in generic
code relying on these traits. It is also safe because technically a
no-op.

Reviewed-by: Alistair Popple <apopple@nvidia.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Link: https://patch.msgid.link/20251215-transmute_unit-v4-1-477d71ec7c23@nvidia.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

authored by

Alexandre Courbot and committed by
Miguel Ojeda
209c7095 7f87c7a0

+8
+8
rust/kernel/transmute.rs
··· 170 170 } 171 171 172 172 impl_frombytes! { 173 + // SAFETY: Inhabited ZSTs only have one possible bit pattern, and these two have no invariant. 174 + (), 175 + {<T>} core::marker::PhantomData<T>, 176 + 173 177 // SAFETY: All bit patterns are acceptable values of the types below. 174 178 u8, u16, u32, u64, usize, 175 179 i8, i16, i32, i64, isize, ··· 234 230 } 235 231 236 232 impl_asbytes! { 233 + // SAFETY: Inhabited ZSTs only have one possible bit pattern, and these two have no invariant. 234 + (), 235 + {<T>} core::marker::PhantomData<T>, 236 + 237 237 // SAFETY: Instances of the following types have no uninitialized portions. 238 238 u8, u16, u32, u64, usize, 239 239 i8, i16, i32, i64, isize,