Skip to content

Commit 0cbff13

Browse files
add rustfmt raw identifer sorting doc
1 parent b3ca7ad commit 0cbff13

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 <https://github.com/rust-lang/rust/issues/124764>.
6+
7+
## Summary
8+
9+
`rustfmt` now properly sorts [raw identifiers].
10+
11+
[raw identifiers]: https://doc.rust-lang.org/rust-by-example/compatibility/raw_identifiers.html
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 specious results.
18+
19+
For example:
20+
21+
```rust
22+
use websocket::client::ClientBuilder;
23+
use websocket::r#async::futures::Stream;
24+
use websocket::result::WebSocketError;
25+
```
26+
27+
Which is now corrected in the 2024 Edition:
28+
29+
```rust
30+
use websocket::r#async::futures::Stream;
31+
use websocket::client::ClientBuilder;
32+
use websocket::result::WebSocketError;
33+
```
34+
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
37+
38+
## Migration
39+
40+
The change can be applied automatically by running `cargo fmt` or `rustfmt` with the 2024 Edition.
41+
42+
With a Cargo.toml file that has `edition` set to `2024`:
43+
44+
```sh
45+
cargo fmt
46+
```
47+
48+
Or by running `rustfmt` directly:
49+
50+
```sh
51+
rustfmt foo.rs --style-edition 2024
52+
```

0 commit comments

Comments
 (0)