Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Open
kenoss opened this issue May 15, 2024 · 2 comments · May be fixed by #6165
Open

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

kenoss opened this issue May 15, 2024 · 2 comments · May be fixed by #6165

Comments

@kenoss
Copy link

kenoss commented May 15, 2024

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

@kenoss
Copy link
Author

kenoss commented May 15, 2024

I'm planning to investigate it.

@kenoss
Copy link
Author

kenoss commented May 18, 2024

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.

kenoss added a commit to kenoss/rustfmt that referenced this issue May 19, 2024
…anularity`

This patch reduces format failure for non default `imports_granularity`
and correct the behavior around some edge cases.

- Supports too long line of `use ...` that contains `{}`.
- Fixes the width calculation of too long lines of `use ...`.
kenoss added a commit to kenoss/rustfmt that referenced this issue May 19, 2024
…anularity`

This patch reduces format failure for non default `imports_granularity`
and correct the behavior around some edge cases.

- Supports too long line of `use ...` that contains `{}`.
- Fixes the width calculation of too long lines of `use ...`.
kenoss added a commit to kenoss/rustfmt that referenced this issue May 28, 2024
…anularity`

This patch reduces format failure for non default `imports_granularity`
and correct the behavior around some edge cases.

- Supports too long line of `use ...` that contains `{}`.
- Fixes the width calculation of too long lines of `use ...`.
kenoss added a commit to kenoss/rustfmt that referenced this issue Jun 1, 2024
…anularity`

This patch reduces format failure for non default `imports_granularity`
and correct the behavior around some edge cases.

- Supports too long line of `use ...` that contains `{}`.
- Fixes the width calculation of too long lines of `use ...`.
kenoss added a commit to kenoss/rustfmt that referenced this issue Jun 4, 2024
…anularity`

This patch reduces format failure for non default `imports_granularity`
and correct the behavior around some edge cases.

- Supports too long line of `use ...` that contains `{}`.
- Fixes the width calculation of too long lines of `use ...`.
kenoss added a commit to kenoss/rustfmt that referenced this issue Jun 20, 2024
…anularity`

This patch reduces format failure for non default `imports_granularity`
and correct the behavior around some edge cases.

- Supports too long line of `use ...` that contains `{}`.
- Fixes the width calculation of too long lines of `use ...`.
kenoss added a commit to kenoss/rustfmt that referenced this issue Jun 25, 2024
…anularity`

This patch reduces format failure for non default `imports_granularity`
and correct the behavior around some edge cases.

- Supports too long line of `use ...` that contains `{}`.
- Fixes the width calculation of too long lines of `use ...`.
kenoss added a commit to kenoss/rustfmt that referenced this issue Jul 10, 2024
…anularity`

This patch reduces format failure for non default `imports_granularity`
and correct the behavior around some edge cases.

- Supports too long line of `use ...` that contains `{}`.
- Fixes the width calculation of too long lines of `use ...`.
kenoss added a commit to kenoss/rustfmt that referenced this issue Jul 20, 2024
…anularity`

This patch reduces format failure for non default `imports_granularity`
and correct the behavior around some edge cases.

- Supports too long line of `use ...` that contains `{}`.
- Fixes the width calculation of too long lines of `use ...`.
kenoss added a commit to kenoss/rustfmt that referenced this issue Aug 20, 2024
…anularity`

This patch reduces format failure for non default `imports_granularity`
and correct the behavior around some edge cases.

- Supports too long line of `use ...` that contains `{}`.
- Fixes the width calculation of too long lines of `use ...`.
kenoss added a commit to kenoss/rustfmt that referenced this issue Dec 17, 2024
…anularity`

This patch reduces format failure for non default `imports_granularity`
and correct the behavior around some edge cases.

- Supports too long line of `use ...` that contains `{}`.
- Fixes the width calculation of too long lines of `use ...`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant