RS.CLIPPY.MANUAL_REM_EUCLID

Manually reimplementing `rem_euclid`

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

What it does

Checks for an expression like ((x % 4) + 4) % 4 which is a common manual reimplementation of x.rem_euclid(4).

Why is this bad?

It's simpler and more readable.

Example

let x: i32 = 24;
let rem = ((x % 4) + 4) % 4;

Use instead:

let x: i32 = 24;
let rem = x.rem_euclid(4);

Configuration

  • msrv: The minimum rust version that the project supports. Defaults to the rust-version field in Cargo.toml

    (default: current version)