Skip to content

Commit dae0f58

Browse files
committed
Merge PR #321: Add rustfmt raw ident sorting doc
2 parents 2f9cfbc + 8b64b52 commit dae0f58

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
- [Cargo: Table and key name consistency](rust-2024/cargo-table-key-names.md)
4848
- [Cargo: Reject unused inherited default-features](rust-2024/cargo-inherited-default-features.md)
4949
- [Rustfmt: Combine all delimited exprs as last argument](rust-2024/rustfmt-overflow-delimited-expr.md)
50+
- [Rustfmt: Raw identifier sorting](rust-2024/rustfmt-raw-identifier-sorting.md)
5051
- [`gen` keyword](rust-2024/gen-keyword.md)
5152
- [Macro fragment specifiers](rust-2024/macro-fragment-specifiers.md)
5253
- [Missing macro fragment specifiers](rust-2024/missing-macro-fragment-specifiers.md)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Rustfmt: Raw identifier 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 issue at <https://github.com/rust-lang/rust/issues/124764>.
6+
7+
## Summary
8+
9+
`rustfmt` now properly sorts [raw identifiers].
10+
11+
[raw identifiers]: ../../reference/identifiers.html#raw-identifiers
12+
13+
## Details
14+
15+
The [Rust Style Guide] includes [rules for sorting][sorting] that `rustfmt` applies in various contexts, such as on imports.
16+
17+
Prior to the 2024 Edition, when sorting rustfmt would use the leading `r#` token instead of the ident which led to unwanted results. For example:
18+
19+
```rust
20+
use websocket::client::ClientBuilder;
21+
use websocket::r#async::futures::Stream;
22+
use websocket::result::WebSocketError;
23+
```
24+
25+
In the 2024 Edition, `rustfmt` now produces:
26+
27+
```rust
28+
use websocket::r#async::futures::Stream;
29+
use websocket::client::ClientBuilder;
30+
use websocket::result::WebSocketError;
31+
```
32+
33+
[Rust Style Guide]: ../../style-guide/index.html
34+
[sorting]: ../../style-guide/index.html#sorting
35+
36+
## Migration
37+
38+
The change can be applied automatically by running `cargo fmt` or `rustfmt` with the 2024 Edition.
39+
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+
```

0 commit comments

Comments
 (0)