-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.min(x).max(y) with x < y #5854
Comments
Should the suggestion be to swap the |
The two options are equivalent, behavior-wise, except when working with floats if |
I would go for changing the order of the functions in that case. That way, we can guarantee to always emit a semantic equivalent suggestion. |
…flip1995 Lint .min(x).max(y) with x < y Fixes rust-lang#5854 changelog: Also lint `ord.min(a).max(b)`, where `a < b` in [`min_max`] lint
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: