implement ZeroableOption for NonZero* types#110
Open
Hamdan-Khan wants to merge 1 commit intoRust-for-Linux:mainfrom
Open
implement ZeroableOption for NonZero* types#110Hamdan-Khan wants to merge 1 commit intoRust-for-Linux:mainfrom
Hamdan-Khan wants to merge 1 commit intoRust-for-Linux:mainfrom
Conversation
BennoLossin
requested changes
Feb 27, 2026
Member
BennoLossin
left a comment
There was a problem hiding this comment.
Thanks a lot for the PR!
Please use the kernel's commit message style. So give a motivation in addition to explaining what the change is.
We also don't use the issue: tag. Instead use Link:.
Please also mention this change in the changelog.
| ($($int:ty),* $(,)?) => { | ||
| // SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee: | ||
| // <https://doc.rust-lang.org/stable/std/option/index.html#representation>). | ||
| $(unsafe impl ZeroableOption for $int {})* |
Member
There was a problem hiding this comment.
This safety comment should go next to the NonZero* types instead of being here. You should still keep a safety comment here though, similar to the impl_zeroable! definition.
BennoLossin
reviewed
Feb 27, 2026
src/lib.rs
Outdated
Comment on lines
1668
to
1671
| impl_non_zero_int_zeroable_option!( | ||
| NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU128, NonZeroUsize, | ||
| NonZeroI8, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI128, NonZeroIsize, | ||
| ); |
Member
There was a problem hiding this comment.
Also use {} instead of (), since otherwise rustfmt will try to format this to be one line per item.
add a macro for implementing `ZeroableOption` for `NonZero*` integer types instead of using `Option<T>` wrapper, which was previously implemented for each `NonZero` type individually inside the `impl_zeroable` macro. Link: Rust-for-Linux#95 Signed-off-by: Hamdan-Khan <hamdankhan212@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
add a macro for implementing ZeroableOption for NonZero* integer types instead of using Option<NonZero*> inside zeroable macro
issue: #95