Skip to content

bug: imports_granularity = "One" deletes aliases #6027

New issue

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

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

Already on GitHub? # to your account

Open
Tracked by #4991
sivizius opened this issue Jan 15, 2024 · 2 comments · May be fixed by #6028
Open
Tracked by #4991

bug: imports_granularity = "One" deletes aliases #6027

sivizius opened this issue Jan 15, 2024 · 2 comments · May be fixed by #6028
Labels
a-imports `use` syntax bug Panic, non-idempotency, invalid code, etc.

Comments

@sivizius
Copy link

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.

@sivizius
Copy link
Author

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.

@ytmimi ytmimi added the a-imports `use` syntax label Jan 15, 2024
@ytmimi
Copy link
Contributor

ytmimi commented Jan 15, 2024

Linking the tracking issue for imports_granularity #4991

@ytmimi ytmimi added the bug Panic, non-idempotency, invalid code, etc. label Jan 15, 2024
@sivizius sivizius linked a pull request Jan 15, 2024 that will close this issue
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
a-imports `use` syntax bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants