From d736d664724efe78c0113fb79403856af0b2ab4d Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Sun, 3 Nov 2024 18:13:48 -0600 Subject: [PATCH 1/4] add rustfmt sorting --- src/SUMMARY.md | 1 + src/rust-2024/rustfmt-sorting.md | 43 ++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/rust-2024/rustfmt-sorting.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 58569215..71c43532 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -51,6 +51,7 @@ - [Rustfmt: Combine all delimited exprs as last argument](rust-2024/rustfmt-overflow-delimited-expr.md) - [Rustfmt: Raw identifier sorting](rust-2024/rustfmt-raw-identifier-sorting.md) - [Rustfmt: Style Edition](rust-2024/rustfmt-style-edition.md) + - [Rustfmt: sorting](rust-2024/rustfmt-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-sorting.md b/src/rust-2024/rustfmt-sorting.md new file mode 100644 index 00000000..1c335fec --- /dev/null +++ b/src/rust-2024/rustfmt-sorting.md @@ -0,0 +1,43 @@ +# Rustfmt: Raw identifier 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. \ No newline at end of file From ff1ed7b921d5a4ee269928daa156983164ca7752 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 18 Nov 2024 11:33:56 -0800 Subject: [PATCH 2/4] Reuse the style edition chapter for rustfmt migration instructions --- src/rust-2024/rustfmt-raw-identifier-sorting.md | 14 ++------------ src/rust-2024/rustfmt-sorting.md | 4 +++- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/rust-2024/rustfmt-raw-identifier-sorting.md b/src/rust-2024/rustfmt-raw-identifier-sorting.md index c61a37a7..5c91f67b 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-sorting.md b/src/rust-2024/rustfmt-sorting.md index 1c335fec..abc8bfa2 100644 --- a/src/rust-2024/rustfmt-sorting.md +++ b/src/rust-2024/rustfmt-sorting.md @@ -40,4 +40,6 @@ use std::num::{NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64}; ## Migration -The change can be applied automatically by running `cargo fmt` or `rustfmt` with the 2024 Edition. \ No newline at end of file +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 From 36e80e79cdd85d48d5c76e369c493ddae8e0a817 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 18 Nov 2024 11:40:08 -0800 Subject: [PATCH 3/4] Rename rustfmt-sorting This is to differentiate with rustfmt-raw-identifier-sorting. --- src/SUMMARY.md | 2 +- .../{rustfmt-sorting.md => rustfmt-version-sorting.md} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/rust-2024/{rustfmt-sorting.md => rustfmt-version-sorting.md} (100%) diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 71c43532..72abf8c9 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -51,7 +51,7 @@ - [Rustfmt: Combine all delimited exprs as last argument](rust-2024/rustfmt-overflow-delimited-expr.md) - [Rustfmt: Raw identifier sorting](rust-2024/rustfmt-raw-identifier-sorting.md) - [Rustfmt: Style Edition](rust-2024/rustfmt-style-edition.md) - - [Rustfmt: sorting](rust-2024/rustfmt-sorting.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-sorting.md b/src/rust-2024/rustfmt-version-sorting.md similarity index 100% rename from src/rust-2024/rustfmt-sorting.md rename to src/rust-2024/rustfmt-version-sorting.md From 7826b2cee282e86b0824546d220e940e06fa7f83 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 18 Nov 2024 11:42:18 -0800 Subject: [PATCH 4/4] Fix chapter title and use consistent capitalization We generally use sentence case for chapter titles. --- src/SUMMARY.md | 2 +- src/rust-2024/rustfmt-style-edition.md | 2 +- src/rust-2024/rustfmt-version-sorting.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 72abf8c9..873dd4e2 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -49,8 +49,8 @@ - [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) diff --git a/src/rust-2024/rustfmt-style-edition.md b/src/rust-2024/rustfmt-style-edition.md index e7c3765c..d48bb796 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 index abc8bfa2..499a524f 100644 --- a/src/rust-2024/rustfmt-version-sorting.md +++ b/src/rust-2024/rustfmt-version-sorting.md @@ -1,4 +1,4 @@ -# Rustfmt: Raw identifier sorting +# Rustfmt: Version sorting 🚧 The 2024 Edition has not yet been released and hence this section is still "under construction".