|
1 |
| -# Rustfmt: raw identifier sorting |
| 1 | +# Rustfmt: Raw identifier sorting |
2 | 2 |
|
3 | 3 | 🚧 The 2024 Edition has not yet been released and hence this section is still "under construction".
|
4 | 4 |
|
5 |
| -More information may be found in <https://github.com/rust-lang/rust/issues/124764>. |
| 5 | +More information may be found in the tracking issue at <https://github.com/rust-lang/rust/issues/124764>. |
6 | 6 |
|
7 | 7 | ## Summary
|
8 | 8 |
|
9 | 9 | `rustfmt` now properly sorts [raw identifiers].
|
10 | 10 |
|
11 |
| -[raw identifiers]: https://doc.rust-lang.org/rust-by-example/compatibility/raw_identifiers.html |
| 11 | +[raw identifiers]: ../../reference/identifiers.html#raw-identifiers |
12 | 12 |
|
13 | 13 | ## Details
|
14 | 14 |
|
15 | 15 | The [Rust Style Guide] includes [rules for sorting][sorting] that `rustfmt` applies in various contexts, such as on imports.
|
16 | 16 |
|
17 |
| -Prior to the 2024 Edition, when sorting rustfmt would use the leading `r#` token instead of the ident which led to specious results. |
18 |
| - |
19 |
| -For example: |
| 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: |
20 | 18 |
|
21 | 19 | ```rust
|
22 | 20 | use websocket::client::ClientBuilder;
|
23 | 21 | use websocket::r#async::futures::Stream;
|
24 | 22 | use websocket::result::WebSocketError;
|
25 | 23 | ```
|
26 | 24 |
|
27 |
| -Which is now corrected in the 2024 Edition: |
| 25 | +In the 2024 Edition, `rustfmt` now produces: |
28 | 26 |
|
29 | 27 | ```rust
|
30 | 28 | use websocket::r#async::futures::Stream;
|
31 | 29 | use websocket::client::ClientBuilder;
|
32 | 30 | use websocket::result::WebSocketError;
|
33 | 31 | ```
|
34 | 32 |
|
35 |
| -[Rust Style Guide]: https://doc.rust-lang.org/nightly/style-guide/index.html |
36 |
| -[sorting]: https://doc.rust-lang.org/stable/style-guide/index.html?highlight=sort#sorting |
| 33 | +[Rust Style Guide]: ../../style-guide/index.html |
| 34 | +[sorting]: ../../style-guide/index.html#sorting |
37 | 35 |
|
38 | 36 | ## Migration
|
39 | 37 |
|
40 | 38 | The change can be applied automatically by running `cargo fmt` or `rustfmt` with the 2024 Edition.
|
41 | 39 |
|
42 |
| -With a Cargo.toml file that has `edition` set to `2024`: |
| 40 | +With a `Cargo.toml` file that has `edition` set to `2024`, run: |
43 | 41 |
|
44 | 42 | ```sh
|
45 | 43 | cargo fmt
|
46 | 44 | ```
|
47 | 45 |
|
48 |
| -Or by running `rustfmt` directly: |
| 46 | +Or run `rustfmt` directly: |
49 | 47 |
|
50 | 48 | ```sh
|
51 | 49 | rustfmt foo.rs --style-edition 2024
|
|
0 commit comments