-
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
implemented unnecessary min #12061
implemented unnecessary min #12061
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @giraffate (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
☔ The latest upstream changes (presumably #12054) made this pull request unmergeable. Please resolve the merge conflicts. |
f601625
to
49cbc0f
Compare
☔ The latest upstream changes (presumably #11987) made this pull request unmergeable. Please resolve the merge conflicts. |
49cbc0f
to
3749e24
Compare
let _ = (A * B).min(B); // Both are constants | ||
let _ = C.min(B); // Both are constants | ||
let _ = B.min(C); // Both are constants |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know whether clippy has a policy for these sorts of things, but linting using the values of constants makes me wary. It would be possible to change A
, B
, or C
in such a way that the use of min
or max
do actually do something, especially if it's something like min(CONST_LIMIT, user_input)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know whether clippy has a policy for these sorts of things, but linting using the values of constants makes me wary. It would be possible to change A, B, or C in such a way that the use of min or max do actually do something
I don't think i get your point.
In your commented block of code all "variables" are constants so afaik it is not possible that one of them can change.
In the case of
min(CONST_LIMIT, user_input)
there should be only a lint emitted if CONST_LIMIT
is either the minimum or maximum value. If it is the minimum value, then the result will always be the minumum regardless of the user_input
and if it is the maximum value then the result will always be the user_input
.
Or did you mean something like that?:
let mut m = u32::MAX;
for _ in 0..1000{
m = m.min(user_input);
}
In this situation nothing should be linted.
I'll add a test to confirm it.
thank you for your feedback. I appreciate it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i added the test
|
||
let _ = i64::MAX.min(test_i64()); // signed with MAX and function | ||
let _ = test_i64().min(i64::MAX); // signed with MAX and function | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to see tests using the u32::min(a, b)
syntax to be sure that the suggestions are correct.
It might be worth adding a test for things like u32::min(CONST, { some_math * abc - 3 })
or other complex expressions that could be placed in the call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'll add that.
Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i tried your suggestion and it doesn't lint it.
It seems like it currently only works as a method with the .
like a.min(b)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed only one character and now the CI is failing.
i did cargo dev update_lints
.
What can i do?
I think you should be able to fix this by rebasing on master and then running |
f0981a8
to
892fc29
Compare
thank you. that worked! |
I don't think you need to do that for every commit. I usually only rebase when conflicts happen or to squash commits when the PR is about to be merged or to clean up history/remove some commits that don't really add any value. Looks like it was only needed here because there are currently 699 lints on master but your branch was behind a bit and didn't, so running |
Hi @FelixMaetzler. Are you still working on this? Would you mind if I continue your work to combine issue #11901 to this? |
yes i'm working on it. But imho the feature is finished. I just have to resolve the conflicts and wait on further review. |
Thanks @FelixMaetzler. Then I will start by fixing the conflict in this PR |
Hey @FelixMaetzler can this PR be closed in favor of #12368? |
Hey @xFrednet, yes this PR can be closed. Thank you. |
fixes #11924
new version of #11951 because i'm to stupid to figure it out how to fix it