Skip to content

Commit fa5fc79

Browse files
committed
Remove redundant precondition
If `base >= 2 && x >= base`, then `x >= 2`, which satisfies `x >= 1`.
1 parent 74ead49 commit fa5fc79

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

library/core/src/num/uint_macros.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,8 +1494,7 @@ macro_rules! uint_impl {
14941494
// Preconditions for calling inner function `slow_ilog`:
14951495
//
14961496
// 1: base >= 2
1497-
// 2: x >= 1
1498-
// 3: x >= base
1497+
// 2: x >= base
14991498
#[inline(always)]
15001499
const fn slow_ilog(x: $SelfT, base: $SelfT) -> u32 {
15011500
// Since x >= base, n >= 1
@@ -1524,12 +1523,12 @@ macro_rules! uint_impl {
15241523
}
15251524

15261525
if core::intrinsics::is_val_statically_known(self) {
1527-
if self <= 0 { // precondition 2
1526+
if self <= 0 {
15281527
None
15291528
} else if core::intrinsics::is_val_statically_known(base) {
15301529
if base <= 1 { // precondition 1
15311530
None
1532-
} else if self < base { // precondition 3
1531+
} else if self < base { // precondition 2
15331532
Some(0)
15341533
} else if base == 2 {
15351534
self.checked_ilog2()
@@ -1540,7 +1539,7 @@ macro_rules! uint_impl {
15401539
}
15411540
} else if base <= 1 { // precondition 1
15421541
None
1543-
} else if self < base { // precondition 3
1542+
} else if self < base { // precondition 2
15441543
Some(0)
15451544
} else { // all preconditions satisfied
15461545
Some(slow_ilog(self, base))
@@ -1552,16 +1551,16 @@ macro_rules! uint_impl {
15521551
self.checked_ilog2()
15531552
} else if base == 10 {
15541553
self.checked_ilog10()
1555-
} else if self <= 0 { // precondition 2
1554+
} else if self <= 0 {
15561555
None
1557-
} else if self < base { // precondition 3
1556+
} else if self < base { // precondition 2
15581557
Some(0)
15591558
} else { // all preconditions satisfied
15601559
Some(slow_ilog(self, base))
15611560
}
1562-
} else if self <= 0 || base <= 1 { // preconditions 1 and 2
1561+
} else if self <= 0 || base <= 1 { // precondition 1
15631562
None
1564-
} else if self < base { // precondition 3
1563+
} else if self < base { // precondition 2
15651564
Some(0)
15661565
} else { // all preconditions satisfied
15671566
Some(slow_ilog(self, base))

0 commit comments

Comments
 (0)