Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mnkhouri opened this issue Jun 11, 2024 · 0 comments · May be fixed by #6192
Open

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

mnkhouri opened this issue Jun 11, 2024 · 0 comments · May be fixed by #6192
Labels
a-imports `use` syntax only-with-option requires a non-default option value to reproduce

Comments

@mnkhouri
Copy link

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;
@ytmimi ytmimi added only-with-option requires a non-default option value to reproduce a-imports `use` syntax labels Jun 11, 2024
mnkhouri added a commit to mnkhouri/rustfmt that referenced this issue Jun 11, 2024
When merging imports using `imports_granularity="Module"`, individual
crate imports should get their own `use` statement on a new line.

```
// Before this commit:
use {library1, library2 as lib2, library3};

// After this commit:
use library1;
use library2 as lib2;
use library3;
```

Fixes: rust-lang#6191
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-imports `use` syntax only-with-option requires a non-default option value to reproduce
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants