-
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 match like matches lint #6216
Improve match like matches lint #6216
Conversation
r? @ebroto (rust_highfive has picked a reviewer for you, use r? to override) |
6fe0035
to
4b0a88b
Compare
One approach is to move In this case we would have to move some functions from the |
Giving two different suggestions for the same code can be misleading if they suggest different things, so we try to avoid it. Moreover, if both lints have auto-applicable suggestions, trying to apply the second one would fail. |
Yeap, I think that your idea is perfectly clear. It's the one I called "global refactoring near these two lints" :) The main problem that all examples in clippy code, I see, were straightforward methods, which call
@ebroto did you get, what I'm trying to say? Is the third idea common for clippy codebase? If it is, can you point several others examples? Personally I like the second idea in cases where there is no some cpu-consuming calculations in this |
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.
The implementation LGTM, I've just suggested to add some tests.
About the interaction with match_same_arms
, I apologize for not being more precise in my first comment. I pointed you to that commit to show that we can move a lint to another module, but the solution of storing the spans is very specific to that case because the conflicting lints start a different levels, one in check_block
and the other one in check_expr
.
In this case, I think it's easier because both lints work at the expression level, and if the expression is a match. So the solution should be applied in this section of the matches
module and doing something like
let matches_applied = check_match_like_matches(cx, expr);
// ...
if !matches_applied {
check_match_same_arms(cx, expr);
}
I want to say that every time we try to avoid conflicting lints, it's a hack. We need a more general solution, probably implemented in rustc itself.
4b0a88b
to
287be36
Compare
- add tests - refactor match_same_arms lint - prioritize match_expr_like_matches_macro over match_same_arms
287be36
to
2b7dd31
Compare
@bors r+ Thanks for taking care of this! |
📌 Commit 2b7dd31 has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
fixes #6186
changelog: improve MATCH_LIKE_MATCHES_MACRO lint