From 3faf1bef760f8d6387c10de31d23e7c03557cad4 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sat, 3 Jul 2021 00:02:55 -0700 Subject: [PATCH 1/3] reserving-syntax.md: Expand and add detail --- src/rust-2021/reserving-syntax.md | 39 +++++++++++++++++-------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/rust-2021/reserving-syntax.md b/src/rust-2021/reserving-syntax.md index 52f8e122..0980a08f 100644 --- a/src/rust-2021/reserving-syntax.md +++ b/src/rust-2021/reserving-syntax.md @@ -2,44 +2,47 @@ ## Summary -- `any_prefix#..`, `any_prefix".."`, and `any_prefix'..'` are reserved syntax, and no longer tokenize. +- `any_prefix#`, `any_prefix"..."`, and `any_prefix'...'` are now reserved + syntax, and no longer tokenize. - This is mostly relevant to macros. E.g. `quote!{ #a#b }` is no longer accepted. - It doesn't treat keywords specially, so e.g. `match".." {}` is no longer accepted. - Insert whitespace to avoid errors. ## Details -To make space for some new syntax in the future, +To make space for new syntax in the future, we've decided to reserve syntax for prefixed identifiers and literals: `prefix#identifier`, `prefix"string"`, `prefix'c'`, and `prefix#123`, where `prefix` can be any identifier. (Except those that already have a meaning, such as `b'…'` and `r"…"`.) +This provides syntax we can expand into in the future without requiring an +edition boundary. We may use that for temporary syntax until the next edition, +or for permanent syntax if appropriate. -This is a breaking change, since macros can currently accept `hello"world"`, -which they will see as two separate tokens: `hello` and `"world"`. -The (automatic) fix is simple though. Just insert a space: `hello "world"`. - - +Without an edition, this would be a breaking change, since macros can currently +accept syntax such as `hello"world"`, which they will see as two separate +tokens: `hello` and `"world"`. The (automatic) fix is simple though: just +insert a space: `hello "world"`. Likewise, `prefix#ident` should become +`prefix #ident`. Other than turning these into a tokenization error, [the RFC][10] does not attach a meaning to any prefix yet. Assigning meaning to specific prefixes is left to future proposals, -which will—thanks to reserving these prefixes now—not be breaking changes. - -These are some new prefixes you might see in the future: +which will now—thanks to reserving these prefixes—not be breaking changes. -- `f""` as a short-hand for a format string. - For example, `f"hello {name}"` as a short-hand for the equivalent `format_args!()` invocation. - -- `c""` or `z""` for null-terminated C strings. +Some new prefixes you might potentially see in the future (though we haven't +committed to any of them yet): - `k#keyword` to allow writing keywords that don't exist yet in the current edition. For example, while `async` is not a keyword in edition 2015, this prefix would've allowed us to accept `k#async` in edition 2015 without having to wait for edition 2018 to reserve `async` as a keyword. +- `f""` as a short-hand for a format string. + For example, `f"hello {name}"` as a short-hand for the equivalent `format!()` invocation. + +- `s""` for `String` literals. + +- `c""` or `z""` for null-terminated C strings. + [10]: https://github.com/rust-lang/rfcs/pull/3101 From b3ddaf41c79fa4618caa4975c087eede97cc36ed Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Wed, 21 Jul 2021 17:27:27 -0700 Subject: [PATCH 2/3] Minor wording and syntax improvements --- src/rust-2021/reserving-syntax.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/rust-2021/reserving-syntax.md b/src/rust-2021/reserving-syntax.md index 0980a08f..1eccee5d 100644 --- a/src/rust-2021/reserving-syntax.md +++ b/src/rust-2021/reserving-syntax.md @@ -2,10 +2,10 @@ ## Summary -- `any_prefix#`, `any_prefix"..."`, and `any_prefix'...'` are now reserved +- `any_identifier#`, `any_identifier"..."`, and `any_identifier'...'` are now reserved syntax, and no longer tokenize. - This is mostly relevant to macros. E.g. `quote!{ #a#b }` is no longer accepted. -- It doesn't treat keywords specially, so e.g. `match".." {}` is no longer accepted. +- It doesn't treat keywords specially, so e.g. `match"..." {}` is no longer accepted. - Insert whitespace to avoid errors. ## Details @@ -14,9 +14,11 @@ To make space for new syntax in the future, we've decided to reserve syntax for prefixed identifiers and literals: `prefix#identifier`, `prefix"string"`, `prefix'c'`, and `prefix#123`, where `prefix` can be any identifier. -(Except those that already have a meaning, such as `b'…'` and `r"…"`.) +(Except those prefixes that already have a meaning, such as `b'...'` (byte +strings) and `r"..."` (raw strings).) + This provides syntax we can expand into in the future without requiring an -edition boundary. We may use that for temporary syntax until the next edition, +edition boundary. We may use this for temporary syntax until the next edition, or for permanent syntax if appropriate. Without an edition, this would be a breaking change, since macros can currently From 02fece9f7aa5258a2eb8ff2e09d5dcc39d5caeaa Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Wed, 21 Jul 2021 17:27:40 -0700 Subject: [PATCH 3/3] Add more on migrations --- src/rust-2021/reserving-syntax.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rust-2021/reserving-syntax.md b/src/rust-2021/reserving-syntax.md index 1eccee5d..fd2f6264 100644 --- a/src/rust-2021/reserving-syntax.md +++ b/src/rust-2021/reserving-syntax.md @@ -6,7 +6,9 @@ syntax, and no longer tokenize. - This is mostly relevant to macros. E.g. `quote!{ #a#b }` is no longer accepted. - It doesn't treat keywords specially, so e.g. `match"..." {}` is no longer accepted. -- Insert whitespace to avoid errors. +- Insert whitespace between the identifier and the subsequent `#`, `"`, or `'` + to avoid errors. +- Edition migrations will help you insert whitespace in such cases. ## Details @@ -25,7 +27,7 @@ Without an edition, this would be a breaking change, since macros can currently accept syntax such as `hello"world"`, which they will see as two separate tokens: `hello` and `"world"`. The (automatic) fix is simple though: just insert a space: `hello "world"`. Likewise, `prefix#ident` should become -`prefix #ident`. +`prefix #ident`. Edition migrations will help with this fix. Other than turning these into a tokenization error, [the RFC][10] does not attach a meaning to any prefix yet.