From 37ed14b389e5a5e6280c720f22f0ebd17f555be5 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 24 Feb 2026 18:42:58 -0800 Subject: [PATCH 1/2] Fix grammar for block comments This fixes an issue with the block comment grammar with nested block comments. For example, this would fail to match `/*/* test */*/` because of the following: The open slash of the inner block comment matches `~[`*` `!`]` which then misinterprets the rest of the inner block comment as being normal characters, and prevents the nesting from working correctly. The original intent with this formulation was to prevent it from matching an inner or outer block doc comment. This is no longer needed because we are now defining the order with the COMMENT production, and the doc comments come before block comments. This also changes the order of BLOCK_COMMENT_OR_DOC, but that is not strictly necessary because once inside a block comment, everything is comment text. rustc does not expose nested comments as being distinct. I mainly ordered them to be consistent with COMMENT (and in case I forgot anything). The implementation for this is at [`Cursor::block_comment`](https://github.com/rust-lang/rust/blob/859951e3c7c9d0322c39bad49221937455bdffcd/compiler/rustc_lexer/src/lib.rs#L782-L817). --- src/comments.md | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/comments.md b/src/comments.md index ef283a9ea1..4b0ed24397 100644 --- a/src/comments.md +++ b/src/comments.md @@ -17,13 +17,9 @@ LINE_COMMENT -> | `//` _immediately followed by LF_ BLOCK_COMMENT -> - `/**/` - | `/***/` - | `/*` - ^ - ( ~[`*` `!`] | `**` | BLOCK_COMMENT_OR_DOC ) - ( BLOCK_COMMENT_OR_DOC | ~`*/` )* - `*/` + `/*` + ^ ( BLOCK_COMMENT_OR_DOC | (!`*/` CHAR) )* + `*/` INNER_LINE_DOC -> `//!` ^ LINE_DOC_COMMENT_CONTENT (LF | EOF) @@ -46,9 +42,9 @@ OUTER_BLOCK_DOC -> BLOCK_CHAR -> (!(`*/` | CR) CHAR) BLOCK_COMMENT_OR_DOC -> - BLOCK_COMMENT + INNER_BLOCK_DOC | OUTER_BLOCK_DOC - | INNER_BLOCK_DOC + | BLOCK_COMMENT ``` r[comments.normal] From 9c042300815d0031d84604980b578901f204c269 Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Mon, 2 Mar 2026 01:09:16 +0000 Subject: [PATCH 2/2] Move cut in `BLOCK_COMMENT` for clarity In the grammar rule for `BLOCK_COMMENT`, we indent the rule expression for the content of the block comment. We had put the cut ahead of this rule, but the resulting indentation makes it seem as though the cut is scoped to this subpart when it in fact applies to all remaining parts of the rule. The potential confusion here is particularly subtle because the rule for the content of a block comment is followed by a Kleene star -- if the cut only applied to this subpart, it would be superfluous. Let's move the cut to after the opening `/*` to avoid this. --- src/comments.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/comments.md b/src/comments.md index 4b0ed24397..f39fcd3927 100644 --- a/src/comments.md +++ b/src/comments.md @@ -17,8 +17,8 @@ LINE_COMMENT -> | `//` _immediately followed by LF_ BLOCK_COMMENT -> - `/*` - ^ ( BLOCK_COMMENT_OR_DOC | (!`*/` CHAR) )* + `/*` ^ + ( BLOCK_COMMENT_OR_DOC | (!`*/` CHAR) )* `*/` INNER_LINE_DOC ->