RS.CLIPPY.MANUAL_RANGE_CONTAINS

Manually reimplementing {`Range`, `RangeInclusive`}`::contains`

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

What it does

Checks for expressions like x >= 3 && x < 8 that could be more readably expressed as (3..8).contains(x).

Why is this bad?

contains expresses the intent better and has less failure modes (such as fencepost errors or using || instead of &&).

Example

// given
let x = 6;

assert!(x >= 3 && x < 8);

Use instead:

assert!((3..8).contains(&x));

Configuration

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

    (default: current version)