Skip to content

Commit 07766cb

Browse files
authored
Merge pull request #332 from calebcartwright/rustfmt-sorting
2024: rustfmt sorting
2 parents 915f9b3 + 7826b2c commit 07766cb

File tree

4 files changed

+50
-14
lines changed

4 files changed

+50
-14
lines changed

src/SUMMARY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@
4949
- [Cargo: Table and key name consistency](rust-2024/cargo-table-key-names.md)
5050
- [Cargo: Reject unused inherited default-features](rust-2024/cargo-inherited-default-features.md)
5151
- [Rustfmt: Combine all delimited exprs as last argument](rust-2024/rustfmt-overflow-delimited-expr.md)
52+
- [Rustfmt: Style edition](rust-2024/rustfmt-style-edition.md)
5253
- [Rustfmt: Raw identifier sorting](rust-2024/rustfmt-raw-identifier-sorting.md)
53-
- [Rustfmt: Style Edition](rust-2024/rustfmt-style-edition.md)
54+
- [Rustfmt: Version sorting](rust-2024/rustfmt-version-sorting.md)
5455
- [`gen` keyword](rust-2024/gen-keyword.md)
5556
- [Macro fragment specifiers](rust-2024/macro-fragment-specifiers.md)
5657
- [Missing macro fragment specifiers](rust-2024/missing-macro-fragment-specifiers.md)

src/rust-2024/rustfmt-raw-identifier-sorting.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,6 @@ use websocket::result::WebSocketError;
3535

3636
## Migration
3737

38-
The change can be applied automatically by running `cargo fmt` or `rustfmt` with the 2024 Edition.
38+
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.
3939

40-
With a `Cargo.toml` file that has `edition` set to `2024`, run:
41-
42-
```sh
43-
cargo fmt
44-
```
45-
46-
Or run `rustfmt` directly:
47-
48-
```sh
49-
rustfmt foo.rs --style-edition 2024
50-
```
40+
[Style edition]: rustfmt-style-edition.md

src/rust-2024/rustfmt-style-edition.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Rustfmt: Style Edition
1+
# Rustfmt: Style edition
22

33
🚧 The 2024 Edition has not yet been released and hence this section is still "under construction".
44

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Rustfmt: Version sorting
2+
3+
🚧 The 2024 Edition has not yet been released and hence this section is still "under construction".
4+
5+
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>.
6+
7+
## Summary
8+
9+
`rustfmt` utilizes a new sorting algorithm.
10+
11+
## Details
12+
13+
The [Rust Style Guide] includes [rules for sorting][sorting] that `rustfmt` applies in various contexts, such as on imports.
14+
15+
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.
16+
17+
For example with a given (unsorted) input:
18+
19+
```rust,ignore
20+
use std::num::{NonZeroU32, NonZeroU16, NonZeroU8, NonZeroU64};
21+
use std::io::{Write, Read, stdout, self};
22+
```
23+
24+
In the prior Editions, `rustfmt` would have produced:
25+
26+
```rust,ignore
27+
use std::io::{self, stdout, Read, Write};
28+
use std::num::{NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8};
29+
```
30+
31+
In the 2024 Edition, `rustfmt` now produces:
32+
33+
```rust,ignore
34+
use std::io::{self, Read, Write, stdout};
35+
use std::num::{NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64};
36+
```
37+
38+
[Rust Style Guide]: ../../style-guide/index.html
39+
[sorting]: ../../style-guide/index.html#sorting
40+
41+
## Migration
42+
43+
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.
44+
45+
[Style edition]: rustfmt-style-edition.md

0 commit comments

Comments
 (0)