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

Rustfmt does not format some redundant imports #4594

Closed
jyn514 opened this issue Dec 16, 2020 · 4 comments
Closed

Rustfmt does not format some redundant imports #4594

jyn514 opened this issue Dec 16, 2020 · 4 comments
Labels
bug Panic, non-idempotency, invalid code, etc.

Comments

@jyn514
Copy link
Member

jyn514 commented Dec 16, 2020

Describe the bug

Rustfmt does not normalize use std::rc::Weak as Weak; to use std::rc::Weak; in some cases.

To Reproduce

x.py fmt on https://github.com/rust-lang/rust/blob/c3ed6681ff8d446e68ce272be4bf66f4145f6e29/compiler/rustc_data_structures/src/sync.rs#L224

Expected behavior

It should turn that line into use std::rc::Weak;, the same way it does on playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=2fbcb920f10e1ad6b4883e3970eba5cc. I'm not sure why this only breaks on rustc.

Meta

  • rustfmt version: rustfmt: nightly-2020-11-19
  • From where did you install rustfmt?: however x.py downloads it, probably CI artifacts directly?
  • How do you run rustfmt: x.py fmt
@jyn514 jyn514 added the bug Panic, non-idempotency, invalid code, etc. label Dec 16, 2020
@jyn514
Copy link
Member Author

jyn514 commented Dec 16, 2020

This might be because it's inside a cfg_if!?

@jyn514
Copy link
Member Author

jyn514 commented Dec 16, 2020

@calebcartwright
Copy link
Member

Ok yes, this was because of the macro:

Correct. Mac call formatting is intentionally pretty limited for various reasons (complexity, failure to be semantics preserving, high potential for butchering, etc.) and that definitely holds true for items within cfg_if. rustfmt will recurse into and format any mods defined or imported within cfg_if, but not the items themselves

@calebcartwright
Copy link
Member

Going to go ahead and close as there's various other open issues like #8 around macro and mac call formatting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

No branches or pull requests

2 participants