-
Notifications
You must be signed in to change notification settings - Fork 14k
style: Use binary literals instead of hex literals in doctests for highest_one and lowest_one
#148520
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
style: Use binary literals instead of hex literals in doctests for highest_one and lowest_one
#148520
Conversation
|
I was going to agree, but with more repeating ones the benefits of hex start to appear. This is also one of the test cases: assert_eq!(0x1f_u64.highest_one(), Some(4));Instead of: assert_eq!(0b11111_u64.highest_one(), Some(4)); |
|
@hkBst When the value has many digits, hex literals are easier to understand: assert_eq!(0x10000000_u64.highest_one(), Some(28));
assert_eq!(0b10000000000000000000000000000_u64.highest_one(), Some(28));
assert_eq!(0x1fffffff_u64.highest_one(), Some(28));
assert_eq!(0b11111111111111111111111111111_u64.highest_one(), Some(28));However, the binary literals in the doctests are at most five digits long, so I think they are easier to understand than hex literals. |
|
I'd use underscores to split up the nibbles, e.g. |
For me 5 ones in a row is already over the limit of what I can easily glance. tgross35's suggestion of adding underscores would help with that though... |
|
Squash please then r=me |
Use binary literals instead of hex literals.
ad63721 to
d956fa1
Compare
|
Added underscores to binary literals longer than 4 digits:
|
|
r? tgross35 |
Rollup of 12 pull requests Successful merges: - #145768 (Offload device) - #145992 (Stabilize `vec_deque_pop_if`) - #147416 (Early return if span is from expansion so we dont get empty span and ice later on) - #147808 (btree: cleanup difference, intersection, is_subset) - #148520 (style: Use binary literals instead of hex literals in doctests for `highest_one` and `lowest_one`) - #148559 (Add typo suggestion for a misspelt Cargo environment variable) - #148567 (Fix incorrect precedence caused by range expression) - #148570 (Fix mismatched brackets in generated .dir-locals.el) - #148575 (fix dev guide link in rustc_query_system/dep_graph/README.md) - #148578 (core docs: add notes about availability of `Atomic*::from_mut_slice`) - #148603 (Backport 1.91.1 relnotes to main) - #148609 (Sync str::rsplit_once example with str::split_once) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #148520 - sorairolake:update-lowest-highest-one-doctests, r=tgross35 style: Use binary literals instead of hex literals in doctests for `highest_one` and `lowest_one` For example, I think it's easier to understand that the index of the highest bit set to one in `16` is `4` as `0b10000` than as `0x10`. ```rust assert_eq!(0x10_u64.highest_one(), Some(4)); ``` Instead of: ```rust assert_eq!(0b10000_u64.highest_one(), Some(4)); ``` #145203
For example, I think it's easier to understand that the index of the highest bit set to one in
16is4as0b10000than as0x10.Instead of:
#145203