Skip to content

two runs required on imports with leading :: #3943

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

Open
calebcartwright opened this issue Nov 26, 2019 · 3 comments
Open

two runs required on imports with leading :: #3943

calebcartwright opened this issue Nov 26, 2019 · 3 comments
Labels
a-imports `use` syntax bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce

Comments

@calebcartwright
Copy link
Member

Formatting can take two runs when imports are using absolute paths and include leading :: (when using the 2018 edition config option)

Original source:

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

1st formatting result:

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

And then second formatting run to get the final result:

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

Seems to be related to the first run reducing ::{Foo} to ::Foo but without fully sorting/reordering the set of imports, and then the second run sorting them to finish formatting.

@topecongiro topecongiro added bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce labels Nov 27, 2019
@topecongiro topecongiro added the a-imports `use` syntax label Jun 30, 2020
davidBar-On added a commit to davidBar-On/rustfmt that referenced this issue Dec 15, 2020
@ytmimi
Copy link
Contributor

ytmimi commented Jul 21, 2022

Confirming this is still an issue using rustfmt 1.5.1-nightly (f2c31ba0 2022-07-19)

@ytmimi
Copy link
Contributor

ytmimi commented Jul 26, 2022

I believe this is also an issue with --edition=2021

@davidBar-On
Copy link
Contributor

I tried with the latest nightly master and it seems that the issue does not exist - no need for two runs.

However, the output is:

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

The :: is removed from all lines and I don't know whether this is o.k.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-imports `use` syntax bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce
Projects
None yet
Development

No branches or pull requests

4 participants