Doc attribute normalization is incorrectly detected as comment loss
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
Repro against current master (6495024ddcb0986f7e3337f357dc0213e4daf62a):
$ 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;
};
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the rustfmt binary and normalize_doc_attributes=true using the command in the report. Compare the top-level and nested #[doc = "..."] attributes; done means both are normalized without the internal comment-loss error, while the provided already-formatted example remains successful.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100