Skip to content

2024: Add reserved syntax #326

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

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Make some editorial tweaks
  • Loading branch information
traviscross committed Oct 18, 2024
commit dceaaca744d1d68266a70f9ae4d4552583c7fc91
11 changes: 7 additions & 4 deletions src/rust-2024/reserved-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ More information may be found in the tracking issue at <https://github.com/rust-

## Details

[RFC 3593] reserved syntax in the 2024 Edition for guarded string literals that do not have a prefix to future-proof against future language changes. The 2021 Edition [reserved syntax][2021] for guarded strings with a prefix, such as `ident##"foo"##`. The 2024 Edition extends that to also reserve strings without the `ident` prefix.
[RFC 3593] reserved syntax in the 2024 Edition for guarded string literals that do not have a prefix to make room for possible future language changes. The 2021 Edition [reserved syntax][2021] for guarded strings with a prefix, such as `ident##"foo"##`. The 2024 Edition extends that to also reserve strings without the `ident` prefix.

There are two reserved syntaxes: One or more `#` immediately followed by a [string literal], and two or more `#` characters in a row.
There are two reserved syntaxes:

This reservation is done across an edition boundary because of interactions with tokenization and macros. For example, with the following macro:
- One or more `#` characters immediately followed by a [string literal].
- Two or more `#` characters in a row (not separated by whitespace).

This reservation is done across an edition boundary because of interactions with tokenization and macros. For example, consider this macro:

```rust
macro_rules! demo {
Expand Down Expand Up @@ -45,7 +48,7 @@ Starting in the 2024 Edition, the `#"foo"#` line and the `###` line now generate

## Migration

The [`rust_2024_guarded_string_incompatible_syntax`] lint will identify any tokens that match the reserved syntax, and will suggest a modification to insert spaces where necessary to ensure it continues to be parsed as separate tokens.
The [`rust_2024_guarded_string_incompatible_syntax`] lint will identify any tokens that match the reserved syntax, and will suggest a modification to insert spaces where necessary to ensure the tokens continue to be parsed separately.

The lint is part of the `rust-2024-compatibility` lint group which is included in the automatic edition migration. In order to migrate your code to be Rust 2024 Edition compatible, run:

Expand Down