-
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
Refactor clippy::match_ref_pats
to check for multiple reference patterns
#7800
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @llogiq (or someone else) soon. Please see the contribution instructions for more information. |
Cool stuff! The only downside I see is that some test cases are now effectively disabled. Would you be OK with changing them so they apply again and adding one or two new tests that show single ref patterns are not linted? |
@llogiq Thank you! I can update the test cases but if I'm not wrong, Let me know if I can approach this differently |
I'm only talking about the lint's own tests. To make the error re-occur, you may need an enum with more than two cases. |
Given that we want to use an enum with more than two cases, would something like this work? fn issue_7740() {
// Should trigger lint
match foobar_variant!(0) {
&FooBar::Foo => println!("Foo"),
&FooBar::Bar => println!("Bar"),
&FooBar::FooBar => println!("FooBar"),
_ => println!("Wild"),
}
// This shouldn't trigger
if let &FooBar::BarFoo = foobar_variant!(3) {
println!("BarFoo");
} else {
println!("Wild");
}
} |
Thank you! @bors r+ |
📌 Commit 1080f6c has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
fixes #7740
When there is only one pattern, to begin with, i.e. a single deref(
&
), then in such cases we suppressclippy::match_ref_pats
.This is done by checking the count of the reference pattern and emitting
clippy::match_ref_pats
when more than one pattern is present.Removed certain errors in the
stderr
tests as they would not be triggered.changelog: Refactor
clippy::match_ref_pats
to check for multiple reference patterns