internal: Represent doc comments using their own node and not as COMMENT trivia - #23218
Open
ChayimFriedman2 wants to merge 1 commit into
Open
internal: Represent doc comments using their own node and not as COMMENT trivia#23218ChayimFriedman2 wants to merge 1 commit into
ChayimFriedman2 wants to merge 1 commit into
Conversation
bit-aloo
self-requested a review
August 23, 2026 11:13
bit-aloo
reviewed
Aug 24, 2026
Comment on lines
-387
to
-394
| do_check( | ||
| r" | ||
| /// foo $0$0omment | ||
| mod { } | ||
| ", | ||
| "c", | ||
| 14, | ||
| ); |
Contributor
Author
There was a problem hiding this comment.
Ah I forgot to comment about this. Since incremental parsing is to-be-removed anyway when we rewrite rowan (and we currently only use it for completion), I didn't bother to investigate why this test fails.
Comment on lines
+678
to
686
| /// Hello$0 | ||
| /// world! | ||
| fn foo() { | ||
| /// Hello$0 | ||
| /// world! | ||
| } | ||
| ", | ||
| r" | ||
| /// Hello$0 world! | ||
| fn foo() { | ||
| /// Hello$0 world! | ||
| } |
Contributor
Author
There was a problem hiding this comment.
An outer doc comment is invalid inside the body. Now the parser produces an error on this, which made this test fail.
For two reasons: - This simplifies my work to fix rust-lang#23088; to fix that issue, macros must have to be able to return doc comments (and not just desugared doc comments), and code in `syntax-bridge` doesn't expect macros to return trivia. Making doc comments non-trivia solves that. - It should simplify the work to attach trivia to tokens; doc comments have no obvious place to attach (for example, when between two attributes we must attach them to either the preceding `]` or the following `#`, both will complicate code handling them). Furthermore, arguably doc comments are really not a trivia: it's an error to put them in an unexpected place, and reason 2 above reveals that they're more like a kind of an attribute than a comment. This touches a lot of places (especially assists etc.) subtly; I fixed what I found and the tests helped reveal more, but it's certainly possible some places are still not handling them correctly now.
ChayimFriedman2
force-pushed
the
doc-comment-no-trivia
branch
from
August 24, 2026 17:03
f73be23 to
10b61ad
Compare
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.
For two reasons:
unexpected token in inputmacro with doc comment #23088; to fix that issue, macros must have to be able to return doc comments (and not just desugared doc comments), and code insyntax-bridgedoesn't expect macros to return trivia. Making doc comments non-trivia solves that.]or the following#, both will complicate code handling them).Furthermore, arguably doc comments are really not a trivia: it's an error to put them in an unexpected place, and reason 2 above reveals that they're more like a kind of an attribute than a comment.
This touches a lot of places (especially assists etc.) subtly; I fixed what I found and the tests helped reveal more, but it's certainly possible some places are still not handling them correctly now.
CC @bit-aloo.