RS.CLIPPY.MODULO_ARITHMETIC

Any modulo arithmetic statement

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: modulo_arithmetic. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for modulo arithmetic.

Why restrict this?

The results of modulo (%) operation might differ depending on the language, when negative numbers are involved. If you interop with different languages it might be beneficial to double check all places that use modulo arithmetic.

For example, in Rust 17 % -3 = 2, but in Python 17 % -3 = -1.

Example

let x = -17 % 3;

Configuration

  • allow-comparison-to-zero: Don't lint when comparing the result of a modulo operation to zero.

    (default: true)