Skip to content

Conversation

@sorairolake
Copy link
Contributor

@sorairolake sorairolake commented Nov 5, 2025

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.

assert_eq!(0x10_u64.highest_one(), Some(4));

Instead of:

assert_eq!(0b10000_u64.highest_one(), Some(4));

#145203

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 5, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 5, 2025

r? @scottmcm

rustbot has assigned @scottmcm.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@hkBst
Copy link
Member

hkBst commented Nov 5, 2025

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));

@sorairolake
Copy link
Contributor Author

@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.

@tgross35
Copy link
Contributor

tgross35 commented Nov 5, 2025

I'd use underscores to split up the nibbles, e.g. 0b1_1111_u32

@hkBst
Copy link
Member

hkBst commented Nov 6, 2025

@hkBst When the value has many digits, hex literals are easier to understand:
However, the binary literals in the doctests are at most five digits long, so I think they are easier to understand than hex literals.

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...

@tgross35
Copy link
Contributor

tgross35 commented Nov 6, 2025

Squash please then r=me

Use binary literals instead of hex literals.
@sorairolake sorairolake force-pushed the update-lowest-highest-one-doctests branch from ad63721 to d956fa1 Compare November 6, 2025 11:08
@sorairolake
Copy link
Contributor Author

Added underscores to binary literals longer than 4 digits:

  • 0b10000 to 0b1_0000
  • 0b11111 to 0b1_1111

@tgross35
Copy link
Contributor

tgross35 commented Nov 6, 2025

r? tgross35
@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Nov 6, 2025

📌 Commit d956fa1 has been approved by tgross35

It is now in the queue for this repository.

@rustbot rustbot assigned tgross35 and unassigned scottmcm Nov 6, 2025
@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 6, 2025
bors added a commit that referenced this pull request Nov 7, 2025
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
@bors bors merged commit 3d765e3 into rust-lang:master Nov 7, 2025
11 checks passed
@rustbot rustbot added this to the 1.93.0 milestone Nov 7, 2025
rust-timer added a commit that referenced this pull request Nov 7, 2025
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
@sorairolake sorairolake deleted the update-lowest-highest-one-doctests branch November 7, 2025 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants