Skip to content

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

@kenoss

Description

@kenoss

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

Activity

kenoss

kenoss commented on May 15, 2024

@kenoss
Author

I'm planning to investigate it.

kenoss

kenoss commented on May 18, 2024

@kenoss
Author

Failed here:

shape = shape.offset_left(2 + segment_str.len())?;

[src/imports.rs:1089:9] "rewrite of UseTree starts" = "rewrite of UseTree starts"
[src/imports.rs:1095:13] &segment = foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
[src/imports.rs:1095:13] &segment_str = "foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
[src/imports.rs:1095:13] &result = "foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
[src/imports.rs:1099:17] &shape = Shape {
    width: 95,
    indent: Indent {
        block_indent: 0,
        alignment: 0,
    },
    offset: 4,
}
[src/imports.rs:1099:17] shape.offset_left(2 + segment_str.len()) = Some(
    Shape {
        width: 4,
        indent: Indent {
            block_indent: 0,
            alignment: 0,
        },
        offset: 95,
    },
)
[src/imports.rs:1099:17] segment_str.len() = 89
[src/imports.rs:1095:13] &segment = bar
[src/imports.rs:1095:13] &segment_str = "bar"
[src/imports.rs:1095:13] &result = "foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo::bar"
[src/imports.rs:1099:17] &shape = Shape {
    width: 4,
    indent: Indent {
        block_indent: 0,
        alignment: 0,
    },
    offset: 95,
}
[src/imports.rs:1099:17] shape.offset_left(2 + segment_str.len()) = None
[src/imports.rs:1099:17] segment_str.len() = 3
[src/imports.rs:338:9] self.rewrite(context, shape.offset_left(vis.len())?) = None

TODO(tomorrow): Understand what Shape is.

added 2 commits that reference this issue on May 19, 2024
6af27ae
0b85501
added 3 commits that reference this issue on May 28, 2024
d9a349c
6a22eca
a0cfa0b
added 2 commits that reference this issue on Jun 20, 2024
2ad2d35
041d1c0
added a commit that references this issue on Jul 10, 2024
ed1684d
added a commit that references this issue on Jul 20, 2024
d2d82d8
added a commit that references this issue on Aug 20, 2024
d312aab
added a commit that references this issue on Dec 17, 2024
5ee8434
added a commit that references this issue on May 13, 2025
af7ffb5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @kenoss

      Issue actions

        `imports_granularity = "Module"` doesn't work if module path is too long · Issue #6164 · rust-lang/rustfmt