rust-lang / rust-lang/rust-clippy

Manual clamp variant for min and max

Open
#16,884 1 comment 0 reactions 1 assignee View on GitHub

@Souradip121 is already working on this.

Since Apr 19, 2026.

A-lint
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

What it does

Replaces manual implementations of Ord::min and Ord::max with those methods.

Advantage

The code becomes more concise, (subjectively) clearer and doesn’t use any control flow.

Drawbacks

In const context, primitives can be compared but the Ord methods cannot be called (as yet). The lint should not trigger in this case.

Example
if x > y {
    y
} else {
    x
}

Could be written as:

x.min(y)

Note that if the comparison were x >= y then the suggested code should be y.min(x).

Comparison with existing lints

The two cases, min and max, can each be considered half of manual_clamp, and should probably just be part of that lint.

Additional Context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.