rust-lang / rust-lang/rustfmt

bug: imports_granularity = "One" deletes aliases

Open
#6,027 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-imports C-bug I-changes-semantics UO-imports_granularity
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with tests/source/5131_one.rs and tests/target/5131_one.rs, using the modified reproducer in the issue to inspect imports_granularity = "One" handling. Trace the grouping logic around the reported (prefix == 0 && a.equal_except_alias(b)) || a == b condition. Done means the qux alias is preserved in the formatted output and the relevant rustfmt test passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.