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

Adding a doc comment inside an enum causes a change in the enum formatting #6280

Closed
malikolivier opened this issue Aug 13, 2024 · 2 comments
Closed

Comments

@malikolivier
Copy link

malikolivier commented Aug 13, 2024

I include a reproduction of the issue in #6279.

The following minimal example is being formatted.

enum A {
    B {
        a: usize,
        b: usize,
        c: usize,
        d: usize,
    },

    /// C
    C {
        a: usize,
    },
}

The resulting format is:

enum A {
    B {
        a: usize,
        b: usize,
        c: usize,
        d: usize,
    },

    /// C
    C { a: usize },
}

However, if /// C is not included, the code is left unformatted (this is what I would expect whether /// C is there or not).

As far as I can tell, this reproducing example is minimal: for example, after removing d: usize we do not reproduce the reported behavior.

I found this issue while adding rustdocs to an existing project.
I would expect that adding a line of documentation should not cause the formatting of the code to change.

@ytmimi ytmimi changed the title Adding a docstring inside an enum causes a change in the enum formatting Adding a doc comment inside an enum causes a change in the enum formatting Aug 14, 2024
@ytmimi
Copy link
Contributor

ytmimi commented Aug 14, 2024

Thanks for the report. I remember something like this being reported before, but I haven't had a chance to dive into the issue tracker to find it yet.

@ytmimi
Copy link
Contributor

ytmimi commented Aug 14, 2024

Duplicate of #6120 and #5662

@ytmimi ytmimi closed this as not planned Won't fix, can't repro, duplicate, stale Aug 14, 2024
malikolivier added a commit to malikolivier/rustfmt that referenced this issue Aug 18, 2024
Test case as reported in rust-lang#6280.
This test case used to fail, but the code in the previous commit fixes
it.

We followed instructions on Contributing.md [1] to create a test case.

`tests/target/rust-doc-in-enum/vertical-no-doc.rs` is being left unformatted
(expected behavior), while `tests/target/rust-doc-in-enum/vertical-with-doc.rs`
is formatted to `C { a: usize }` (unexpected behavior).

The only different between the two samples is the `/// C` rustdoc added
in `with-doc.rs`.
This reproducing example is minimal: for example, after removing `d: usize`
we do not reproduce the reported behavior.

We found this issue while adding rustdocs to an existing project.
We would expect that adding a line of documentation should not cause the
formatting of the code to change.

[1] https://github.com/rust-lang/rustfmt/blob/40f507526993651ad3b92eda89d5b1cebd0ed374/Contributing.md#L33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants