RS.CLIPPY.MANUAL_MIDPOINT

Manual implementation of `midpoint` which can overflow

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

What it does

Checks for manual implementation of midpoint.

Why is this bad?

Using (x + y) / 2 might cause an overflow on the intermediate addition result.

Example

let c = (a + 10) / 2;

Use instead:

let c = u32::midpoint(a, 10);

Configuration

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

    (default: current version)