Rustfmt: Support for use_nested_groups Feature

Created on 19 Mar 2018  路  4Comments  路  Source: rust-lang/rustfmt

Now that https://github.com/rust-lang/rust/issues/44494 has been stabilized, it would be nice to have a rustfmt option to reformat all imports into the use_nested_groups format.

feature-request

Most helpful comment

We should decide what is the idiomatic way to use_nested_groups. For example, I had code like this:

use chalk_engine::{
    context,
    ExClause,
    hh::HhGoal,
};

use rustc::{
    infer::InferOk, 
    infer::canonical::{Canonical, CanonicalVarValues},
    traits::ProgramClause, 
    ty::subst::Kind,
    ty::{Binder, OutlivesPredicate, Region, Ty, TyCtxt},
};

which was reformatted into:

use chalk_engine::{context, ExClause, hh::HhGoal};

use rustc::{infer::InferOk, infer::canonical::{Canonical, CanonicalVarValues},
            traits::ProgramClause, ty::subst::Kind,
            ty::{Binder, OutlivesPredicate, Region, Ty, TyCtxt}};

The current output doesn't feel right to me; it's hard to skim the names etc, but I can see how rustfmt reached that point. I'm not sure if the style I was using is the "right" one, but I sort of like it: basically like having the first import (the crate) be special, and each line below is sort of like a use statement of its own.

All 4 comments

We should decide what is the idiomatic way to use_nested_groups. For example, I had code like this:

use chalk_engine::{
    context,
    ExClause,
    hh::HhGoal,
};

use rustc::{
    infer::InferOk, 
    infer::canonical::{Canonical, CanonicalVarValues},
    traits::ProgramClause, 
    ty::subst::Kind,
    ty::{Binder, OutlivesPredicate, Region, Ty, TyCtxt},
};

which was reformatted into:

use chalk_engine::{context, ExClause, hh::HhGoal};

use rustc::{infer::InferOk, infer::canonical::{Canonical, CanonicalVarValues},
            traits::ProgramClause, ty::subst::Kind,
            ty::{Binder, OutlivesPredicate, Region, Ty, TyCtxt}};

The current output doesn't feel right to me; it's hard to skim the names etc, but I can see how rustfmt reached that point. I'm not sure if the style I was using is the "right" one, but I sort of like it: basically like having the first import (the crate) be special, and each line below is sort of like a use statement of its own.

@nrc Should this be reopened, or should we open a new issue to discuss the formatting that @nikomatsakis mentioned above?

@cramertj we should discuss on rust-lang-nursery/fmt-rfcs#24

Was this page helpful?
0 / 5 - 0 ratings

Related issues

0x7CFE picture 0x7CFE  路  5Comments

Jerald picture Jerald  路  4Comments

MoSal picture MoSal  路  5Comments

jonhoo picture jonhoo  路  4Comments

tkilbourn picture tkilbourn  路  5Comments