Skip to content

Commit e08f6d4

Browse files
committed
switch from using leading zeros to trailing zeros
1 parent 398cd2d commit e08f6d4

File tree

1 file changed

+4
-1
lines changed
  • src/tools/rust-analyzer/crates/ide/src/hover

1 file changed

+4
-1
lines changed

src/tools/rust-analyzer/crates/ide/src/hover/render.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,9 +1235,12 @@ fn is_pwr2plus1(val: u128) -> bool {
12351235
val != 0 && is_pwr2(val - 1)
12361236
}
12371237

1238+
/// Formats a power of two as an exponent of two, i.e. 16 => ⁴. Note that `num` MUST be a power
1239+
/// of 2, or this function will panic.
12381240
fn pwr2_to_exponent(num: u128) -> String {
12391241
const DIGITS: [char; 10] = ['⁰', '¹', '²', '³', '⁴', '⁵', '⁶', '⁷', '⁸', '⁹'];
1240-
(127 - num.leading_zeros())
1242+
assert_eq!(num.count_ones(), 1);
1243+
num.trailing_zeros()
12411244
.to_string()
12421245
.chars()
12431246
.map(|c| c.to_digit(10).unwrap() as usize)

0 commit comments

Comments
 (0)