.min(x).max(y) with x < y #5854
Labels
A-lint
Area: New lints
good-first-issue
These issues are a good way to get started with Clippy
L-correctness
Lint: Belongs in the correctness lint group
L-suggestion
Lint: Improving, adding or fixing lint suggestions
What it does
Lints against people using
min
andmax
methods (on the float types or onOrd
) to constrain a value to a range, but getting the arguments tomin
andmax
backwards (such that the argument to min is less than the argument to max). In that case, instead of clamping the value to be between the two arguments (likely what was intended), it will always return the argument of the second function called.Categories (optional)
Drawbacks
None. If someone wanted the result of the expression this lint triggers on (which is unlikely), they could just include the returned value directly.
Example
Given a floating-point variable
x
:will always give the value 1.0, whereas
will give the value of x, clamped between
-1.0
and1.0
, with1.0
forNaN
.The text was updated successfully, but these errors were encountered: