Skip to content

Add support for moving module imports into the same use statement as their children (with self) #4915

Closed
@zedseven

Description

@zedseven

When importing things, my IDE isn't very smart about how it adds new use statements. Thankfully rustfmt mostly cleans it up, but one thing it doesn't seem to do is move module imports into the same block as their children if some of their components are also imported.

A common case for me is when manually implementing Debug on something - I often end up with the following after rustfmt cleans up (with imports_granularity = "Crate"):

use std::{
	fmt,
	fmt::{Debug, Formatter},
};

...

impl Debug for MyStruct {
	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
		f.debug_struct("MyStruct")
			...
			.finish()
	}
}

It would be nice to have an option (or default behaviour, I'm not sure) to have rustfmt format the imports as:

use std::fmt::{self, Debug, Formatter};

...

It saves space, looks cleaner, and in a big import tree, makes it easier to read imo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions