Skip to content

reorder_imports=false should still format the imports #3515

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
dtolnay opened this issue Apr 16, 2019 · 4 comments · Fixed by #3523
Closed

reorder_imports=false should still format the imports #3515

dtolnay opened this issue Apr 16, 2019 · 4 comments · Fixed by #3523
Labels
a-imports `use` syntax bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce
Milestone

Comments

@dtolnay
Copy link
Member

dtolnay commented Apr 16, 2019

Input file repro.rs:

use std :: fmt :: { self , Display } ;
use std :: collections :: HashMap ;

fn main() {}

Rustfmt invocation:

cargo run --bin rustfmt -- \
    path/to/repro.rs \
    --config-path <(echo reorder_imports=false) \
    --emit=stdout

Output as of current master branch, 34bf137:

use std :: fmt :: { self , Display } ;
use std :: collections :: HashMap ;

fn main() {}

Expected output, imports formatted but not reordered:

use std::fmt::{self, Display};
use std::collections::HashMap;

fn main() {}

I care about this for dtolnay/cargo-expand#56 in which I receive imports from a proc macro in TokenStream-style spaced out formatting and want to format them without reordering anything.

@dtolnay
Copy link
Member Author

dtolnay commented Apr 16, 2019

Note that reorder_modules=false seems to handle this correctly already. It turns:

mod b ;
mod a ;

into:

mod b;
mod a;

which is how I would expect.

@topecongiro topecongiro added a-imports `use` syntax bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce labels Apr 16, 2019
@scampi
Copy link
Contributor

scampi commented Apr 16, 2019

@dtolnay the rustfmt output was the original one in your description.

use std::collections::HashMap;
use std::fmt::{self, Display};

fn main() {}

@dtolnay
Copy link
Member Author

dtolnay commented Apr 16, 2019

@scampi you may not have set reorder_imports=false, since what you show has imports reordered.

@scampi
Copy link
Contributor

scampi commented Apr 16, 2019

@dtolnay indeed... sorry ;oD

topecongiro added a commit to topecongiro/rustfmt that referenced this issue Apr 22, 2019
@topecongiro topecongiro added this to the 1.2.2 milestone Apr 22, 2019
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

Successfully merging a pull request may close this issue.

3 participants