Skip to content

implement ZeroableOption for NonZero* types#110

Open
Hamdan-Khan wants to merge 1 commit intoRust-for-Linux:mainfrom
Hamdan-Khan:main
Open

implement ZeroableOption for NonZero* types#110
Hamdan-Khan wants to merge 1 commit intoRust-for-Linux:mainfrom
Hamdan-Khan:main

Conversation

@Hamdan-Khan
Copy link

add a macro for implementing ZeroableOption for NonZero* integer types instead of using Option<NonZero*> inside zeroable macro

issue: #95

Copy link
Member

@BennoLossin BennoLossin left a comment

Choose a reason for hiding this comment

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

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 {})*
Copy link
Member

Choose a reason for hiding this comment

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

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.

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,
);
Copy link
Member

Choose a reason for hiding this comment

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

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>
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.

2 participants