Source context

Program Rust

count_trailing_zeros

This Rust is the input prepared for Aeneas. Modeling choices explains the adaptations from the production source.

232 // It is separate because Aeneas cannot join the loop while `parse_decimal_seq`233 // retains its other slice borrows.  The downward index has the same visitation234 // order and counts precisely the same zero bytes while ignoring dots.235 fn count_trailing_zeros(start: &[u8], consumed_len: usize) -> usize {236     let mut n_trailing_zeros = 0;237     let mut i = consumed_len;238     let mut scanning = true;239     while i != 0 && scanning {240         let c = start[i - 1];241         if c == b'0' || c == b'.' {242             i -= 1;243             if c == b'0' {244                 n_trailing_zeros += 1;245             }246         } else {247             scanning = false;248         }249     }250     n_trailing_zeros251 }252 253 // Equivalent to `ByteSlice::parse_digits(|digit| d.try_add_digit(digit))`.254 // An explicit index keeps the closure's mutable borrow out of the enclosing

Aeneas declaration

The Lean below was mechanically extracted by Aeneas from Rust.

@[reducible]
def num.imp.dec2flt.decimal_seq.count_trailing_zeros
  (start : Slice Std.U8) (consumed_len : Std.Usize) : Result Std.Usize := do
  num.imp.dec2flt.decimal_seq.count_trailing_zeros_loop start 0#usize
    consumed_len true
Operations used here

count_trailing_zeros_loop · Program Rust

Source details
Declarationnum.imp.dec2flt.decimal_seq.count_trailing_zeros
Filenum/imp/../../dec2flt/decimal_seq.rs
Lines235:0–251:1
Program versionPreparation 2