rust-lang / rust-lang/rustfmt

`imports_granularity=One` removes macro imports that share names with modules

Open
#6,717 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-changes-semantics I-invalid-code only-with-option S-has-mcve UO-imports_granularity
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

#![no_implicit_prelude]
extern crate alloc;

use alloc::boxed;
use alloc::vec;
use alloc::vec::Vec;

fn main() {
    let _: Vec<i32> = vec![];
}

turns into

#![no_implicit_prelude]
extern crate alloc;

use alloc::{
    boxed,
    vec::{self, Vec},
};

fn main() {
    let _: Vec<i32> = vec![];
}

after

$ rustfmt --unstable-features --config imports_granularity=One ./src/main.rs

This is no longer valid rust, as the vec! macro isnt in scope anymore.

tested on latest nightly:

$ rustfmt -V
rustfmt 1.8.0-nightly (d5419f1e97 2025-10-30)
$ rustc -V
rustc 1.93.0-nightly (d5419f1e9 2025-10-30)

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

Reproduce the issue from the provided src/main.rs example with rustfmt --unstable-features and imports_granularity=One. Trace the import-granularity handling and add a regression test covering a macro and module with the same name. Done means the formatted code still resolves vec! and remains valid Rust.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.