diff options
| author | Luuk Wester <luuk.wester@gmail.com> | 2025-01-21 14:47:07 +0100 |
|---|---|---|
| committer | Luuk Wester <luuk.wester@gmail.com> | 2025-01-21 14:47:07 +0100 |
| commit | d8553c9c056d8f8f206dc3910e6c6256302b7e35 (patch) | |
| tree | 8ef30a8a078739d86591875d6c5f9f777a05ba0d | |
| parent | e08f6d45305617b180856ae75969aac6c0db3a80 (diff) | |
| download | rust-d8553c9c056d8f8f206dc3910e6c6256302b7e35.tar.gz rust-d8553c9c056d8f8f206dc3910e6c6256302b7e35.zip | |
remove is_pwr2
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide/src/hover/render.rs | 20 |
1 files changed, 3 insertions, 17 deletions
diff --git a/src/tools/rust-analyzer/crates/ide/src/hover/render.rs b/src/tools/rust-analyzer/crates/ide/src/hover/render.rs index fb7c2904afc..40f3406b72d 100644 --- a/src/tools/rust-analyzer/crates/ide/src/hover/render.rs +++ b/src/tools/rust-analyzer/crates/ide/src/hover/render.rs @@ -1083,7 +1083,7 @@ fn render_memory_layout( if config.niches { if let Some(niches) = layout.niches() { if niches > 1024 { - if is_pwr2(niches) { + if niches.is_power_of_two() { format_to!(label, "niches = 2{}, ", pwr2_to_exponent(niches)); } else if is_pwr2plus1(niches) { format_to!(label, "niches = 2{} + 1, ", pwr2_to_exponent(niches - 1)); @@ -1223,16 +1223,12 @@ fn render_dyn_compatibility( } } -fn is_pwr2(val: u128) -> bool { - val.is_power_of_two() -} - fn is_pwr2minus1(val: u128) -> bool { - val == u128::MAX || is_pwr2(val + 1) + val == u128::MAX || (val + 1).is_power_of_two() } fn is_pwr2plus1(val: u128) -> bool { - val != 0 && is_pwr2(val - 1) + val != 0 && (val - 1).is_power_of_two() } /// Formats a power of two as an exponent of two, i.e. 16 => ⁴. Note that `num` MUST be a power @@ -1255,16 +1251,6 @@ mod tests { const TESTERS: [u128; 10] = [0, 1, 2, 3, 4, 255, 256, 257, u128::MAX - 1, u128::MAX]; #[test] - fn test_is_pwr2() { - const OUTCOMES: [bool; 10] = - [false, true, true, false, true, false, true, false, false, false]; - for (test, expected) in TESTERS.iter().zip(OUTCOMES) { - let actual = is_pwr2(*test); - assert_eq!(actual, expected, "is_pwr2({test}) gave {actual}, expected {expected}"); - } - } - - #[test] fn test_is_pwr2minus1() { const OUTCOMES: [bool; 10] = [true, true, false, true, false, true, false, false, false, true]; |
