Skip to content
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

Handle DefinitiveListTactic::SpecialMacro when writing pre-comments #5028

Merged
merged 1 commit into from
Oct 17, 2021

Conversation

ytmimi
Copy link
Contributor

@ytmimi ytmimi commented Oct 14, 2021

Resolves #4615

Previously only Vertical and Mixed enum variants of DefinitiveListTactic
were considered when rewriting pre-comments for inner items in
lists::write_list.

Because we failed to considering the SpecialMacro variant we ended up in
a scenario where a ListItem with a pre_comment and a pre_comment_style
of ListItemCommentStyle::DifferentLine was written on the same line as the
list item itself.

Now we apply the same pre-comment formatting to SpecialMacro, Vertical,
and Mixed variants of DefinitiveListTactic.

Resolves 4615

Previously only Vertical and Mixed enum variants of DefinitiveListTactic
were considered when rewriting pre-comments for inner items in
lists::write_list.

Because we failed to considering the SpecialMacro variant we ended up in
a scenario where a ListItem with a pre_comment and a pre_comment_style
of ListItemCommentStyle::DifferentLine was written on the same line as the
list item itself.

Now we apply the same pre-comment formatting to SpecialMacro, Vertical,
and Mixed variants of DefinitiveListTactic.
Copy link
Member

@calebcartwright calebcartwright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent find and fix, thank you!

Comment on lines +370 to +373
match tactic {
DefinitiveListTactic::SpecialMacro(_)
| DefinitiveListTactic::Vertical
| DefinitiveListTactic::Mixed => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't feel obligated to change anything, just sharing for awareness. For future reference, you may want to consider utilizing the matches! macro in these types of cases because it could both express the condition more succinctly, and it helps avoid the extra level of indentation that comes with the match arm body, e.g.

                use DefinitiveListTactic::*;
                if matches!(tactic, Vertical | Mixed | SpecialMacro(_)) {

(with the wildcard import being another option to shorten the length of the pattern variants)

Copy link
Contributor Author

@ytmimi ytmimi Oct 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate you pointing this out. It didn't even occur to me to use the matches! macro. I went ahead and made the change in #5034!

@calebcartwright calebcartwright merged commit 5f4811e into rust-lang:master Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rustfmt is creating my code uncompilable
2 participants