Skip to content

imports_granularity=One removes macro imports that share names with modules #6717

@lars-schumann

Description

@lars-schumann
#![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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICEI-changes-semanticsIssue: changes observable semantics of the code (even if code still compiles!)I-invalid-codeIssue: formatting causes compile-pass code to compile-failS-has-mcveStatus: a Minimal Complete and Verifiable Example has been found for this issueUO-imports_granularityUnstable option: imports_granularityonly-with-optionRequires a non-default option value to reproduce

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions