75. L0415 (loop_invariant_mod_div) lint with cpl fix (2026-11-21)
- Flag loop-invariant
Mod<P>divisors insidefor/whileloops (L0415,loop_invariant_mod_div) and offer acpl fixhoist.- Reason:
Mod<P>division runs anO(log P)modular inverse on every iteration; hoistinglet inv_d = d.inv(orZ(k).invfor an integer divisor) before the outermost invariant loop replaces it withO(1)multiplication with zero false positives (0 false positives across 1,429 corpus + stdlib files, 2 real hits incf2180gandnoip22p3). 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 (thecf2245fpattern) 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_DIVfromcrates/cpl-lint/src/lib.rs, and its call incrates/cpl-lint/src/rules/mod.rs.
- Reason: