Unnamed repository; edit this file 'description' to name the repository.
make large niche description more terse, switch to using u128::is_power_of_two
Luuk Wester 2025-01-21
parent 57bd824 · commit 6b6e019
-rw-r--r--crates/ide/src/hover/render.rs8
-rw-r--r--crates/ide/src/hover/tests.rs2
2 files changed, 5 insertions, 5 deletions
diff --git a/crates/ide/src/hover/render.rs b/crates/ide/src/hover/render.rs
index 7fe344cfa4..95be7c5618 100644
--- a/crates/ide/src/hover/render.rs
+++ b/crates/ide/src/hover/render.rs
@@ -1090,7 +1090,7 @@ fn render_memory_layout(
} else if is_pwr2minus1(niches) {
format_to!(label, "niches = 2{} - 1, ", pwr2_to_exponent(niches + 1));
} else {
- format_to!(label, "niches = really rather quite large, ");
+ format_to!(label, "niches = a lot, ");
}
} else {
format_to!(label, "niches = {niches}, ");
@@ -1224,15 +1224,15 @@ fn render_dyn_compatibility(
}
fn is_pwr2(val: u128) -> bool {
- val.count_ones() == 1
+ val.is_power_of_two()
}
fn is_pwr2minus1(val: u128) -> bool {
- val == u128::MAX || (val + 1).count_ones() == 1
+ val == u128::MAX || is_pwr2(val + 1)
}
fn is_pwr2plus1(val: u128) -> bool {
- val != 0 && (val - 1).count_ones() == 1
+ val != 0 && is_pwr2(val - 1)
}
fn pwr2_to_exponent(num: u128) -> String {
diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs
index 63eb772fde..064a845dc5 100644
--- a/crates/ide/src/hover/tests.rs
+++ b/crates/ide/src/hover/tests.rs
@@ -1357,7 +1357,7 @@ fn hover_enum_limit() {
---
- size = 12 (0xC), align = 4, niches = really rather quite large
+ size = 12 (0xC), align = 4, niches = a lot
"#]],
);
}