-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #332 from calebcartwright/rustfmt-sorting
2024: rustfmt sorting
- Loading branch information
Showing
4 changed files
with
50 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Rustfmt: Version sorting | ||
|
||
🚧 The 2024 Edition has not yet been released and hence this section is still "under construction". | ||
|
||
More information may be found in the tracking issues at <https://github.com/rust-lang/rust/issues/123800> and <https://github.com/rust-lang/rust/issues/123802>. | ||
|
||
## Summary | ||
|
||
`rustfmt` utilizes a new sorting algorithm. | ||
|
||
## Details | ||
|
||
The [Rust Style Guide] includes [rules for sorting][sorting] that `rustfmt` applies in various contexts, such as on imports. | ||
|
||
Previous versions of the Style Guide and Rustfmt generally used an "ASCIIbetical" based approach. In the 2024 Edition this is changed to use a version-sort like algorithm that compares Unicode characters lexicographically and provides better results in ASCII digit comparisons. | ||
|
||
For example with a given (unsorted) input: | ||
|
||
```rust,ignore | ||
use std::num::{NonZeroU32, NonZeroU16, NonZeroU8, NonZeroU64}; | ||
use std::io::{Write, Read, stdout, self}; | ||
``` | ||
|
||
In the prior Editions, `rustfmt` would have produced: | ||
|
||
```rust,ignore | ||
use std::io::{self, stdout, Read, Write}; | ||
use std::num::{NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8}; | ||
``` | ||
|
||
In the 2024 Edition, `rustfmt` now produces: | ||
|
||
```rust,ignore | ||
use std::io::{self, Read, Write, stdout}; | ||
use std::num::{NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64}; | ||
``` | ||
|
||
[Rust Style Guide]: ../../style-guide/index.html | ||
[sorting]: ../../style-guide/index.html#sorting | ||
|
||
## Migration | ||
|
||
The change can be applied automatically by running `cargo fmt` or `rustfmt` with the 2024 Edition. See the [Style edition] chapter for more information on migrating and how style editions work. | ||
|
||
[Style edition]: rustfmt-style-edition.md |