rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

Don't merge crates when `imports_granularity="Module"`

Open mnkhouri opened this issue 1 year ago • 3 comments

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: #6191

mnkhouri avatar Jun 11 '24 18:06 mnkhouri

I haven't really reviewed this, but I quickly tested out this branch on this input:

use library1;
use library1::one;
use library1::two;
use library2 as lib2;
use library3;

which produced this output:

use library1;
use library1::{one, two};
use library2 as lib2;
use library3;

It seems reasonable to me, but I'm wondering if it would be expected to produce the following instead:

use library1::{self, one, two};
use library2 as lib2;
use library3;

ytmimi avatar Jul 06 '24 19:07 ytmimi

Thanks for trying it out!

but I'm wondering if it would be expected to produce the following instead

I personally would also prefer the second output rather than the first, but I think this is out of scope for this PR because I think aliasing module to module::self is a separate issue -- there's some discussion in https://github.com/rust-lang/rustfmt/pull/6028#issuecomment-1894143286 which suggests that use library1 and use library1::{self} are semantically different, and that we shouldn't convert between the two forms

mnkhouri avatar Jul 06 '24 19:07 mnkhouri

Hi, hoping we could bump this.

zerny avatar Mar 10 '25 09:03 zerny