Skip to content

Commit 400fa6e

Browse files
add similar invariants
1 parent 228bb41 commit 400fa6e

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

library/core/src/num/uint_macros.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,7 @@ macro_rules! uint_impl {
14021402
n = self.ilog2() / (base.ilog2() + 1);
14031403
r = base.pow(n);
14041404
}
1405-
#[safety::loop_invariant(base > 1 && r > 1 && r <= s && n <= r)]
1405+
#[safety::loop_invariant(base > 1 && r > 1 && n <= r)]
14061406
while r <= self / base {
14071407
n += 1;
14081408
r *= base;
@@ -1779,7 +1779,8 @@ macro_rules! uint_impl {
17791779
}
17801780
let mut base = self;
17811781
let mut acc: Self = 1;
1782-
1782+
1783+
#[safety::loop_invariant(true)]
17831784
loop {
17841785
if (exp & 1) == 1 {
17851786
acc = try_opt!(acc.checked_mul(base));
@@ -2349,6 +2350,7 @@ macro_rules! uint_impl {
23492350
let mut acc: Self = 1;
23502351

23512352
if intrinsics::is_val_statically_known(exp) {
2353+
#[safety::loop_invariant(exp>=1)]
23522354
while exp > 1 {
23532355
if (exp & 1) == 1 {
23542356
acc = acc.wrapping_mul(base);
@@ -2366,6 +2368,7 @@ macro_rules! uint_impl {
23662368
// at compile time. We can't use the same code for the constant
23672369
// exponent case because LLVM is currently unable to unroll
23682370
// this loop.
2371+
#[safety::loop_invariant(true)]
23692372
loop {
23702373
if (exp & 1) == 1 {
23712374
acc = acc.wrapping_mul(base);
@@ -3043,7 +3046,8 @@ macro_rules! uint_impl {
30433046
let mut overflown = false;
30443047
// Scratch space for storing results of overflowing_mul.
30453048
let mut r;
3046-
3049+
3050+
#[safety::loop_invariant(true)]
30473051
loop {
30483052
if (exp & 1) == 1 {
30493053
r = acc.overflowing_mul(base);

0 commit comments

Comments
 (0)