Skip to content

Doc attribute normalization is incorrectly detected as comment loss #4879

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

Open
dtolnay opened this issue Jun 23, 2021 · 0 comments
Open

Doc attribute normalization is incorrectly detected as comment loss #4879

dtolnay opened this issue Jun 23, 2021 · 0 comments
Labels
a-comments only-with-option requires a non-default option value to reproduce p-low

Comments

@dtolnay
Copy link
Member

dtolnay commented Jun 23, 2021

Repro against current master (6495024):

$ echo '#[doc = "..."] static S: () = { #[doc = "..."] struct S; };' | CFG_RELEASE_CHANNEL=dev CFG_RELEASE=dev cargo run --bin rustfmt -- --edition=2018 --emit=stdout --config=normalize_doc_attributes=true

///...
static S: () = { #[doc = "..."] struct S; };

error[internal]: not formatted because a comment would be lost
 --> stdin:1
  |
1 | #[doc = "..."] static S: () = { #[doc = "..."] struct S; };
  |
  = note: set `error_on_unformatted = false` to suppress the warning against comments or string literals

warning: rustfmt has failed to format. See previous 1 errors.

You can see the first #[doc = "..."] is correctly normalized to ///... while the second is not, due to the printed internal error.

This seems like a consequence of normalize_doc_attributes=true because the following is formatted with no problem.

$ echo -e '///...\nstatic S: () = { ///...\nstruct S; };' | CFG_RELEASE_CHANNEL=dev CFG_RELEASE=dev cargo run --bin rustfmt -- --edition=2018 --emit=stdout --config=normalize_doc_attributes=true

///...
static S: () = {
    ///...
    struct S;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-comments only-with-option requires a non-default option value to reproduce p-low
Projects
None yet
Development

No branches or pull requests

3 participants