Design decisions

75. L0415 (loop_invariant_mod_div) lint with cpl fix (2026-11-21)

  1. Flag loop-invariant Mod<P> divisors inside for/while loops (L0415, loop_invariant_mod_div) and offer a cpl fix hoist.
    • Reason: Mod<P> division runs an O(log P) modular inverse on every iteration; hoisting let inv_d = d.inv (or Z(k).inv for an integer divisor) before the outermost invariant loop replaces it with O(1) multiplication with zero false positives (0 false positives across 1,429 corpus + stdlib files, 2 real hits in cf2180g and noip22p3). Auto-fix attaches only when the division is unconditional in the loop or the divisor is a nonzero literal so hoisting cannot introduce a division-by-zero trap.
    • Deferred: A second rule for loop-varying small-integer divisors when Comb<M> is in scope (the cf2245f pattern) is deferred because it has a single corpus hit and requires range/sign/depth guards; reopen if a second instance appears.
    • Reverse: Remove crates/cpl-lint/src/rules/mod_div.rs, LOOP_INVARIANT_MOD_DIV from crates/cpl-lint/src/lib.rs, and its call in crates/cpl-lint/src/rules/mod.rs.