rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

Add new lint `stacked_if_match`

Open promptkp opened this issue 1 year ago • 7 comments

fixes #12483


changelog: new [stacked_if_match] lint against if if and match match

promptkp avatar Aug 25 '24 12:08 promptkp

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

rustbot avatar Aug 25 '24 12:08 rustbot

:umbrella: The latest upstream changes (presumably #11476) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Aug 28 '24 08:08 bors

In theory cases with match if and if match should work? I would be nice to have examples what happens in this cases

alex-semenyuk avatar Aug 31 '24 07:08 alex-semenyuk

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!

promptkp avatar Sep 01 '24 13:09 promptkp

:umbrella: The latest upstream changes (presumably #13247) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Sep 03 '24 17:09 bors

:umbrella: The latest upstream changes (presumably #13322) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Sep 22 '24 14:09 bors

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

Alexendoo avatar Sep 29 '24 13:09 Alexendoo

:umbrella: The latest upstream changes (possibly d28d2344d000aa96bef729cf408731f952f71fb0) made this pull request unmergeable. Please resolve the merge conflicts.

rustbot avatar Mar 31 '25 23:03 rustbot

Ping @promptkp from triage. Do you plan to return to working on this?

Jarcho avatar Sep 17 '25 00:09 Jarcho

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.

Jarcho avatar Oct 01 '25 20:10 Jarcho