-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Implement MIN
/MAX
constants for non-zero integers
#93293
Conversation
r? @scottmcm (rust-highfive has picked a reviewer for you, use r? to override) |
triage: @nvzqz could you address Josh's review? |
Was accidentally placed on unsigned integers, where it is not relevant.
@joshtriplett good catch on the mixup. Fixed and sorry for the delay. |
I may be missing something, but is it possible to implement this without calling unwrap? This lives in the same module as the struct definition; can it just do |
I had tried but there's this error:
I did not want to add |
📌 Commit ecb7927 has been approved by |
@joshtriplett you actually don't need to rely on the optimizer here because it's evaluated as a |
Rollup of 5 pull requests Successful merges: - rust-lang#93293 (Implement `MIN`/`MAX` constants for non-zero integers) - rust-lang#94356 (Rename unix::net::SocketAddr::from_path to from_pathname and stabilize it) - rust-lang#94765 (Rename is_{some,ok,err}_with to is_{some,ok,err}_and.) - rust-lang#94819 (configure: don't serialize empty array elements) - rust-lang#94826 (Improve doc wording for retain on some collections) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…=dtolnay Stabilize `nonzero_min_max` ## Overall Stabilizes `nonzero_min_max` to allow the "infallible" construction of ordinary minimum and maximum `NonZero*` instances. The feature is fairly straightforward and already matured for some time in stable toolchains. ```rust let _ = NonZeroU8::MIN; let _ = NonZeroI32::MAX; ``` ## History * On 2022-01-25, implementation was [created](rust-lang#93293). ## Considerations * This report is fruit of the inanition observed after two unsuccessful attempts at getting feedback. * Other constant variants discussed at rust-lang#89065 (comment) are orthogonal to this feature. Fixes rust-lang#89065
…=dtolnay Stabilize `nonzero_min_max` ## Overall Stabilizes `nonzero_min_max` to allow the "infallible" construction of ordinary minimum and maximum `NonZero*` instances. The feature is fairly straightforward and already matured for some time in stable toolchains. ```rust let _ = NonZeroU8::MIN; let _ = NonZeroI32::MAX; ``` ## History * On 2022-01-25, implementation was [created](rust-lang#93293). ## Considerations * This report is fruit of the inanition observed after two unsuccessful attempts at getting feedback. * Other constant variants discussed at rust-lang#89065 (comment) are orthogonal to this feature. Fixes rust-lang#89065
Stabilize `nonzero_min_max` ## Overall Stabilizes `nonzero_min_max` to allow the "infallible" construction of ordinary minimum and maximum `NonZero*` instances. The feature is fairly straightforward and already matured for some time in stable toolchains. ```rust let _ = NonZeroU8::MIN; let _ = NonZeroI32::MAX; ``` ## History * On 2022-01-25, implementation was [created](rust-lang/rust#93293). ## Considerations * This report is fruit of the inanition observed after two unsuccessful attempts at getting feedback. * Other constant variants discussed at rust-lang/rust#89065 (comment) are orthogonal to this feature. Fixes rust-lang/rust#89065
This adds the associated
MIN
/MAX
constants toNonZero{U,I}{8,16,32,64,128,size}
, requested in #89065.This reimplements #89077 due that PR being stagnant for 4 months. I am fine with closing this in favor of that one if the author revisits it. If so, I'd like to see that PR have the docs link to the
$Int
's constants.