Prevent ranges from getting collapsed in patterns#6871
Conversation
|
Just to be sure these changes wouldn't impact things I ran the Diff-Check --edition=2021 --style-edition=2021. Things seem to be working as expected. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Thanks, this looks good to me. This impacts stable default format but previously this was working code -> broken code on ranges in patterns. AFAICT this shouldn't affect other cases (though it's possible there are edge cases that I failed to consider and that DiffCheck is only run on a limited set of repos, and that this code pattern is comparatively rare to hit in practice).
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
I think we should be good here. Especially since the formatting rustfmt produced broke the code. I also wouldn't expect this to impact any other stable formatting because I feel like we have enough range formatting coverage in the test suite, but just to be sure I'll expand on the tests I add here. |
Move the range rewrite logic from `src/exrp.rs` to `src/range.rs`. There are a few different places where we rewrite ranges so centralizing the logic in a single location is ideal.
Cleans up the syntax a little. Was suggested in the PR review.
Reuse the range rewrite logic that we abstracted into `src/range.rs`.
Reuse the range rewrite logic that we abstracted into `src/range.rs`.
Now that we've centralized the logic into `rewrite_range` we no longer need a dedicated `rewrite_range_pat` function. Getting rid of that also lets us remove some other unnecessary code which is nice.
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@rustbot ready @jieyouxu when you have a chance can you take another look. I added a lot of different test cases with both the |
|
Running the Diff-Check for good measure, but as you mentioned we might not hit the bug case in real code. Will still be good to check and make sure that the formatting produced by the |
|
New DiffCheck looks clean 👍, though as discussed, it won't be too representative, but still better than nothing :) |
Fixes #6869
Expression rewriting handled this correctly, but there was distinct logic implemented for patterns. I've extracted the range formatting logic used by expressions into a common
rewrite_rangefunction and reused that when rewriting ranges in patterns and types. Was able to remove a nice amount of code after these changes were done.PR is broken up into logical commits. Feel free to review the PR as a whole or commit by commit.