-
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
Fix match_same_arms to fail late #4102
Conversation
Changes: - Add a function search_same_list which return a list of matched expressions - Change the match_same_arms implementation behaviour. It will lint each same arms found.
Hello, I would like some feedback, especially for the tests. I have some tests failing and did not figure out yet how to fix them. |
Hey, thanks for the contribution! Have you looked at https://github.com/rust-lang/rust-clippy/blob/master/doc/adding_lints.md#testing? It is described there how to update reference files (*.stderr files) and how to add tests. |
Changes: - Add a test to match multiple arms in the same match statement
Thank you for the tips I did not pay attention to the doc folder. You guys did a good job making contributing trivial. My last commit should add the right test and fix the test errors. |
Happy to hear that! With your changes the first error doesn't get printed anymore. That's a regression we want to avoid. Could you look into that? |
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.
Is the implementation for search_same
still needed?
Or maybe more important: Shouldn't the if check also fail late?
I have questions about the "unwrap" line 387. I am not sure its the right way to do it. |
@pJunger Thank you for your insight it helps a lot. |
You're welcome! |
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.
Looks good to me.
Great ! |
Thanks for the review @pJunger ! Now that Also (not really related to the issue, but while you're at it... 😄), could you change these rust-clippy/clippy_lints/src/copies.rs Lines 212 to 220 in cbae9ed
to span_help and use the span of the pat s instead of the body. The lint message should then look something like this:
...
+help: consider refactoring into `41 | 52`
-note: consider refactoring into `41 | 52`
--> $DIR/match_same_arms.rs:115:15
|
LL | 41 => 2,
+ | ^^
- | ^ And last but not least: Could you add a test where more than 2 match arms are the same: match x {
1 => 2,
2 => 2,
3 => 2, // 3rd time the same arm
4 => 3,
} |
Thanks! You have to run |
Maybe also add a function to the if_same_then_else block with multiple branches?
|
I hope this fixes everything. I forgot to do a full uitest before commiting. |
LGTM now. 2 Things left to do:
and this is good to go. |
I try to install rustfmt, but I get this errors: 'cargo-fmt' is not installed for the toolchain 'master' |
Yeah, you can't really install components on the master toolchain. For Clippy we use nightly rustfmt anyway (for this reason). So install rustfmt for nightly and then run |
9721840
to
038bd5f
Compare
Changes: - Refactor the common case search into a function. - Fix the useless Option around the vec in the search_same_list.
Changes: - Fix stderr breaking the tests - Adding tests over the if arms
038bd5f
to
40f3665
Compare
That should cover 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.
Thanks!
Every PR is currently blocked on #4121, but I'll merge this once this bug is fixed.
@bors r+ |
📌 Commit 40f3665 has been approved by |
…lip1995 Fix match_same_arms to fail late Changes: - Add a function search_same_list which return a list of matched expressions - Change the match_same_arms implementation behavior. It will lint each same arms found. fixes rust-lang#4096 changelog: none
Changes:
fixes #4096
changelog: none