Add DelimSpan to hold the 3 different spans of a delimiter #366
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 getting the span of an opening punctuation or closing punctuation of a group,
proc_macro
only lets you usespan_open()
andspan_close()
if you still have the originalGroup
that came in through the macro input. If you just have the group'sSpan
, there is no possible way to split that intospan_open
andspan_close
after the fact (even though rustc is capable of doing this operation). You can't even fool it by doinglet mut tmp = Group::new(Delimiter::Parenthesis, TokenStream::new()); tmp.set_span(span); tmp.span_close()
-- this will just give you backspan
instead of the correctspan_close
.Libraries sometimes want to keep track of delimiter spans separately from contents. An example of this is
syn::MacroDelimiter
-- https://docs.rs/syn/1/syn/enum.MacroDelimiter.html. Delimiters of a macro invocation cannot beDelimiter::None
so representing them using the originalGroup
would be too general. Today such libraries are forced to eagerly callspan_open()
andspan_close()
before dropping the original parsedGroup
, and then they need to store 3×proc_macro2::Span
which is an excessive 36 bytes.This PR adds a more compact 3×
Span
data structure which is only 12 bytes, the same size as a singleproc_macro2::Span
.