Skip to content

Commit 0b6ce17

Browse files
update
1 parent 572a872 commit 0b6ce17

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/tokens.md

+19-4
Original file line numberDiff line numberDiff line change
@@ -758,25 +758,34 @@ r[lex.token.life.syntax]
758758
>       `'` [IDENTIFIER_OR_KEYWORD][identifier]
759759
> _(not immediately followed by `'`)_\
760760
>    | `'_`
761-
> _(not immediately followed by `'`)_
761+
> _(not immediately followed by `'`)_\
762762
>    | RAW_LIFETIME
763763
>
764764
> LIFETIME_OR_LABEL :\
765765
>       `'` [NON_KEYWORD_IDENTIFIER][identifier]
766766
> _(not immediately followed by `'`)_\
767767
>    | `'_`
768-
> _(not immediately followed by `'`)_
768+
> _(not immediately followed by `'`)_\
769769
>    | RAW_LIFETIME
770770
>
771771
> RAW_LIFETIME :\
772-
>       `'r#` [IDENTIFIER_OR_KEYWORD][identifier]
772+
>    `'r#` [IDENTIFIER_OR_KEYWORD][identifier]
773773
> _(not immediately followed by `'`)_
774774
775775
r[lex.token.life.intro]
776776
Lifetime parameters and [loop labels] use LIFETIME_OR_LABEL tokens. Any
777777
LIFETIME_TOKEN will be accepted by the lexer, and for example, can be used in
778778
macros.
779779

780+
r[lex.token.life.raw.intro]
781+
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.)
782+
783+
r[lex.token.life.raw.allowed]
784+
Unlike a normal lifetime, a raw lifetime may be any strict or reserved keyword.
785+
786+
> **Edition differences**: Raw lifetimes are accepted in the 2021
787+
> edition or later. In earlier additions the token `'r#lt` is lexed as `'r # lt`.
788+
780789
## Punctuation
781790

782791
r[lex.token.punct]
@@ -857,7 +866,8 @@ r[lex.token.reserved-prefix.syntax]
857866
> **<sup>Lexer 2021+</sup>**\
858867
> RESERVED_TOKEN_DOUBLE_QUOTE : ( IDENTIFIER_OR_KEYWORD <sub>_Except `b` or `c` or `r` or `br` or `cr`_</sub> | `_` ) `"`\
859868
> RESERVED_TOKEN_SINGLE_QUOTE : ( IDENTIFIER_OR_KEYWORD <sub>_Except `b`_</sub> | `_` ) `'`\
860-
> RESERVED_TOKEN_POUND : ( IDENTIFIER_OR_KEYWORD <sub>_Except `r` or `br` or `cr`_</sub> | `_` ) `#`
869+
> RESERVED_TOKEN_POUND : ( IDENTIFIER_OR_KEYWORD <sub>_Except `r` or `br` or `cr`_</sub> | `_` ) `#`\
870+
> RESERVED_TOKEN_LIFETIME : `'` (IDENTIFIER_OR_KEYWORD <sub>_Except `r`_</sub> | _) `#`
861871
862872
r[lex.token.reserved-prefix.intro]
863873
Some lexical forms known as _reserved prefixes_ are reserved for future use.
@@ -871,6 +881,9 @@ Note that raw identifiers, raw string literals, and raw byte string literals may
871881
r[lex.token.reserved-prefix.strings]
872882
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.
873883

884+
r[lex.token.reserved-prefix.life]
885+
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.
886+
874887
r[lex.token.reserved-prefix.edition2021]
875888
> **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).
876889
>
@@ -883,6 +896,7 @@ r[lex.token.reserved-prefix.edition2021]
883896
> lexes!{continue 'foo}
884897
> lexes!{match "..." {}}
885898
> lexes!{r#let#foo} // three tokens: r#let # foo
899+
> lexes!{'prefix #lt}
886900
> ```
887901
>
888902
> Examples accepted before the 2021 edition but rejected later:
@@ -891,6 +905,7 @@ r[lex.token.reserved-prefix.edition2021]
891905
> lexes!{a#foo}
892906
> lexes!{continue'foo}
893907
> lexes!{match"..." {}}
908+
> lexes!{'prefix#lt}
894909
> ```
895910
896911
[Inferred types]: types/inferred.md

0 commit comments

Comments
 (0)