Auto combining shared prefix "use ...."

  1. Suppose we have a code block like:
use foobar::A;
use foobar::B;
use foobar::C;

Is there some way of having rust-fmt (or some other tool) to automatically replace it with:

use foobar::{A, B, C}


  1. I find the latter easier to read / more organized; but often end up with the former due to IntelliIJ auto adding imports locally which I then move to

You can try creating rustfmt.toml with the following contents

merge_imports = true


(This requires using nightly toolchain though, as the option is still unstable)


Works perfectly (even from IntelliJ). Thanks!