Skip to content

Commit baa3d73

Browse files
committed
Document r#_ and 'r#_ as reserved
These are rejected by the lexer.
1 parent f490b7c commit baa3d73

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/identifiers.md

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ r[ident.syntax]
1414
>
1515
> IDENTIFIER :\
1616
> NON_KEYWORD_IDENTIFIER | RAW_IDENTIFIER
17+
>
18+
> RESERVED_RAW_IDENTIFIER : `r#_`
1719
1820
<!-- When updating the version, update the UAX links, too. -->
1921
r[ident.unicode]
@@ -71,6 +73,10 @@ r[ident.raw.allowed]
7173
Unlike a normal identifier, a raw identifier may be any strict or reserved
7274
keyword except the ones listed above for `RAW_IDENTIFIER`.
7375

76+
r[ident.raw.reserved]
77+
It is an error to use the RESERVED_RAW_IDENTIFIER token `r#_` in order to avoid confusion with the [_WildcardPattern_].
78+
79+
[_WildcardPattern_]: patterns.md#wildcard-pattern
7480
[`extern crate`]: items/extern-crates.md
7581
[`no_mangle`]: abi.md#the-no_mangle-attribute
7682
[`path` attribute]: items/modules.md#the-path-attribute

src/tokens.md

+7
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,9 @@ r[lex.token.life.syntax]
769769
> RAW_LIFETIME :\
770770
> &nbsp;&nbsp; `'r#` [IDENTIFIER_OR_KEYWORD][identifier] <sub>*Except `crate`, `self`, `super`, `Self`*</sub>
771771
> _(not immediately followed by `'`)_
772+
>
773+
> RESERVED_RAW_LIFETIME : `'r#_`
774+
> _(not immediately followed by `'`)_
772775
773776
r[lex.token.life.intro]
774777
Lifetime parameters and [loop labels] use LIFETIME_OR_LABEL tokens. Any
@@ -781,6 +784,9 @@ A raw lifetime is like a normal lifetime, but its identifier is prefixed by `r#`
781784
r[lex.token.life.raw.allowed]
782785
Unlike a normal lifetime, a raw lifetime may be any strict or reserved keyword except the ones listed above for `RAW_LIFETIME`.
783786

787+
r[lex.token.life.raw.reserved]
788+
It is an error to use the RESERVED_RAW_LIFETIME token `'r#_` in order to avoid confusion with the [placeholder lifetime].
789+
784790
r[lex.token.life.raw.edition2021]
785791
> **Edition differences**: Raw lifetimes are accepted in the 2021
786792
> edition or later. In earlier additions the token `'r#lt` is lexed as `'r # lt`.
@@ -946,6 +952,7 @@ r[lex.token.reserved-prefix.edition2021]
946952
[numeric types]: types/numeric.md
947953
[paths]: paths.md
948954
[patterns]: patterns.md
955+
[placeholder lifetime]: lifetime-elision.md
949956
[question]: expressions/operator-expr.md#the-question-mark-operator
950957
[range]: expressions/range-expr.md
951958
[rangepat]: patterns.md#range-patterns

0 commit comments

Comments
 (0)