Skip to content

x.py tidy forces use path::{...} to come after use path::m::{...}; makes commits noisy. #88029

Open
@pnkfelix

Description

@pnkfelix

(This may be a rustfmt bug, rather than a rustc bootstrap issue. But I just wanted to file it somewhere before I forgot about it.)

Today, if you have:

use rustc_middle::middle::cstore::CrateDepKind;
use rustc_middle::middle::cstore::LinkagePreference::{self, RequireDynamic, RequireStatic};

and you want to import rustc_middle::middle::cstore::CStore, you could write

use rustc_middle::middle::cstore::CrateDepKind;
use rustc_middle::middle::cstore::CStore; // <--- new line
use rustc_middle::middle::cstore::LinkagePreference::{self, RequireDynamic, RequireStatic};

But one might rightly think that's overly verbose; why not use a {...} block on the first use?

But if you try that, and write:

use rustc_middle::middle::cstore::{CrateDepKind, CStore}; // <--- changed line
use rustc_middle::middle::cstore::LinkagePreference::{self, RequireDynamic, RequireStatic};

then x.py tidy complains, and says it wants you to rewrite it as:

use rustc_middle::middle::cstore::LinkagePreference::{self, RequireDynamic, RequireStatic};
use rustc_middle::middle::cstore::{CrateDepKind, CStore}; // <--- changed and *moved* line

This seems wrong to me.

if I had to guess, I'd infer that the rustfmt algorithm is using a naive alphabetical ordering on the lines, rather than considering the higher level module tree structure. Looking at it from the view point of putting nodes closer to the tree's root first, everything for use path::{...} should come before use path::m::{...}, right?

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