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

Rustfmt misaligns doc comment between rustfmt::skip modules #6176

Open
dtolnay opened this issue May 28, 2024 · 2 comments
Open

Rustfmt misaligns doc comment between rustfmt::skip modules #6176

dtolnay opened this issue May 28, 2024 · 2 comments

Comments

@dtolnay
Copy link
Member

dtolnay commented May 28, 2024

mod modules {
    #[rustfmt::skip]
    #[path = "/dev/null"]
    mod first;

    /// ...
    /// ...
    #[rustfmt::skip]
    #[path = "/dev/null"]
    mod second;
}

Running rustfmt on this file turns it into:

mod modules {
    #[rustfmt::skip]
    #[path = "/dev/null"]
    mod first; /// ...
               /// ...
    #[rustfmt::skip]
    #[path = "/dev/null"]
    mod second;
}
<     mod first;
<
<     /// ...
<     /// ...
---
>     mod first; /// ...
>                /// ...

Observations:

  • The #[path = "/dev/null"] attribute is not necessary for the repro. It is just to make this reproducible with a single input file.
  • Both #[rustfmt::skip] are necessary for the repro. Without either one, the problem does not occur.
  • Both ; are necessary for the repro. If either module uses {} instead of ;, the problem does not occur.
  • The outer module is necessary.
@dtolnay
Copy link
Member Author

dtolnay commented May 28, 2024

This currently affects syn as of https://github.com/dtolnay/syn/tree/2.0.66. Running cargo fmt in that repo produces the incorrect diff seen in dtolnay/syn#1672.

The oldest version of rustfmt that exhibits this issue is the one that shipped with Rust 1.38; rustfmt in older Rust releases leaves the original code unmodified.

@dtolnay
Copy link
Member Author

dtolnay commented May 28, 2024

According to bisect, this regressed between nightly-2019-07-25 and nightly-2019-07-31 (the dates in between are missing the rustfmt component). The only PR touching rust-lang/rust's src/tools/rustfmt in that range is rust-lang/rust#62805, so the relevant rustfmt commit range is 66c27c9...9e960e7.

#3691 looks suspiciously relevant based on these changes it causes to some of the tests.

image

@dtolnay dtolnay changed the title Rustfmt misaligns comment between rustfmt::skip modules Rustfmt misaligns doc comment between rustfmt::skip modules May 28, 2024
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