rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

Add option to put pub imports (aka exports) before normal imports

Open Boscop opened this issue 5 years ago • 2 comments

Context: When reorder_imports = true, rustfmt mixes pub imports in with private imports. Please add an option to put pub imports (aka exports) before normal imports. IMO it's not idiomatic to mix them in with normal imports because they are also exports and deserve extra attention so I usually put them before normal imports and then leave an empty line between.

Boscop avatar Mar 01 '20 06:03 Boscop

Also, I would REALLY appreciate a configuration option to order imports as follows:

pub imports (exports) imports from std, core, alloc etc. (the built-in crates) imports from third-party crates imports from crates of the current workspace imports from the current crate

With an optional empty line between each group. Can you please add this :)

Boscop avatar Mar 17 '20 23:03 Boscop

For someone who use group_imports = "StdExternalCrate" together with reorder_imports = true like me, my current workaround is

// define a macro somewhere
macro_rules! _____ {
    () => {};
}


// use the macro between `use`s to avoid grouping by rustfmt
pub use a;
pub use b;

_____!();

pub(crate) use c;
pub(crate) use d;

_____!();

use e;
use f;

LambdaAlpha avatar Jun 12 '25 01:06 LambdaAlpha