Skip to content

Should group_imports apply to function bodies? #6704

@camsteffen

Description

@camsteffen

In Rust, you can write imports inside of function bodies. This is usually used for one or a small few imports that are relevant to that function. There is a clear distinction between these two kinds of places in the Rust AST (items vs. statements) so I think it may be reasonable to have different rules in how they are handled.

My concern is that, since the number of imports inside of function bodes is usually small, group_imports will often result in separating two or three imports with blank lines, and this will feel noisy.

(Contrived) example:

fn my_function(thing: Bar) {
    use std::collections::hash_map::Entry::*;

    use foo::Bar::*;

    match thing {
        Sally(..) => ..,
        Sammy(..) => ..,

vs.

fn my_function(thing: Bar) {
    use std::collections::hash_map::Entry::*;
    use foo::Bar::*;

    match thing {
        Sally(..) => ..,
        Sammy(..) => ..,

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions