rust-lang / rust-lang/rustfmt

`imports_granularity = "Module"` doesn't work if module path is too long

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

Nobody has claimed this yet.

C-bug only-with-option UO-imports_granularity
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

Repro steps

  1. Add the following inputs to tests/source/5131_module.rs.
  2. Execute cargo test test::system_tests and get output.
case 1. correct

Input:

use foo::{
    Foo,
    bar::Bar,
};

Output:

use foo::bar::Bar;
use foo::Foo;
case 2. wrong

Input:

use foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo::{
    Foo,
    bar::Bar,
};

Output:

use foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo::{
    Foo,
    bar::Bar,
};

Expected:

use foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo::bar::Bar;
use foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo::Foo;
case 3. wrong

Input:

use x::fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo::{
    Foo,
    bar::Bar,
};

Output:

use x::fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo::{
    Foo,
    bar::Bar,
};

Expected:

use x::fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo::bar::Bar;
use x::fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo::Foo;

Link: #4991

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_module.rs and run cargo test test::system_tests using the three long-module-path cases described here. Done means imports_granularity = "Module" produces separate imports for Foo and bar::Bar in cases 2 and 3, matching the expected output.

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.