Skip to content

Commit

Permalink
Merge PR #321: Add rustfmt raw ident sorting doc
Browse files Browse the repository at this point in the history
  • Loading branch information
traviscross committed Oct 19, 2024
2 parents 2f9cfbc + 8b64b52 commit dae0f58
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
- [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: Raw identifier sorting](rust-2024/rustfmt-raw-identifier-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)
Expand Down
50 changes: 50 additions & 0 deletions src/rust-2024/rustfmt-raw-identifier-sorting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 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 issue at <https://github.com/rust-lang/rust/issues/124764>.

## Summary

`rustfmt` now properly sorts [raw identifiers].

[raw identifiers]: ../../reference/identifiers.html#raw-identifiers

## Details

The [Rust Style Guide] includes [rules for sorting][sorting] that `rustfmt` applies in various contexts, such as on imports.

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:

```rust
use websocket::client::ClientBuilder;
use websocket::r#async::futures::Stream;
use websocket::result::WebSocketError;
```

In the 2024 Edition, `rustfmt` now produces:

```rust
use websocket::r#async::futures::Stream;
use websocket::client::ClientBuilder;
use websocket::result::WebSocketError;
```

[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.

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
```

0 comments on commit dae0f58

Please sign in to comment.