From afeea28243b62936c7913ba29d5fc8cc5d607c0f Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 18 Aug 2026 14:42:07 -0700 Subject: [PATCH 1/3] Fix the grammar for string continuation String continuation includes all of the following TAB/LF/CR/SP characters immediately following the next line. This was clarified and documented in https://github.com/rust-lang/reference/pull/1042, but we didn't update the grammar at the same time. This corrects that to include those spaces. This fixes an issue with strings such as: $' "string\\\n\n\r\tcontinuation"' (using shell escaping to illustrate newlines and carriage returns). There the bare CR should be allowed due to this special-casing for continuations. --- src/tokens.md | 2 +- src/whitespace.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tokens.md b/src/tokens.md index 1d48380aad..fe4d9dee3e 100644 --- a/src/tokens.md +++ b/src/tokens.md @@ -179,7 +179,7 @@ STRING_LITERAL -> | STRING_CONTINUE )* `"` SUFFIX? -STRING_CONTINUE -> `\` LF +STRING_CONTINUE -> `\` LF [TAB LF CR SP]* ``` r[lex.token.literal.str.intro] diff --git a/src/whitespace.md b/src/whitespace.md index 7e16c51d41..9034b7fa79 100644 --- a/src/whitespace.md +++ b/src/whitespace.md @@ -21,6 +21,8 @@ TAB -> U+0009 // Horizontal tab, `'\t'` LF -> U+000A // Line feed, `'\n'` CR -> U+000D // Carriage return, `'\r'` + +SP -> U+0020 // Space, `' '` ``` r[lex.whitespace.intro] From 3befb8bdf6a90f6ca5896c532e8618f7f23fddb7 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 18 Aug 2026 14:44:47 -0700 Subject: [PATCH 2/3] Fix the grammar for OUTER_BLOCK_DOC and bare CR This fixes an issue where OUTER_BLOCK_DOC was allowing bare CR as the first character when it shouldn't have. This fixes an issue with comments such as: $'/**\r CR starting block doc comment */' (using shell escaping to illustrate newlines and carriage returns). There the bare CR should not be allowed and should result in a parse error. --- src/comments.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/comments.md b/src/comments.md index f39fcd3927..b5ff203e15 100644 --- a/src/comments.md +++ b/src/comments.md @@ -35,7 +35,7 @@ OUTER_LINE_DOC -> OUTER_BLOCK_DOC -> `/**` ![`*` `/`] ^ - ( ~`*` | BLOCK_COMMENT_OR_DOC ) + ( ~[`*` CR] | BLOCK_COMMENT_OR_DOC ) ( BLOCK_COMMENT_OR_DOC | BLOCK_CHAR )* `*/` From 5b328bcf7e5e56c5cd3c660655348c2d85dea5cf Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 18 Aug 2026 14:55:47 -0700 Subject: [PATCH 3/3] Fix BLOCK_COMMENT in the context of SHEBANG This fixes an issue with the BLOCK_COMMENT grammar as it is used within the SHEBANG rule. The problem is that BLOCK_COMMENT was changed in https://github.com/rust-lang/reference/pull/2191 so that it relied on the order of how the comments were handled in the COMMENT rule to avoid ambiguity with OUTER_BLOCK_DOC. However, because SHEBANG is using the BLOCK_COMMENT rule directly, we need BLOCK_COMMENT to be able to stand on its own without relying on the order in COMMENT. This fixes an issue with shebang such as: #! /** doc */ [attr] Here this should be treated as a shebang (because it is a doc block comment). The solution is to do the appropriate negative lookahead to exclude OUTER_BLOCK_DOC and INNER_BLOCK_DOC. --- src/comments.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/comments.md b/src/comments.md index b5ff203e15..64b90d8e36 100644 --- a/src/comments.md +++ b/src/comments.md @@ -17,7 +17,7 @@ LINE_COMMENT -> | `//` _immediately followed by LF_ BLOCK_COMMENT -> - `/*` ^ + `/*` !(`!` | `*` ![`*` `/`]) ^ ( BLOCK_COMMENT_OR_DOC | (!`*/` CHAR) )* `*/`