Skip to content

Commit 5c0c306

Browse files
compiler-errorsehuss
authored andcommitted
update
1 parent df53c5e commit 5c0c306

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

Diff for: src/tokens.md

+19-4
Original file line numberDiff line numberDiff line change
@@ -758,23 +758,32 @@ 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]
766-
> _(not immediately followed by `'`)_
766+
> _(not immediately followed by `'`)_\
767767
>    | RAW_LIFETIME
768768
>
769769
> RAW_LIFETIME :\
770-
>       `'r#` [IDENTIFIER_OR_KEYWORD][identifier]
770+
>    `'r#` [IDENTIFIER_OR_KEYWORD][identifier]
771771
> _(not immediately followed by `'`)_
772772
773773
r[lex.token.life.intro]
774774
Lifetime parameters and [loop labels] use LIFETIME_OR_LABEL tokens. Any
775775
LIFETIME_TOKEN will be accepted by the lexer, and for example, can be used in
776776
macros.
777777

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

780789
r[lex.token.punct]
@@ -855,7 +864,8 @@ r[lex.token.reserved-prefix.syntax]
855864
> **<sup>Lexer 2021+</sup>**\
856865
> RESERVED_TOKEN_DOUBLE_QUOTE : ( IDENTIFIER_OR_KEYWORD <sub>_Except `b` or `c` or `r` or `br` or `cr`_</sub> | `_` ) `"`\
857866
> RESERVED_TOKEN_SINGLE_QUOTE : ( IDENTIFIER_OR_KEYWORD <sub>_Except `b`_</sub> | `_` ) `'`\
858-
> RESERVED_TOKEN_POUND : ( IDENTIFIER_OR_KEYWORD <sub>_Except `r` or `br` or `cr`_</sub> | `_` ) `#`
867+
> RESERVED_TOKEN_POUND : ( IDENTIFIER_OR_KEYWORD <sub>_Except `r` or `br` or `cr`_</sub> | `_` ) `#`\
868+
> RESERVED_TOKEN_LIFETIME : `'` (IDENTIFIER_OR_KEYWORD <sub>_Except `r`_</sub> | _) `#`
859869
860870
r[lex.token.reserved-prefix.intro]
861871
Some lexical forms known as _reserved prefixes_ are reserved for future use.
@@ -869,6 +879,9 @@ Note that raw identifiers, raw string literals, and raw byte string literals may
869879
r[lex.token.reserved-prefix.strings]
870880
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.
871881

882+
r[lex.token.reserved-prefix.life]
883+
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.
884+
872885
r[lex.token.reserved-prefix.edition2021]
873886
> **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).
874887
>
@@ -881,6 +894,7 @@ r[lex.token.reserved-prefix.edition2021]
881894
> lexes!{continue 'foo}
882895
> lexes!{match "..." {}}
883896
> lexes!{r#let#foo} // three tokens: r#let # foo
897+
> lexes!{'prefix #lt}
884898
> ```
885899
>
886900
> Examples accepted before the 2021 edition but rejected later:
@@ -889,6 +903,7 @@ r[lex.token.reserved-prefix.edition2021]
889903
> lexes!{a#foo}
890904
> lexes!{continue'foo}
891905
> lexes!{match"..." {}}
906+
> lexes!{'prefix#lt}
892907
> ```
893908
894909
[Inferred types]: types/inferred.md

0 commit comments

Comments
 (0)