Skip to content

Comments on extern crates that are reordered get misplaced #3127

New issue

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

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

Already on GitHub? # to your account

Open
shepmaster opened this issue Oct 22, 2018 · 3 comments
Open

Comments on extern crates that are reordered get misplaced #3127

shepmaster opened this issue Oct 22, 2018 · 3 comments

Comments

@shepmaster
Copy link
Member

0.99.6-nightly (2018-10-18 750b252)

Before

extern crate serde; // 1.0.78
extern crate serde_json; // 1.0.27
extern crate serde_derive; // 1.0.78

After

extern crate serde; // 1.0.78
extern crate serde_derive;
extern crate serde_json; // 1.0.27 // 1.0.78

Expected

extern crate serde; // 1.0.78
extern crate serde_derive; // 1.0.78
extern crate serde_json; // 1.0.27 
@nrc
Copy link
Member

nrc commented Nov 15, 2018

Happens with use imports too

@nrc
Copy link
Member

nrc commented Nov 15, 2018

See #3128 (comment) for an explanation of why.

After some investigation it seems that fixing this is pretty difficult, so un-blocking the milestone, would be good to fix this though.

@nrc nrc removed this from the 1.0 (edition rc1) milestone Nov 15, 2018
@topecongiro topecongiro added the a-imports `use` syntax label Jun 7, 2020
whizsid added a commit to whizsid/rustfmt that referenced this issue Feb 20, 2021
@ytmimi
Copy link
Contributor

ytmimi commented Jul 20, 2022

Confirming I can still reproduce this with rustfmt 1.5.1-nightly (f2c31ba0 2022-07-19). The issue is with reorder_imports, which is a stable option. One way to work around this is to set reorder_imports=false.

input

extern crate serde; // 1.0.78
extern crate serde_json; // 1.0.27
extern crate serde_derive; // 1.0.78

output reorder_imports=false

extern crate serde; // 1.0.78
extern crate serde_json; // 1.0.27
extern crate serde_derive; // 1.0.78

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

4 participants