[WIP] feat: imports: flatten last {self} segments#6950
Conversation
|
@rustbot label +E-help-wanted |
|
We will not add an option for this. self imports are semantically different. |
I understand that self imports can have semantic differences in certain contexts, but since the official Rust Style Guide explicitly mandates this normalization ( Is the goal for rustfmt to eventually comply with this part of the style guide, or is this a deliberate and permanent divergence? I'd like to know where this decision, or the mention of an option for this behavior came from. For convenience, i have traced the Style Guide normalization decisions back to their roots:
nrc's comment on import equivalence: rust-lang/style-team#24 (comment)
|
|
@Paladynee see #6129 and the linked issues. It's possible that these semantic differences have been addressed in new Rust language editions, but from what I remember |
this PR adds a feature that aims to do these conversions when in
Itemimports granularity:rationale
3rd and 1st clause of https://doc.rust-lang.org/style-guide/items.html?highlight=imports#normalisation combined.
personal rationale
The
Itemimports granularity is to have a single Item for each import. whileuse thing::{self};satisfies being a single import, it often gets formatted like this:which goes against the use case of
Itemgranularity for having a flat column ofusekeywords, and not introduce random indentations everywhere, and avoid cognitive load caused by theself. you'll usually never seeuse a::self;oruse a::{self};inItemimport granularity, as it is meaningless module indirection overhead. in fact, i'd argueselfimports in general inItemimport granularity are completely useless.HELP NEEDED
i currently implemented half of the functionality inside
flatten_use_treesusing a new method forUseTreenamedflatten_trailing_self. I mostly don't know the codebase, there was a feature i wanted and i decided to implement it so its sloppy but it works EXCEPT while flattening the last List segment that only contains a singleSlfsegment, the comments surrounding them (if any) are lost.i modified a single test (you can see in the commit diff) to reflect all of the changes this PR should make. the rest of the test file should stay intact (preserving the comments) without flattening the List segment to the parent ident, and i have no idea how to do it properly.
it probably mostly goes through
UseTree.list_itembut i'm not sure. any and all help is appreciated!