Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a number-smart sorting function for imports #5130

Closed
scottmcm opened this issue Dec 11, 2021 · 2 comments
Closed

Use a number-smart sorting function for imports #5130

scottmcm opened this issue Dec 11, 2021 · 2 comments
Labels

Comments

@scottmcm
Copy link
Member

scottmcm commented Dec 11, 2021

Today, rustfmt reorders like this:

-use crate::num::{NonZeroI8, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI128, NonZeroIsize};
+use crate::num::{NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize};

Playground to repro: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=69ff891f23f740c0602c91da88d40b3f

I consider that ordering materially worse, since it's the biggest one, then three in ascending order, then the smallest one.

Because in type names people are unlikely to zero-pad, I think rustfmt should choose an ordering predicate that can pick up on numbers and sort that part numerically, as opposed to lexicographically-on-the-decimal-representation.

(Maybe do this along with #5075 that's also about the sorting predicate.)

@calebcartwright
Copy link
Member

Thanks, though going to close as a duplicate in a desire to attempt to consolidate the discussion on this recurring topic in one place (#5075 (comment))

@scottmcm
Copy link
Member Author

Ah, I see it came up in #3242 too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants