bug: imports_granularity = "One" deletes aliases
I would like to open issue #5131 again with:
Modified https://github.com/rust-lang/rustfmt/blob/master/tests/source/5131_one.rs:
// rustfmt-imports_granularity: One
pub use foo::x;
pub use foo::x as x2;
pub use foo::y;
use bar::a;
use bar::b;
use bar::b::f;
use bar::b::f as f2;
use bar::b::g;
use bar::c;
use bar::d::e;
use bar::d::e as e2;
use qux::h;
use qux::i;
use qux::i as j; // added this alias
And modified https://github.com/rust-lang/rustfmt/blob/master/tests/target/5131_one.rs:
// rustfmt-imports_granularity: One
pub use foo::{x, x as x2, y};
use {
bar::{
a,
b::{self, f, g},
c,
d::{e, e as e2},
},
qux::{h, i, i as j}, // expected, but fails
};
I tested this with rev 6356fca675bd756d71f5c123cd053d17b16c573e. I assume, this (prefix == 0 && a.equal_except_alias(b)) || a == b needs some adjustment.
I guess the issue is:
use foo::module;
use foo::module as mydyl;
should be merged as:
use foo::module::{self, self as mydyl};
But functions should be merged differently:
use foo::do_something;
use foo::do_something as do_it;
as:
use foo:::{do_something, do_something as do_it};
There could be some heuristics implemented to check if the item is self-able (modules, types…), e.g. if there is some foo::bar or mod foo, but this would not catch the first example.
Linking the tracking issue for imports_granularity https://github.com/rust-lang/rustfmt/issues/4991