Skip to content

proposal: groupping of imports #2979

@fulara

Description

@fulara

In clang-format recently the grouping and sorting of includes was introduced.
see: clang-format search for IncludeCategories
Where one is able to specify via regex some index and based on that the sorting is applied.

Since rust has proper import and crates we dont need any regex driven categories to achieve sorting.

It would be nice if cargo-fmt not only sorted includes alphabetically but also groupped them.
something like:

  1. std
  2. alphabetically sorted 3rd party imports, so first uses from use a::b; and then use b::c etc.
  3. alphabetically sorted workspace imports.
  4. alphabetically sorted this crate imports.

Inserting blank lines between these groups above

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-importsArea: imports, e.g. `use` syntaxC-feature-requestCategory: a feature request (not decided/implemented)

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions