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 Unicode string comparison for sortable identifiers #5075

Open
KamilaBorowska opened this issue Nov 10, 2021 · 1 comment
Open

Use Unicode string comparison for sortable identifiers #5075

KamilaBorowska opened this issue Nov 10, 2021 · 1 comment

Comments

@KamilaBorowska
Copy link

Rust supports Unicode identifiers (https://rust-lang.github.io/rfcs/2457-non-ascii-idents.html). I think it would make sense for rustfmt to sort identifiers according to Unicode collation rather than Unicode codepoint ordering.

The following code:

use example::{e, é, f};

Is formatted like this:

use example::{e, f, é};

As é is later in Unicode than f.

I think it would make sense to for it to be ordered like {e, é, f}.

Different languages have different collations. It would useful for rustfmt to provide an option to configure locale with a default setting und (which is good enough for most languages).

@calebcartwright
Copy link
Member

calebcartwright commented Dec 15, 2021

The Rust Style Guide that codifies the rules rustfmt must obey is very explicit about the sort order being asciibetical

https://github.com/rust-dev-tools/fmt-rfcs/blob/master/guide/items.md#ordering-list-import
rust-lang/style-team#24

And that's not something that we can just change, neither in rustfmt nor the style guide. In general I agree that we need something better here (even if a non-default option) but there's a lot of things that need to get sorted (no pun intended 😆) before we can identify the right foot forward.

This is functionally a duplicate of #3242 as the asciibetical prescriptions apply to both, and the PR that wanted to pivot to natural sorting was targeting a hypothetical breaking major release of rustfmt that's not going to happen any time soon, and may not happen outside an ecosystem wide 2.0 rust release.

See also rust-lang/style-team#143

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

No branches or pull requests

3 participants