Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate all associated items on the NonZero integer types into a single impl block per type #118665

Merged
merged 18 commits into from
Jan 19, 2024
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
56df3bb
Move nonzero_integers macro call to bottom of module
dtolnay Dec 6, 2023
54cb822
Define only a single NonZero type per macro call
dtolnay Dec 6, 2023
9196d2a
Unindent nonzero_integer macro body
dtolnay Dec 6, 2023
a6152cd
Format nonzero_integer macro calls same way we do the primitive int i…
dtolnay Dec 6, 2023
3de0af1
Move 'impl FromStr for NonZero' into nonzero_integer macro
dtolnay Dec 6, 2023
81e1a7c
Move impl Div and Rem into nonzero_integer macro
dtolnay Dec 6, 2023
a78d9a6
Unindent nonzero_integer_impl_div_rem macro body
dtolnay Dec 6, 2023
f846ed5
Move leading_zeros and trailing_zeros methods into nonzero_integer macro
dtolnay Dec 6, 2023
757ed25
Move Neg impl into the macro that generates Div and Rem
dtolnay Dec 6, 2023
4291b3f
Move signedness dependent methods into the omnibus impl block
dtolnay Dec 6, 2023
b21b9cc
Unindent nonzero_integer_signedness_dependent_methods macro body
dtolnay Dec 6, 2023
c6d776e
Work around rustfmt doc attribute indentation bug
dtolnay Dec 6, 2023
63256af
Move nonzero_unsigned_signed_operations methods into the omnibus impl…
dtolnay Dec 6, 2023
4419136
Move is_power_of_two into unsigned part of signedness_dependent_methods
dtolnay Dec 6, 2023
7f7c5af
Move unsigned MIN and MAX into signedness_dependent_methods
dtolnay Dec 6, 2023
66cda3b
Move signed MIN and MAX into signedness_dependent_methods
dtolnay Dec 6, 2023
c537132
Move BITS into omnibus impl block
dtolnay Dec 6, 2023
cdee1fe
Unbreak tidy's feature parser
dtolnay Dec 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Move nonzero_integers macro call to bottom of module
This way all the other macros defined in this module, such as
nonzero_leading_trailing_zeros, are available to call within the expansion of
nonzero_integers.

(Macros defined by macro_rules cannot be called from the same module above the
location of the macro_rules.)

In this commit the ability to call things like nonzero_leading_trailing_zeros is
not immediately used, but later commits in this stack will be consolidating the
entire API of NonZeroT to be generated through nonzero_integers, and will need
to make use of some of the other macros to do that.
  • Loading branch information
dtolnay committed Jan 14, 2024
commit 56df3bb70d808d535e46f1c017bafeccbbf1cb6d
30 changes: 15 additions & 15 deletions library/core/src/num/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,21 +190,6 @@ macro_rules! nonzero_integers {
}
}

nonzero_integers! {
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU8(u8);
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU16(u16);
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU32(u32);
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU64(u64);
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU128(u128);
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroUsize(usize);
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI8(i8);
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI16(i16);
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI32(i32);
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI64(i64);
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI128(i128);
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroIsize(isize);
}

macro_rules! from_str_radix_nzint_impl {
($($t:ty)*) => {$(
#[stable(feature = "nonzero_parse", since = "1.35.0")]
Expand Down Expand Up @@ -1396,3 +1381,18 @@ nonzero_bits! {
NonZeroUsize(usize);
NonZeroIsize(isize);
}

nonzero_integers! {
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU8(u8);
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU16(u16);
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU32(u32);
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU64(u64);
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroU128(u128);
#[stable(feature = "nonzero", since = "1.28.0")] #[rustc_const_stable(feature = "nonzero", since = "1.28.0")] NonZeroUsize(usize);
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI8(i8);
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI16(i16);
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI32(i32);
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI64(i64);
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroI128(i128);
#[stable(feature = "signed_nonzero", since = "1.34.0")] #[rustc_const_stable(feature = "signed_nonzero", since = "1.34.0")] NonZeroIsize(isize);
}