rust-lang / rust-lang/rust-clippy
Manual clamp variant for min and max
Open
@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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.