Skip to content

Commit 60d4b9e

Browse files
author
Kasim Te
committed
Add Kani contracts and harnesses for NonZero (Challenge 12)
1 parent b0768ce commit 60d4b9e

3 files changed

Lines changed: 1959 additions & 4 deletions

File tree

library/core/src/num/int_macros.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1736,7 +1736,10 @@ macro_rules! int_impl {
17361736
let mut base = self;
17371737
let mut acc: Self = 1;
17381738

1739-
#[safety::loop_invariant(true)]
1739+
// `self == 0` covers the primitive's own harness (e.g. `0.checked_pow(n)`, where
1740+
// `acc` can reach 0); in the NonZero call path `self` is never 0, so it is dead
1741+
// but harmless there. The right disjunct (`acc != 0 && base != 0`) is the inductive core.
1742+
#[safety::loop_invariant(self == 0 || (acc != 0 && base != 0))]
17401743
loop {
17411744
if (exp & 1) == 1 {
17421745
acc = try_opt!(acc.checked_mul(base));

0 commit comments

Comments
 (0)