-
Notifications
You must be signed in to change notification settings - Fork 532
Raw lifetimes #1603
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
Raw lifetimes #1603
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ef87ed6
Raw lifetimes
compiler-errors df53c5e
Don't allow `'r#kw'`
compiler-errors 5c0c306
update
compiler-errors f04cd63
Clarify raw lifetime cannot be certain keywords
ehuss f490b7c
Add rule name for raw lifetime edition differences
ehuss baa3d73
Document r#_ and 'r#_ as reserved
ehuss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -758,17 +758,39 @@ r[lex.token.life.syntax] | |
> `'` [IDENTIFIER_OR_KEYWORD][identifier] | ||
> _(not immediately followed by `'`)_\ | ||
> | `'_` | ||
> _(not immediately followed by `'`)_ | ||
> _(not immediately followed by `'`)_\ | ||
> | RAW_LIFETIME | ||
> | ||
> LIFETIME_OR_LABEL :\ | ||
> `'` [NON_KEYWORD_IDENTIFIER][identifier] | ||
> _(not immediately followed by `'`)_\ | ||
> | RAW_LIFETIME | ||
compiler-errors marked this conversation as resolved.
Show resolved
Hide resolved
|
||
> | ||
> RAW_LIFETIME :\ | ||
> `'r#` [IDENTIFIER_OR_KEYWORD][identifier] <sub>*Except `crate`, `self`, `super`, `Self`*</sub> | ||
> _(not immediately followed by `'`)_ | ||
> | ||
> RESERVED_RAW_LIFETIME : `'r#_` | ||
> _(not immediately followed by `'`)_ | ||
|
||
r[lex.token.life.intro] | ||
Lifetime parameters and [loop labels] use LIFETIME_OR_LABEL tokens. Any | ||
LIFETIME_TOKEN will be accepted by the lexer, and for example, can be used in | ||
macros. | ||
|
||
r[lex.token.life.raw.intro] | ||
A raw lifetime is like a normal lifetime, but its identifier is prefixed by `r#`. (Note that the `r#` prefix is not included as part of the actual lifetime.) | ||
|
||
r[lex.token.life.raw.allowed] | ||
Unlike a normal lifetime, a raw lifetime may be any strict or reserved keyword except the ones listed above for `RAW_LIFETIME`. | ||
|
||
r[lex.token.life.raw.reserved] | ||
It is an error to use the RESERVED_RAW_LIFETIME token `'r#_` in order to avoid confusion with the [placeholder lifetime]. | ||
|
||
r[lex.token.life.raw.edition2021] | ||
> **Edition differences**: Raw lifetimes are accepted in the 2021 | ||
> edition or later. In earlier additions the token `'r#lt` is lexed as `'r # lt`. | ||
|
||
## Punctuation | ||
|
||
r[lex.token.punct] | ||
|
@@ -849,7 +871,8 @@ r[lex.token.reserved-prefix.syntax] | |
> **<sup>Lexer 2021+</sup>**\ | ||
> RESERVED_TOKEN_DOUBLE_QUOTE : ( IDENTIFIER_OR_KEYWORD <sub>_Except `b` or `c` or `r` or `br` or `cr`_</sub> | `_` ) `"`\ | ||
> RESERVED_TOKEN_SINGLE_QUOTE : ( IDENTIFIER_OR_KEYWORD <sub>_Except `b`_</sub> | `_` ) `'`\ | ||
> RESERVED_TOKEN_POUND : ( IDENTIFIER_OR_KEYWORD <sub>_Except `r` or `br` or `cr`_</sub> | `_` ) `#` | ||
> RESERVED_TOKEN_POUND : ( IDENTIFIER_OR_KEYWORD <sub>_Except `r` or `br` or `cr`_</sub> | `_` ) `#`\ | ||
> RESERVED_TOKEN_LIFETIME : `'` (IDENTIFIER_OR_KEYWORD <sub>_Except `r`_</sub> | _) `#` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is isn't reserving But I'm not sure it's worth trying to get all the |
||
|
||
r[lex.token.reserved-prefix.intro] | ||
Some lexical forms known as _reserved prefixes_ are reserved for future use. | ||
|
@@ -863,6 +886,9 @@ Note that raw identifiers, raw string literals, and raw byte string literals may | |
r[lex.token.reserved-prefix.strings] | ||
Similarly the `r`, `b`, `br`, `c`, and `cr` prefixes used in raw string literals, byte literals, byte string literals, raw byte string literals, C string literals, and raw C string literals are not interpreted as reserved prefixes. | ||
|
||
r[lex.token.reserved-prefix.life] | ||
Source input which would otherwise be lexically interpreted as a non-raw lifetime (or a keyword or `_`) which is immediately followed by a `#` character (without intervening whitespace) is identified as a reserved lifetime prefix. | ||
|
||
r[lex.token.reserved-prefix.edition2021] | ||
> **Edition differences**: Starting with the 2021 edition, reserved prefixes are reported as an error by the lexer (in particular, they cannot be passed to macros). | ||
> | ||
|
@@ -875,6 +901,7 @@ r[lex.token.reserved-prefix.edition2021] | |
> lexes!{continue 'foo} | ||
> lexes!{match "..." {}} | ||
> lexes!{r#let#foo} // three tokens: r#let # foo | ||
> lexes!{'prefix #lt} | ||
> ``` | ||
> | ||
> Examples accepted before the 2021 edition but rejected later: | ||
|
@@ -883,6 +910,7 @@ r[lex.token.reserved-prefix.edition2021] | |
> lexes!{a#foo} | ||
> lexes!{continue'foo} | ||
> lexes!{match"..." {}} | ||
> lexes!{'prefix#lt} | ||
> ``` | ||
|
||
[Inferred types]: types/inferred.md | ||
|
@@ -924,6 +952,7 @@ r[lex.token.reserved-prefix.edition2021] | |
[numeric types]: types/numeric.md | ||
[paths]: paths.md | ||
[patterns]: patterns.md | ||
[placeholder lifetime]: lifetime-elision.md | ||
[question]: expressions/operator-expr.md#the-question-mark-operator | ||
[range]: expressions/range-expr.md | ||
[rangepat]: patterns.md#range-patterns | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.