rustc: Implement tokenization of nested items #52618
Merged
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.
Ever plagued by #43081 the compiler can return surprising spans in situations
related to procedural macros. This is exhibited by #47983 where whenever a
procedural macro is invoked in a nested item context it would fail to have
correct span information.
While #43230 provided a "hack" to cache the token stream used for each item in
the compiler it's not a full-blown solution. This commit continues to extend
this "hack" a bit more to work for nested items.
Previously in the parser the
parse_item
method would collect the tokens for anitem into a cache on the item itself. It turned out, however, that nested items
were parsed through the
parse_item_
method, so they didn't receive similartreatment. To remedy this situation the hook for collecting tokens was moved
into
parse_item_
instead ofparse_item
.Afterwards the token collection scheme was updated to support nested collection
of tokens. This is implemented by tracking
TokenStream
tokens instead ofTokenTree
to allow for collecting items into streams at intermediate layersand having them interleaved in the upper layers.
All in all, this...
Closes #47983