diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 5856921..873dd4e 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -49,8 +49,9 @@ - [Cargo: Table and key name consistency](rust-2024/cargo-table-key-names.md) - [Cargo: Reject unused inherited default-features](rust-2024/cargo-inherited-default-features.md) - [Rustfmt: Combine all delimited exprs as last argument](rust-2024/rustfmt-overflow-delimited-expr.md) + - [Rustfmt: Style edition](rust-2024/rustfmt-style-edition.md) - [Rustfmt: Raw identifier sorting](rust-2024/rustfmt-raw-identifier-sorting.md) - - [Rustfmt: Style Edition](rust-2024/rustfmt-style-edition.md) + - [Rustfmt: Version sorting](rust-2024/rustfmt-version-sorting.md) - [`gen` keyword](rust-2024/gen-keyword.md) - [Macro fragment specifiers](rust-2024/macro-fragment-specifiers.md) - [Missing macro fragment specifiers](rust-2024/missing-macro-fragment-specifiers.md) diff --git a/src/rust-2024/rustfmt-raw-identifier-sorting.md b/src/rust-2024/rustfmt-raw-identifier-sorting.md index c61a37a..5c91f67 100644 --- a/src/rust-2024/rustfmt-raw-identifier-sorting.md +++ b/src/rust-2024/rustfmt-raw-identifier-sorting.md @@ -35,16 +35,6 @@ use websocket::result::WebSocketError; ## Migration -The change can be applied automatically by running `cargo fmt` or `rustfmt` with the 2024 Edition. +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. -With a `Cargo.toml` file that has `edition` set to `2024`, run: - -```sh -cargo fmt -``` - -Or run `rustfmt` directly: - -```sh -rustfmt foo.rs --style-edition 2024 -``` +[Style edition]: rustfmt-style-edition.md diff --git a/src/rust-2024/rustfmt-style-edition.md b/src/rust-2024/rustfmt-style-edition.md index e7c3765..d48bb79 100644 --- a/src/rust-2024/rustfmt-style-edition.md +++ b/src/rust-2024/rustfmt-style-edition.md @@ -1,4 +1,4 @@ -# Rustfmt: Style Edition +# Rustfmt: Style edition 🚧 The 2024 Edition has not yet been released and hence this section is still "under construction". diff --git a/src/rust-2024/rustfmt-version-sorting.md b/src/rust-2024/rustfmt-version-sorting.md new file mode 100644 index 0000000..499a524 --- /dev/null +++ b/src/rust-2024/rustfmt-version-sorting.md @@ -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 and . + +## 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