Skip to content

automatically merge multiple use statements from the same crate #6658

@hailangx

Description

@hailangx

Currently, rustfmt does not automatically merge multiple use statements from the same crate or module into a single, aligned use statement. For example, given the following imports:

use crate::backend::index::build::InsertBuildStats;
use crate::backend::index::update::UpdateStageResults;
use crate::utils::{self, fmt, MaybeDisplay};
use crate::{
    backend::index::update::UpdateResults,
    benchmark::inputs::async::InplaceDeleteMethod,
    utils::{datafiles::UpdateOperationType, percentiles,},
};

It would be preferable if rustfmt could merge and align these into a single, more concise and organized statement, such as:

use crate::{
    backend::index::{
        build::InsertBuildStats,
        update::{UpdateStageResults, UpdateResults},
    },
    benchmark::inputs::async::InplaceDeleteMethod,
    utils::{self, fmt, MaybeDisplay, datafiles::UpdateOperationType, percentiles},
};

Expected Behavior:

rustfmt should automatically merge and align use statements that share a common root.
The merged statement should be formatted according to rustfmt’s existing style conventions for multi-line imports.
Motivation:

Merging imports improves code readability and reduces duplication.
It also helps maintain a cleaner and more idiomatic Rust codebase.
Request: Please consider adding an option or enhancing the default behavior to merge and align related use statements as illustrated above.

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