Skip to content

Commit d8553c9

Browse files
committed
remove is_pwr2
1 parent e08f6d4 commit d8553c9

File tree

1 file changed

+3
-17
lines changed
  • src/tools/rust-analyzer/crates/ide/src/hover

1 file changed

+3
-17
lines changed

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

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ fn render_memory_layout(
10831083
if config.niches {
10841084
if let Some(niches) = layout.niches() {
10851085
if niches > 1024 {
1086-
if is_pwr2(niches) {
1086+
if niches.is_power_of_two() {
10871087
format_to!(label, "niches = 2{}, ", pwr2_to_exponent(niches));
10881088
} else if is_pwr2plus1(niches) {
10891089
format_to!(label, "niches = 2{} + 1, ", pwr2_to_exponent(niches - 1));
@@ -1223,16 +1223,12 @@ fn render_dyn_compatibility(
12231223
}
12241224
}
12251225

1226-
fn is_pwr2(val: u128) -> bool {
1227-
val.is_power_of_two()
1228-
}
1229-
12301226
fn is_pwr2minus1(val: u128) -> bool {
1231-
val == u128::MAX || is_pwr2(val + 1)
1227+
val == u128::MAX || (val + 1).is_power_of_two()
12321228
}
12331229

12341230
fn is_pwr2plus1(val: u128) -> bool {
1235-
val != 0 && is_pwr2(val - 1)
1231+
val != 0 && (val - 1).is_power_of_two()
12361232
}
12371233

12381234
/// Formats a power of two as an exponent of two, i.e. 16 => ⁴. Note that `num` MUST be a power
@@ -1254,16 +1250,6 @@ mod tests {
12541250

12551251
const TESTERS: [u128; 10] = [0, 1, 2, 3, 4, 255, 256, 257, u128::MAX - 1, u128::MAX];
12561252

1257-
#[test]
1258-
fn test_is_pwr2() {
1259-
const OUTCOMES: [bool; 10] =
1260-
[false, true, true, false, true, false, true, false, false, false];
1261-
for (test, expected) in TESTERS.iter().zip(OUTCOMES) {
1262-
let actual = is_pwr2(*test);
1263-
assert_eq!(actual, expected, "is_pwr2({test}) gave {actual}, expected {expected}");
1264-
}
1265-
}
1266-
12671253
#[test]
12681254
fn test_is_pwr2minus1() {
12691255
const OUTCOMES: [bool; 10] =

0 commit comments

Comments
 (0)