-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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 BITS
constant for non-zero integers
#93292
Conversation
r? @yaahc (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
library/core/src/num/nonzero.rs
Outdated
#[doc = concat!("assert_eq!(", stringify!($Ty), "::BITS, ", stringify!($Int), "::BITS);")] | ||
/// ``` | ||
#[unstable(feature = "nonzero_bits", issue = "none")] | ||
pub const BITS: u32 = $BITS; |
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.
Drive-by review: could this just be $Int::BITS
instead of $BITS
? Basically removing $BITS altogether
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 considered implementing it directly in terms of $Int::BITS
but wanted the constant in doctests. After thinking about it for a bit (heh), I'm in favor of this. Especially because it reduces the maintenance burden.
See 870f978.
Looks good, just needs a tracking issue. |
minor thing, since you need another commit for a tracking issue anyway: Consider using this constant on line 468 in the |
Ping from triage: FYI: when a PR is ready for review, post a message containing |
☔ The latest upstream changes (presumably #94834) made this pull request unmergeable. Please resolve the merge conflicts. |
@bors r+ |
📌 Commit 6b5acf0 has been approved by |
…askrgr Rollup of 5 pull requests Successful merges: - rust-lang#93292 (Implement `BITS` constant for non-zero integers) - rust-lang#94777 (Update armv7-unknown-linux-uclibceabi platform support page.) - rust-lang#94816 (Add `Atomic*::get_mut_slice`) - rust-lang#94844 (Reduce rustbuild bloat caused by serde_derive) - rust-lang#94907 (Omit stdarch test crates from the rust-src component) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…r=thomcc Stabilize `nonzero_bits` Closes rust-lang#94881, implemented by rust-lang#93292. This change stabilizes the associated `BITS` constant for `NonZero{U,I}{8,16,32,64,128,size}` integers, e.g.: ```rs impl NonZeroUsize { pub const BITS: u32 = usize::BITS; } ```
This adds the associated
BITS
constant toNonZero{U,I}{8,16,32,64,128,size}
.This is useful when a type alias refers to either a regular or non-zero integer.