-
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
Improve heuristic for eagerness suggestion #7639
Conversation
r? @Manishearth (rust-highfive has picked a reviewer for you, use r? to override) |
a5ae777
to
9af9a75
Compare
I don't really love the idea of teaching Clippy an exhaustive list of cheap functions in std. |
Hmm, yeah, I'm unsure. @rust-lang/clippy ? |
I think it would be better to have it consistent for all functions, regardless of how simple they are. It could be confusing for newcomers why some functions are accepted and some not. Also, I'm not sure how such simple closures are handled in rustc, but they could be stored as function pointers, which would still make them cheaper than calling them beforehand. Function calls are still more expensive than passing a function pointer as an argument, as far as I know. The PR description states:
Have we ever had FP reports like these? 🤔 |
Practically speaking it isn't a performance issue. Everything will be inlined anyways (don't know where debug builds stand on this).
No reported issues, but people have mentioned it being dumb. Changing
I agree it's an unwieldy list. Would a shortlist of the worst offenders be ok? Off the top of my head would be Do we have access to the mir for external crates from clippy? Then we could just look at the function and check if it's trivial or not. |
This does get close to the kinds of analyses we'd like to avoid having to do. But I'm not opposed to an allowlist of functions, I just want to be sure that's the path we want to go down. |
How bout a blanket allow on names |
That works |
Is there a particular reason to avoid doing so in this case?
That would remove almost every case I've had it trigger on. Should it be limited to std functions just to be safe? I've seen |
Global analyses tend to be more expensive and brittle |
☔ The latest upstream changes (presumably #7661) made this pull request unmergeable. Please resolve the merge conflicts. |
b09ce5b
to
8ecfcbf
Compare
Removed the list of functions. Now there's only a few heuristics:
|
010a6f3
to
bafe94e
Compare
Does it work to just check that the entire function call
Hmm could you explain how you came up with this? |
That would also work. The check should be moved into
The goal with this is to catch the helper functions for enums to check for specific variants. The various constraints on the fields are to limit the function to only checking the variants. Technically the function could do anything, it's just very unlikely given the constraints applied. The name could be limited to |
going to r? @camsteffen on this one ; I mostly think it's okay but want someone else to make the call 😄 |
☔ The latest upstream changes (presumably #7685) made this pull request unmergeable. Please resolve the merge conflicts. |
Anything else for the review? |
Looks like everything from the last review is resolved. Needs a rebase. |
a5eb1e5
to
1f80543
Compare
☔ The latest upstream changes (presumably #7974) made this pull request unmergeable. Please resolve the merge conflicts. |
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.
LGTM after another rebase, thanks!
1f80543
to
2938ffd
Compare
Can you remove WIP from the PR title? I could do it but I just want to be sure. |
I completely forgot that was still there. |
@bors r+ |
📌 Commit 2938ffd has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
I think this was a good change, but it did create a situation where old clippy warns about new code, new clippy warns about old code; we hit this in ostreedev/ostree-rs-ext#256 (comment) We pin to a specific version for linting in our CI, but not every developer uses the same rustc. For future changes like this, I think it'd be nice to have the new clippy not warn on previously accepted code - at least for a decent period of time. |
Still to be done:
changelog: Improve heuristics for
or_fun_call
andunnecessary_lazy_evaluations