Skip to content

Import sorting breaks with long paths #5829

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

Closed
lovesegfault opened this issue Jul 12, 2023 · 4 comments
Closed

Import sorting breaks with long paths #5829

lovesegfault opened this issue Jul 12, 2023 · 4 comments

Comments

@lovesegfault
Copy link
Contributor

Given the following code:

use zsome_other_crate_with_long_name::baz_baz_baz_baz_baz_baz_baz::baz_baz_baz_baz_baz::BazBazBazBazBaz;
use ayet_another_crate_with_a_really_big_name::bar_bar_bar_bar_bar_bar_bar_bar_bar::bar_bar_bar_bar_bar::BarBarBarBarBarBarBarBarBar;

playground link

I would expect rustfmt to reorder those two, resulting in:

use ayet_another_crate_with_a_really_big_name::bar_bar_bar_bar_bar_bar_bar_bar_bar::bar_bar_bar_bar_bar::BarBarBarBarBarBarBarBarBar;
use zsome_other_crate_with_long_name::baz_baz_baz_baz_baz_baz_baz::baz_baz_baz_baz_baz::BazBazBazBazBaz;

However, if you test it, rustfmt leaves the ordering unchanged, which, I believe, is a bug.

@lovesegfault
Copy link
Contributor Author

If you configure max_width to a large number, it works as expected.

@ytmimi
Copy link
Contributor

ytmimi commented Jul 12, 2023

@lovesegfault thanks for reaching out, and for digging into this a little yourself.

This is indeed a max_width issue. max_width is a hard constraint for rustfmt, and I don't think that's going to change anytime soon. Unfortunately this doesn't seem to be actionable at this time so I'm going to go ahead and close this.

@ytmimi ytmimi closed this as not planned Won't fix, can't repro, duplicate, stale Jul 12, 2023
@lovesegfault
Copy link
Contributor Author

@ytmimi I don't think solving this necessarily requires fiddling with max_width though, right?

For example, it could attempt to format that long import as:

use ayet_another_crate_with_a_really_big_name::{
    bar_bar_bar_bar_bar_bar_bar_bar_bar::{
        bar_bar_bar_bar_bar::BarBarBarBarBarBarBarBarBar;
    }
};

To keep it under max_width?

@ytmimi
Copy link
Contributor

ytmimi commented Jul 12, 2023

I believe something similar was proposed in #4746, specifically #4746 (comment)

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

No branches or pull requests

2 participants