-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Implemented MIN and MAX constants for the non-zero integer types.#89065 #89077
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
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0156ef1
Max working.
mjclements b5c1fe1
nonzero min and nonzero max working.
mjclements 84d88f2
Fixed some formatting issues.
mjclements b274022
Made a macro name consistent.
mjclements 0f84d19
Fixed variable name _properly_
mjclements 279f0bf
Fixed build errors.
mjclements 591b89d
Addressing PR Comment.
mjclements 56ce3a2
Removed {unsafe} since we are in constant context.
mjclements 3cbfdec
Split macro, added documentation.
mjclements 7a718e1
Trailing ws.
mjclements 87d92f9
Tidy cleanup comment, trailing WS
mjclements 2fecb01
Update library/core/src/num/nonzero.rs
mjclements 5b48c54
Cleaned up some documentation.
mjclements 5ac53ef
Fixes missing parenthesis in doc test.
mjclements File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -895,3 +895,75 @@ macro_rules! nonzero_unsigned_is_power_of_two { | |
} | ||
|
||
nonzero_unsigned_is_power_of_two! { NonZeroU8 NonZeroU16 NonZeroU32 NonZeroU64 NonZeroU128 NonZeroUsize } | ||
|
||
macro_rules! nonzero_constants_signed { | ||
( $( $Ty: ident($Int: ty); )+ ) => { | ||
$( | ||
impl $Ty { | ||
#[unstable(feature = "nonzero_min_max", issue = "89065")] | ||
#[doc = concat!("The maximum value for a `", stringify!($Ty), "` is the same as `", stringify!($Int), "`.")] | ||
/// # Examples | ||
/// | ||
/// ``` | ||
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MAX, ", stringify!($Int), "::MAX);")] | ||
/// ``` | ||
pub const MAX : $Ty = $Ty::new(<$Int>::MAX).unwrap(); | ||
#[unstable(feature = "nonzero_min_max", issue = "89065")] | ||
#[doc = concat!("The minimum value for a `", stringify!($Ty), " `.")] | ||
/// # Examples | ||
/// | ||
/// ``` | ||
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MIN, ", stringify!($Int), "::MIN);")] | ||
/// ``` | ||
pub const MIN : $Ty = $Ty::new(<$Int>::MIN).unwrap(); | ||
} | ||
)+ | ||
} | ||
} | ||
|
||
nonzero_constants_signed! { | ||
NonZeroI8(i8); | ||
NonZeroI16(i16); | ||
NonZeroI32(i32); | ||
NonZeroI64(i64); | ||
NonZeroI128(i128); | ||
NonZeroIsize(isize); | ||
} | ||
|
||
macro_rules! nonzero_constants_unsigned{ | ||
( $( $Ty: ident($Int: ty); )+ ) => { | ||
$( | ||
impl $Ty { | ||
#[unstable(feature = "nonzero_min_max", issue = "89065")] | ||
#[doc = concat!("The maximum value for a `", stringify!($Ty), "` is the same as `", stringify!($Int), "`.")] | ||
/// Note: While most integer types are defined for every whole number between MIN and | ||
/// MAX, signed non-zero integers are a special case. They have a 'gap' at 0. | ||
/// # Examples | ||
/// | ||
/// ``` | ||
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MAX, ", stringify!($Int), "::MAX);")] | ||
/// ``` | ||
pub const MAX : $Ty = $Ty::new(<$Int>::MAX).unwrap() ; | ||
#[unstable(feature = "nonzero_min_max", issue = "89065")] | ||
#[doc = concat!("The minimum value for a `", stringify!($Ty), "`.")] | ||
/// Note: While most integer types are defined for every whole number between MIN and | ||
/// MAX, signed non-zero integers are a special case. They have a 'gap' at 0. | ||
/// # Examples | ||
/// | ||
/// ``` | ||
#[doc = concat!("assert_eq!(", stringify!($Ty), "::MIN, ", stringify!($Int), "::MIN);")] | ||
/// ``` | ||
pub const MIN : $Ty = $Ty::new(1).unwrap(); | ||
} | ||
)+ | ||
} | ||
} | ||
|
||
nonzero_constants_unsigned! { | ||
NonZeroU8(u8); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation mismatch here. |
||
NonZeroU16(u16); | ||
NonZeroU32(u32); | ||
NonZeroU64(u64); | ||
NonZeroU128(u128); | ||
NonZeroUsize(usize); | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this and the below example need a ``` ... ``` code block, for formatting (though they're not very interesting as doctests).
I think including some blank lines as done above for
nonzero_unsigned_signed_operations
(such as ``` above and below the Examples header, and a normal blank line between the MAX and MIN definitions) but before would also make the macro code more readable even if it doesn't affect the documentation output.