Skip to content

Cleanup Zeroable and ZeroableOptions.#118

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

Cleanup Zeroable and ZeroableOptions.#118
nbdd0121 merged 3 commits into
Rust-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
nbdd0121 added a commit to nbdd0121/linux that referenced this pull request Apr 27, 2026
This series collects all upstream developments of pin-init to date and
synchronize them to the kernel tree.

A major change in this cycle is the bump of MSRV to 1.82 to get rid of
unstable features, following the kernel version bump in 7.1. The MSRV is
bumped straight to 1.85 as pin-init can also be used outside kernel, so we
avoid bumping unless there is a need for new version.

Here are the list of merged changes included in the series:

- examples: mark as `#[inline]` all `From::from()`s for `Error`
  Rust-for-Linux/pin-init#126
- bump minimum Rust version to 1.82
  Rust-for-Linux/pin-init#129
- cleanup `Zeroable` and `ZeroableOptions`
  Rust-for-Linux/pin-init#118
- internal: add missing where clause to projection types
  Rust-for-Linux/pin-init#121
- internal: internal: remove redundant `#[pin]` filtering
  Rust-for-Linux/pin-init#131

For information, here are the list of upstream-only changes, which are
related to Cargo or tests/CI changes only.

- build.rs: use `option_env!` to register env variable dependency
  Rust-for-Linux/pin-init#128
- clean up dependencies
  Rust-for-Linux/pin-init#130
- tests: add test for check correct macro hygiene 
  Rust-for-Linux/pin-init#133
- ci: use tagged release of actions
  Rust-for-Linux/pin-init#134
- ci: have a single job to gate all required jobs
  Rust-for-Linux/pin-init#138

Best,
Gary

--- b4-submit-tracking ---
# This section is used internally by b4 prep for tracking purposes.
{
  "series": {
    "revision": 1,
    "change-id": "20260414-pin-init-sync-ae407945a726",
    "prefixes": [],
    "presubject": ""
  }
}
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