rust-lang / rust-lang/rustfmt

`use` imports are wrapped unless double-nested imports are present

Open
#3,286 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-imports I-poor-formatting
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

rustfmt gives this:

use {
    fidl_fuchsia_hardware_ethernet_ext::EthernetQueueFlags, futures::TryStreamExt, std::fs::File,
    structopt::StructOpt,
};

which is, IMO, pretty gross as it mixes imports from many different crates all together onto the same line.

Adding a group after _ext:: and adding Bar to it gives this:

use {
    fidl_fuchsia_hardware_ethernet_ext::{Bar, EthernetQueueFlags},
    futures::TryStreamExt,
    std::fs::File,
    structopt::StructOpt,
};

which is more like what I would expect. What's going on here? Is there a setting that can be enabled to always get the bottom layout, even when no nested groups are present?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two import examples from the issue and inspect rustfmt's import-formatting behavior and available configuration options. Determine whether an existing setting can produce the grouped layout, or define the behavior needed for a new option; done means imports from separate crates remain on separate lines without requiring a nested group.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.