Skip to content

rustfmt does not collapse foo::{self} #5398

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
stepancheg opened this issue Jun 22, 2022 · 2 comments
Closed

rustfmt does not collapse foo::{self} #5398

stepancheg opened this issue Jun 22, 2022 · 2 comments

Comments

@stepancheg
Copy link
Contributor

use foo::self;

is collapsed to:

use foo;

But this:

use foo::{self};

is kept as is.

Used rustfmt from master (2022 Jun 22) with rustfmt.toml from rustfmt repo.

This behavior doesn't look intentional.

@ytmimi
Copy link
Contributor

ytmimi commented Jun 22, 2022

@stepancheg, thanks for reaching out.

I can't find any great documentation on the topic, but the two cases you mention aren't equivalent. The best resource I can link you to are the discussions in #3568, #4681, and rust-lang/rust#60941

A brief summary of the issue is that each import brings different things into scope so converting use foo::{self}; to use foo; could cause compilation problems. rustfmt can't safely make that transformation and leaves the import alone.

@ytmimi ytmimi closed this as not planned Won't fix, can't repro, duplicate, stale Jun 22, 2022
@stepancheg
Copy link
Contributor Author

@ytmimi thank you for the explanations!

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