Skip to content

Cleanup Zeroable and ZeroableOptions.#118

Merged
nbdd0121 merged 3 commits intoRust-for-Linux:mainfrom
mqqz:cleanup-zeroable
Apr 22, 2026
Merged

Cleanup Zeroable and ZeroableOptions.#118
nbdd0121 merged 3 commits intoRust-for-Linux:mainfrom
mqqz:cleanup-zeroable

Conversation

@mqqz
Copy link
Copy Markdown
Contributor

@mqqz mqqz commented Mar 10, 2026

Did my part of janitor work to help cleanup Zeroable and ZeroableOption as suggested in #116:

  • Ensure consistency in placement: put the Zeroable trait and its implementations (including macro invocations) first in the relevant section of src/lib.rs, followed by the ZeroableOption trait and its implementations.
  • One of the macros is currently named impl_non_zero_int_zeroable_option; it should be renamed to impl_zeroable_option for consistency.
  • Use the impl_zeroable_option macro to handle generic impls for types like &T, &mut T, NonNull<T>, and others (for which Option<T> is guaranteed to be zeroable).

Added an extra commit for minimal testing which I'm not sure how helpful it is but feel free to not include:

  • tests/zeroing.rs coverage that zeroed::<Option<T>>() is None for refs, NonNull, and nonzero ints.
  • generic compile-check coverage for T: ZeroableOption (&u8, &mut u8, NonNull<u8>, NonZeroU8).
  • UI compile-fail test zeroable/option_string_not_zeroable.rs to verify Option<String> is not Zeroable.

Closes: #116

Copy link
Copy Markdown
Member

@nbdd0121 nbdd0121 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits, mostly LGTM

Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
mqqz added 3 commits April 22, 2026 11:47
Place definitions and implementations (incl. macro invocations) of
the `Zeroable` trait first in the relevant section of `src/lib.rs`,
followed by the ZeroableOption trait and its implementations.

Rename `impl_non_zero_int_zeroable_option` to `impl_zeroable_option`
for consistency.

This commit should not introduce any functional changes.

Signed-off-by: Mohamad Alsadhan <mo@sdhn.cc>
Improve impl_zeroable_option macro to handle generic impls for types
like `&T`, `&mut T`, `NonNull<T>`, and others (for which `Option<T>`
is guaranteed to be zeroable) with similar approach to
`impl_zeroable`.

Also, update old declarations to use generics e.g. `NonZeroU8` to
`NonZero<u8>`.

Signed-off-by: Mohamad Alsadhan <mo@sdhn.cc>
Minimal testing including:
- add `tests/zeroing.rs` coverage that `zeroed::<Option<T>>()` is
  `None` for refs, `NonNull`, and nonzero ints.
- add generic compile-check coverage for `T: ZeroableOption` (`&u8`,
  `&mut u8`, `NonNull<u8>`, `NonZeroU8`).
- add UI compile-fail test `zeroable/option_string_not_zeroable.rs`
  to verify `Option<String>` is not `Zeroable`.

Not entirely sure how useful these tests are but it's on a different
commit so feel free to not include them.

Signed-off-by: Mohamad Alsadhan <mo@sdhn.cc>
@mqqz mqqz force-pushed the cleanup-zeroable branch from b550439 to 965d503 Compare April 22, 2026 08:55
@nbdd0121 nbdd0121 merged commit bce69a8 into Rust-for-Linux:main Apr 22, 2026
26 checks passed
@nbdd0121
Copy link
Copy Markdown
Member

Thanks!

@mqqz mqqz deleted the cleanup-zeroable branch April 24, 2026 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Cleanup macros around Zeroable & ZeroableOption

2 participants