`rustfmt` needs more than 1 run to reach an idempotent state in some cases
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
Consider e.g. the following code:
#[derive(Clone, Debug)]
#[derive(Default, Copy, PartialEq, PartialOrd)]
pub struct Vec2D(pub [f32; 2usize]);
fn main() {}
Running cargo fmt once will get rid of the superfluous linefeed as you'd expect:
#[derive(Clone, Debug)]
#[derive(Default, Copy, PartialEq, PartialOrd)]
pub struct Vec2D(pub [f32; 2usize]);
fn main() {}
But since rustfmt doesn't seem to recurse, it doesn't notice that there's an opportunity to merge the two #derive clauses here, which leaves us in an awkward situation where things aren't quite fully formatted.
Running cargo fmt once more will merge the two #derive clauses and actually put us in an idempotent state this time:
#[derive(Clone, Debug, Default, Copy, PartialEq, PartialOrd)]
pub struct Vec2D(pub [f32; 2usize]);
fn main() {}
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 example with rustfmt or cargo fmt and compare the first and second formatting runs. Trace the formatting path responsible for removing blank lines and merging adjacent derive clauses, then add coverage showing that one run reaches the final idempotent output.
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