Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add rustfmt raw identifer sorting doc #321

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/rust-2024/rustfmt-raw-identifiers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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 <https://github.com/rust-lang/rust/issues/124764>.

## Summary

`rustfmt` now properly sorts [raw identifiers].

[raw identifiers]: https://doc.rust-lang.org/rust-by-example/compatibility/raw_identifiers.html

## 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 specious results.

For example:

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

Which is now corrected in the 2024 Edition:

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

[Rust Style Guide]: https://doc.rust-lang.org/nightly/style-guide/index.html
[sorting]: https://doc.rust-lang.org/stable/style-guide/index.html?highlight=sort#sorting
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a suggestion to remove the highlighting.

Suggested change
[sorting]: https://doc.rust-lang.org/stable/style-guide/index.html?highlight=sort#sorting
[sorting]: https://doc.rust-lang.org/stable/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`:

```sh
cargo fmt
```

Or by running `rustfmt` directly:

```sh
rustfmt foo.rs --style-edition 2024
```