-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
unnecessary call to min function #11924
Comments
I have never done a contribution to such a project, so i think this is a perfect opportunity for that. |
@rustbot claim |
This is a good idea. You'll want to match on an Getting the value of the constant is tricky, versus just matching on the name. I'd go with the former for the same reason as matching on the name. See the Not sure how you'd easily check if it's gt/lt if it's a float. I think we could extend this to The same applies to the |
Yes i thought the same. and here is a bit of pseudo code of what i would do in my // i have something like this:
let _ = a.min(b);
// Check function:
let ty = cx.typeck_results().expr_ty(expr);
match ty {
types_i_want_to_support => {},
_ => return,
}
if a == 0 | T::MIN | T::MAX {
lint()
}
if b == 0 | T::MIN | T::MAX {
lint()
} Technically i don't want to check if it is a
I think i don't quite understand what you're saying.
I will look into that. Thank you!
That's a good point. The logic for checking on these special values could been shared. |
It's 4am. On the first section I mean that, rather than only linting when the receiver is The second section is how |
My bad. I'm from europe and i didn't think about other timezones.
Of course. Thats a good point. I didnt think of that at all. That happens if you are so focused on a detail, that you don't see the bigger picture.
I definitely have to look into what different Types there are and what i can do with it.
I think it does work. Because i see the |
Was just explaining why it was worded improperly 😅 You're fine :) |
So i have implemented the first draft. Because i'm new to colloboration on github, what is the next step? |
Closing as this was implemented in #12368 |
What it does
A few days ago i opened #11901
You could do this for the
min()
method too.So
0.min(<anything>)
is always zero if<anything>
is an unsigned integer.Also this method is symmetric, that means same applies to
<anything>.min(0)
.You could go even further and generalize this to
T::MIN.min(<anything>)
(whereT
is any type of integer like i.e.i64
) is alwaysT::MIN
.And you could do this with the upper bound too:
T::MAX.min(<anything>)
is for any integer typeT
the same as<anything>
.Advantage
Drawbacks
No response
Example
Could be written as:
The text was updated successfully, but these errors were encountered: