Fix nested block comment grammar - #2348
Merged
Merged
Conversation
These were identified by matheww in rust-lang#2325 (comment) and we should have captured them when they were fixed.
When the grammar check fails, it prints the input on the screen. However, when there are embedded CRs, it disrupts the output. This replaces it with the Unicode character for CR Symbol.
These are some problems identified in rust-lang#2333.
This adds a BLOCK_CHAR rule so that both block comments and doc-block comments match each other. This is just done for aesthetics.
This reverts rust-lang@5b328bc which is no longer needed due to rust-lang#2331 changing shebang to use its own dedicated comment rule.
This fixes some issues with nested block comments when they contain carriage returns. The old logic was that a block comment could contain nested block comments of the form of either regular block comments or doc-block comments. This wasn't correct, though, because when inter-mixing regular block comments and doc-block comments, the rules are different with respect to things like carriage returns. However, in reality, when rustc encounters a regular block comment, it just eats everything that looks block-like without any validation. And conversely, for a doc-block comment, it requires that everything inside does not contain a carriage return, even if it is a nested regular block comment. The logic for how nested comments are handled is at https://github.com/rust-lang/rust/blob/a4330234a776684c36428d001721d0320d24dd77/compiler/rustc_lexer/src/lib.rs#L783-L815.
This includes the tests from the `cases` module. Eventually this should be changed in some way. Either these tests should be moved to rust-lang/rust, or there should be separate files that contain the tests. For now it doesn't hurt to run some of these that don't show up in either the permutation or the rust-lang/rust tests.
In the grammar rules, we put spaces between parentheses and what comes inside; let's do that here.
Before the fix in this branch, our grammar disagreed with rustc on comments nested three layers deep. Let's add tests for that and for an inner block doc variant of the CR-starting case.
The only way to match the `NESTED_BLOCK_DOC_COMMENT` rule is for the string to start with `/`, but we've already ruled that out with a negative lookahead, making this alternative dead. Let's remove it.
traviscross
force-pushed
the
fix-more-comments
branch
from
September 2, 2026 04:23
8fbbe9b to
c49c560
Compare
Contributor
|
Thanks @ehuss. |
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Sep 8, 2026
Update books ## rust-lang/book 1 commits in 917544888a55e4da7109bdba8c88c893c0da70f4..1500248d8f230566e4ec9f27fcbb8fe9e2898ab1 2026-09-02 16:04:34 UTC to 2026-09-02 16:04:34 UTC - Update to Rust 1.98 (rust-lang/book#4823) ## rust-lang/edition-guide 1 commits in f5abcf137698e5ad6ebed359d69654ff705346af..ab8544aeed7b792984366aa122ac19bd47ad9a2f 2026-08-25 19:50:54 UTC to 2026-08-25 19:50:54 UTC - Update never-type-fallback for never type stabilization (rust-lang/edition-guide#384) ## rust-lang/reference 12 commits in 3b38834b39f732c64686f7c64aa29dcf3cd83ba5..e24eecf97b0c9a6dbac67191098204dc8a190aaa 2026-09-02 04:25:27 UTC to 2026-08-25 07:52:18 UTC - Fix nested block comment grammar (rust-lang/reference#2348) - dangling pointers: turn some consequences of the definition into notes (rust-lang/reference#2336) - Fix the nightly grammar validation job (rust-lang/reference#2347) - Order grammar summary deterministically (rust-lang/reference#2346) - Remove leftover `types/textual.md` file (rust-lang/reference#2345) - Fix non-leaf rules with bodies (rust-lang/reference#2344) - Fix rule IDs not following the header hierarchy (rust-lang/reference#2343) - Fix heading level of the `verbatim` modifier section (rust-lang/reference#2342) - Fix `...diagnostics.deprecated...` rule ID (rust-lang/reference#2341) - Update for stabilization of the never type (rust-lang/reference#2283) - Add missing punctuation (rust-lang/reference#2339) - Fix field-less `repr(C)` enum docs (rust-lang/reference#2018)
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Sep 8, 2026
Update books ## rust-lang/book 1 commits in 917544888a55e4da7109bdba8c88c893c0da70f4..1500248d8f230566e4ec9f27fcbb8fe9e2898ab1 2026-09-02 16:04:34 UTC to 2026-09-02 16:04:34 UTC - Update to Rust 1.98 (rust-lang/book#4823) ## rust-lang/edition-guide 1 commits in f5abcf137698e5ad6ebed359d69654ff705346af..ab8544aeed7b792984366aa122ac19bd47ad9a2f 2026-08-25 19:50:54 UTC to 2026-08-25 19:50:54 UTC - Update never-type-fallback for never type stabilization (rust-lang/edition-guide#384) ## rust-lang/reference 12 commits in 3b38834b39f732c64686f7c64aa29dcf3cd83ba5..e24eecf97b0c9a6dbac67191098204dc8a190aaa 2026-09-02 04:25:27 UTC to 2026-08-25 07:52:18 UTC - Fix nested block comment grammar (rust-lang/reference#2348) - dangling pointers: turn some consequences of the definition into notes (rust-lang/reference#2336) - Fix the nightly grammar validation job (rust-lang/reference#2347) - Order grammar summary deterministically (rust-lang/reference#2346) - Remove leftover `types/textual.md` file (rust-lang/reference#2345) - Fix non-leaf rules with bodies (rust-lang/reference#2344) - Fix rule IDs not following the header hierarchy (rust-lang/reference#2343) - Fix heading level of the `verbatim` modifier section (rust-lang/reference#2342) - Fix `...diagnostics.deprecated...` rule ID (rust-lang/reference#2341) - Update for stabilization of the never type (rust-lang/reference#2283) - Add missing punctuation (rust-lang/reference#2339) - Fix field-less `repr(C)` enum docs (rust-lang/reference#2018)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes some issues with nested block comments, particularly with the way it handled CRs.
Fixes #2333