Imports are not formatted when long import lines are present
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
On some inputs containing long lines, rustfmt makes no changes, either to those lines or any other imports. Using shorter identifiers fixes the problem.
To Reproduce
Run rustup run nightly rustfmt --verbose --config imports_granularity=Crate --emit stdout on this input file:
use foo::bar;
use foo::{quuz, baz};
use abaadfsasdfdsfdfas::aasdffjsioejr::abc::sdsdf::sdfsdfsdf::sdfsdfdsf::{
asdfasdefasdasdfsdfdfasdf::asdfasdasedfafasdfasdf,
};
The input file will be returned unchanged.
Expected behavior
Delete the final s from the initial abaadfsasdfdsfdfas and the correct behavior is seen; the output is
use abaadfsasdfdsfdfa::aasdffjsioejr::abc::sdsdf::sdfsdfsdf::sdfsdfdsf::asdfasdefasdasdfsdfdfasdf::asdfasdasedfafasdfasdf;
use foo::{bar, baz, quuz};
I can reproduce the same behavior with merge_imports=true on stable.
Meta
- rustfmt version:
rustup run nightly rustfmt --versionreturnsrustfmt 1.4.36-nightly (7de6968 2021-02-07). - From where did you install rustfmt?:
rustup - How do you run rustfmt:
rustfmt
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 running the reported rustup nightly rustfmt command with imports_granularity=Crate on the supplied input, then repeat with merge_imports=true on stable. Compare the unchanged output with the expected merged and sorted imports, and consider the issue resolved when both configurations format the long import and the other imports as shown.
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