Skip to content

Issue 4668 #4720

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

Merged
merged 1 commit into from
Mar 12, 2021
Merged

Issue 4668 #4720

merged 1 commit into from
Mar 12, 2021

Conversation

ChinYing-Li
Copy link
Contributor

Opening a new PR as I accidentally deleted the forked rustfmt repo! This PR aims at resolving #4668.

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.

Thanks for this! Could you please expand the set of test cases to include some other scenarios, particularly where wrap_comments still holds the default false value?

here's one in particular I'd like to include to cover non-wrapping within a chain :

fn f() {
    async {
let x  =   true  ;
        /* Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin urna felis, molestie ex. */
    }
    .boxed()
}

some other scenarios with more deeply indented/nested constructs would be good too (doesn't really matter how we get the indentations, nested items, control flow expressions, etc.)

// needed to set the kind of the ending character on the last line
prev_kind = self.kind;
Copy link
Member

Choose a reason for hiding this comment

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

Could you swap these, just to maintain the association of the inline comment with the same line?

Suggested change
// needed to set the kind of the ending character on the last line
prev_kind = self.kind;
prev_kind = self.kind;
// needed to set the kind of the ending character on the last line

Add idempotent tests for wrapping block-style comment
@ChinYing-Li
Copy link
Contributor Author

I added a few test cases, but ran out of ideas ;)
Please let me know if you'd like to add other scenarios.

@calebcartwright
Copy link
Member

Thank you! We'll need to backport this on to the main 1.x release branches, and it will need to be version gated (since this change will permit rustfmt to format some things it was failing to format prior) if that's something you'd be interested in!

@calebcartwright calebcartwright merged commit 65f41f3 into rust-lang:master Mar 12, 2021
@ChinYing-Li
Copy link
Contributor Author

Thank you for the review, @calebcartwright ! To back-port, I will have to fix this bug on all rust-1.x branches, is my understanding correct? I'd love to work on back-porting; please let me know in case there's some pitfall I have to be aware of.

@calebcartwright
Copy link
Member

calebcartwright commented Mar 16, 2021

I'd love to work on back-porting

❤️ beautiful thank you!

To back-port, I will have to fix this bug on all rust-1.x branches, is my understanding correct

Nope it's actually a bit simpler. Just open a PR against the current 1.x branch (which is https://github.com/rust-lang/rustfmt/tree/rustfmt-1.4.37 at the moment), and you'll most likely be able to just cherry-pick 65f41f3 directly.

It's a bit of a long story, but at the moment the default (master) branch in this repository contains a very different version of the rustfmt source than the version of rustfmt that actually gets released and utilized by users. That happened because there was originally a major 2.0 release planned for rustfmt with myriad breaking changes, but that's been put on hold indefinitely. Hoping to get that sorted soon, but currently we'll often have to apply changes against both the 2.0 and 1.x versions of rustfmt.

There will be some additional changes required to the code on the 1.x branch, specifically to leverage the Version gate on the arm guard. That'll be needed to maintain rustfmt's stability guarantee since this change will result in rustfmt formatting some code it wasn't formatting before.

I imagine it'll basically be taking this:

(_, FullCodeCharKind::Normal) if prev_kind == FullCodeCharKind::EndComment => {

and adding the additional check on the guard with something like:

(_, FullCodeCharKind::Normal) if prev_kind == FullCodeCharKind::EndComment && self.config_version == Version::Two => {

but you may need to get some additional context into the LineClasses struct so that is available. More info on version gating rustfmt code changes can be found here.

Feel free to open an early draft PR along the way if you have any questions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants