RS.CLIPPY.MANUAL_SATURATING_ARITHMETIC

`.checked_add/sub(x).unwrap_or(MAX/MIN)`

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_saturating_arithmetic. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for .checked_add/sub(x).unwrap_or(MAX/MIN).

Why is this bad?

These can be written simply with saturating_add/sub methods.

Example

let add = x.checked_add(y).unwrap_or(u32::MAX);
let sub = x.checked_sub(y).unwrap_or(u32::MIN);

can be written using dedicated methods for saturating addition/subtraction as:

let add = x.saturating_add(y);
let sub = x.saturating_sub(y);