rust-lang / rust-lang/rustfmt

`imports_granularity` is not respected for `#[cfg]`'d items

Open
#6,666 2 comments 0 reactions 1 assignee View on GitHub

@dingxiangfei2009 is already working on this.

Since Jun 16, 2026.

A-cfg A-imports C-bug I-changes-semantics UO-imports_granularity
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

Example with imports_granularity = "crate". The following:

#[cfg(true)]
use std::{cmp::Ordering, hash::Hash, hash::Hasher};
use core::{cmp::Ordering, hash::Hash, hash::Hasher};

will normalise to:

#[cfg(true)]
use std::{cmp::Ordering, hash::Hash, hash::Hasher};
use core::{cmp::Ordering, hash::{Hash, Hasher}};

Note that the desire to avoid messing with cfgs is too conservative here: the imports are not grouped in the same way.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.