Rustfmt deletes comments in trait declarations
Open
Nobody has claimed this yet.
1x-backport:pending
A-comments
C-bug
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
Describe the bug
I have the following piece of code:
pub trait Foo<'a, 'b>
where
'a: 'b, // Some random comment
{
}
Which rustfmt reformats to:
pub trait Foo<'a, 'b>
where
'a: 'b,
{
}
Deleting the comment
To Reproduce
Run cargo fmt with the first code block results in the second code block
Expected behavior
The comment should not be deleted
Meta
- rustfmt version:
rustfmt 1.4.25-stable. Reddit user u/m0rphism also reports it can be reproduced withrustfmt 1.4.9-nightly - From where did you install rustfmt?:
rustup - How do you run rustfmt:
cargo fmt& from vscode
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 trait declaration shown in the report and run cargo fmt using the reported rustfmt setup. Check whether the inline comment after the lifetime bound is retained; done means cargo fmt no longer deletes that comment.
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
- Clearly specified
- Newbie friendliness
- 45/100