rust-lang / rustfmt

Format Rust code
https://rust-lang.github.io/rustfmt/
Apache License 2.0
5.98k stars 878 forks source link

`imports_granularity = "Module"` merges top-level modules into a single `use` statement #6191

Open mnkhouri opened 3 months ago

mnkhouri commented 3 months ago

Documented behavior

The current docs for imports_granularity = "Module" say this:

Merge imports from the same module into a single use statement. Conversely, imports from different modules are split into separate statements.

The current example in docs looks like this:

use foo::b::{f, g};
use foo::d::e;
use foo::{a, b, c};
use qux::{h, i};

Current formatting of "top-level" modules

For imports of a entire modules, when the path only has a single item (no submodules), the current output when using imports_granularity = "Module" is to format like this:

use {library1, library2 as lib2, library3};

Suggested formatting of "top-level" modules

The docs say "imports from different modules are split into separate statements". My reading of the docs and my intuition would say the formatting should instead look like this:

use library1;
use library2 as lib2;
use library3;