mirror of
https://github.com/torvalds/linux.git
synced 2026-03-14 00:56:20 +01:00
rust: pin-init: implement ZeroableOption for &T and &mut T
`Option<&T>` and `Option<&mut T>` are documented [1] to have the `None` variant be all zeroes. Link: https://doc.rust-lang.org/stable/std/option/index.html#representation [1] Link: https://github.com/Rust-for-Linux/pin-init/pull/56/commits/5ef1638c79e019d3dc0c62db5905601644c2e60a Link: https://lore.kernel.org/all/20250523145125.523275-5-lossin@kernel.org Signed-off-by: Benno Lossin <lossin@kernel.org>
This commit is contained in:
parent
d67b370120
commit
e93a238605
1 changed files with 7 additions and 0 deletions
|
|
@ -1546,6 +1546,13 @@ pub unsafe trait ZeroableOption {}
|
|||
// SAFETY: by the safety requirement of `ZeroableOption`, this is valid.
|
||||
unsafe impl<T: ZeroableOption> Zeroable for Option<T> {}
|
||||
|
||||
// SAFETY: `Option<&T>` is part of the option layout optimization guarantee:
|
||||
// <https://doc.rust-lang.org/stable/std/option/index.html#representation>.
|
||||
unsafe impl<T> ZeroableOption for &T {}
|
||||
// SAFETY: `Option<&mut T>` is part of the option layout optimization guarantee:
|
||||
// <https://doc.rust-lang.org/stable/std/option/index.html#representation>.
|
||||
unsafe impl<T> ZeroableOption for &mut T {}
|
||||
|
||||
/// Create an initializer for a zeroed `T`.
|
||||
///
|
||||
/// The returned initializer will write `0x00` to every byte of the given `slot`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue