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

fix(rustfmt): fix struct field formatting with doc comments present #5217

Conversation

tharun208
Copy link
Contributor

Fixes #5215

@tharun208 tharun208 force-pushed the fix/struct_field_issue_with_doc_comment branch from 940eaa1 to 302a27c Compare February 4, 2022 09:42
@tharun208 tharun208 force-pushed the fix/struct_field_issue_with_doc_comment branch from 302a27c to 0d15b1f Compare February 4, 2022 09:48
Copy link
Contributor

@ytmimi ytmimi 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 submitting this PR!

A few minor tweaks, and then I think we should be good to go on this one.

@ytmimi
Copy link
Contributor

ytmimi commented Feb 4, 2022

Thanks again for taking on the PR, and for the quick turnaround after receiving some feedback! CI checks look like they're off to a good start, but I'll check back up on this later for another review.

@ytmimi
Copy link
Contributor

ytmimi commented Feb 4, 2022

The code changes look good to me!

I'm wondering if we could add another test case around an attribute that isn't necessarily a doc comment. For example, what does this get formatted to?

struct MyTuple(
    #[cfg(unix)] // some comment
    u64,
    #[cfg(not(unix))] /*block comment */
    u32,
);

struct MyTuple(
    #[cfg(unix)]
    // some comment
    u64,
    #[cfg(not(unix))]
    /*block comment */
    u32,
);

@tharun208 tharun208 requested a review from ytmimi February 4, 2022 18:35
@ytmimi
Copy link
Contributor

ytmimi commented Feb 6, 2022

@tharun208 Thanks again for all the work on this. I know there's a been a decent amount of back and forth so far.

For completeness, and to improve the test coverage could you take all of the tuple struct tests and also include regular struct versions of them. For the regular struct versions of the tests could you also add some fields with various visibility modifiers like pub or pub(crate) in combination with block and inline comments and doc attributes and normal attributes?

@tharun208
Copy link
Contributor Author

@ytmimi sorry for replying late. will improve the coverage and possibly come with the changes next week.

@ytmimi
Copy link
Contributor

ytmimi commented Mar 17, 2022

@tharun208 absolutely no worries. I totally get that things come up and working on PRs can get away from you. No rush on the requested tests, but if you have time to work on them next that would be great!

@tharun208
Copy link
Contributor Author

@ytmimi can we merge this and introduce the test changes as a new pr?

@ytmimi
Copy link
Contributor

ytmimi commented Mar 22, 2022

@ytmimi can we merge this and introduce the test changes as a new pr?

I personally don't have an issue with that, and I think the current tests show that the fix works, but just to give you an example these were the additional test cases that I was looking for:

struct MyTuple(
    #[cfg(unix)] // some comment
    pub u64,
    #[cfg(not(unix))] /*block comment */
    pub(crate) u32,
);

struct MyTuple(
    /// Doc Comments
    /* TODO note to add more to Doc Comments */
    pub u32,
    /// Doc Comments
    // TODO note
    pub(crate) u64,
);

struct MyStruct {
    #[cfg(unix)] // some comment
    a: u64,
    #[cfg(not(unix))] /*block comment */
    b: u32,
}

struct MyStruct {
    #[cfg(unix)] // some comment
    pub a: u64,
    #[cfg(not(unix))] /*block comment */
    pub(crate) b: u32,
}

struct MyStruct {
    /// Doc Comments
    /* TODO note to add more to Doc Comments */
    a: u32,
    /// Doc Comments
    // TODO note
    b: u64,
}

struct MyStruct {
    /// Doc Comments
    /* TODO note to add more to Doc Comments */
    pub a: u32,
    /// Doc Comments
    // TODO note
    pub(crate) b: u64,
}

@tharun208 tharun208 requested a review from ytmimi March 28, 2022 05:51
Copy link
Contributor

@ytmimi ytmimi left a comment

Choose a reason for hiding this comment

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

Thank you for adding those additional test cases!! Just one minor tweak to reintroduce a newline at the of test/souce/structs.rs, and I think we're good to go here.

@tharun208
Copy link
Contributor Author

@ytmimi done 😃

@ytmimi ytmimi self-requested a review March 28, 2022 21:03
Copy link
Contributor

@ytmimi ytmimi left a comment

Choose a reason for hiding this comment

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

LGTM Thanks for this!

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.

lgtm as well, thank you both!

@calebcartwright calebcartwright merged commit 1dcdfb2 into rust-lang:master Apr 2, 2022
@tharun208 tharun208 deleted the fix/struct_field_issue_with_doc_comment branch April 2, 2022 08:00
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.

Tuple struct field comments consume the field itself, only with doc comment
3 participants