Rustfmt incorrectly strips comments when removing empty where clause
Open
Nobody has claimed this yet.
A-comments
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
Empty where clauses are semantically valid Rust. However rustfmt incorrectly removes them and comments.
Before:
trait Foo {
fn bar(&self)
where
// Self: Bar
// Some comment
;
}
fn foo<T>()
where
// T: Bar,
// Some comment
{
println!("foo");
}
After:
trait Foo {
fn bar(&self);
}
fn foo<T>() {
println!("foo");
}
rustfmt 1.4.25-stable (0f29ff6d 2020-11-11)
I also tested it on master a97fd770e322714933f6f05b6244303c50199dd3
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 two Rust snippets in the report and trace rustfmt's handling of empty where clauses. The fix is complete when formatting preserves the comments in both examples while still handling the empty clauses correctly; add regression coverage where the existing formatter tests for this behavior are found.
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