Add new lint `stacked_if_match`
fixes #12483
changelog: new [stacked_if_match] lint against if if and match match
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Alexendoo (or someone else) some time within the next two weeks.
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 (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:
-
@rustbot author: the review is finished, PR author should check the comments and take action accordingly -
@rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue
:umbrella: The latest upstream changes (presumably #11476) made this pull request unmergeable. Please resolve the merge conflicts.
In theory cases with match if and if match should work? I would be nice to have examples what happens in this cases
Hi @alex-semenyuk, thank you for the comment. To prevent overlinting, stacked_if_match only lints against if if and match match. I'll add additional test cases for match if and if match.
Note: this is my first contribution to Clippy, so if there's a faster/cleaner way to implement this, please let me know!
:umbrella: The latest upstream changes (presumably #13247) made this pull request unmergeable. Please resolve the merge conflicts.
:umbrella: The latest upstream changes (presumably #13322) made this pull request unmergeable. Please resolve the merge conflicts.
A few times I've looked at this again trying to figure out what the rustfmt rules are but they seem difficult to predict, e.g. here's an if in the middle of a condition that gets formatted in the undesired way
if 1 == if xxxxxxxxxxxxxxxxxx {
111111111111
} else {
222222222222222
} && x == y
{
3
} else {
4
};
Maybe instead of trying to recreate the behaviour we should check the actual format directly, something like calling SourceMap::lookup_char_pos to check if the inner if's hi is one above the outer if's lo
:umbrella: The latest upstream changes (possibly d28d2344d000aa96bef729cf408731f952f71fb0) made this pull request unmergeable. Please resolve the merge conflicts.
Ping @promptkp from triage. Do you plan to return to working on this?
Closing since there's been no response. @promptkp if you wish to return to working on this feel free to reopen or create a new PR.