-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tokens in an attribute macro receive wrong spacing #50700
Comments
So it looks like, as usual, there's a couple of bugs here. Pretty-printed macros don't persist delimitersWhen we print item-like macros we don't preserve the delimiter. This means that the pretty-printed version of That in turn causes this check to fail. which means in the second case here, Parsing stringified tokens gives wrong joint-nessJoint-ness of a TokenTree when parsing is determined here and here. In both locations it's I'll look into fixing both of these soon. The first one is likely not too hard, but the latter one I'll have to do some more investigation for. |
This commit fixes `StringReader`'s parsing of tokens which have been stringified through procedural macros. Whether or not a token tree is joint is defined by span information, but when working with procedural macros these spans are often dummy and/or overridden which means that they end up considering all operators joint if they can! The fix here is to track the raw source span as opposed to the overridden span. With this information we can more accurately classify `Punct` structs as either joint or not. Closes rust-lang#50700
rustc: Fix joint-ness of stringified token-streams This commit fixes `StringReader`'s parsing of tokens which have been stringified through procedural macros. Whether or not a token tree is joint is defined by span information, but when working with procedural macros these spans are often dummy and/or overridden which means that they end up considering all operators joint if they can! The fix here is to track the raw source span as opposed to the overridden span. With this information we can more accurately classify `Punct` structs as either joint or not. Closes #50700
Originally reported by @CodeSandwich as dtolnay/syn#425.
We are seeing a functionlike procedural macro invocation
m![< -]
receive the expected spacing (Alone for both tokens) but preprocessing the same input with an attribute macro#[attribute] m![< -]
receives incorrect spacing -- Joint for the<
token even though it is followed by whitespace. Strangely using parentheses appears to fix the spacing so that#[attribute] m!(< -)
correctly has Alone for both tokens.Repro script
Output
@alexcrichton
The text was updated successfully, but these errors were encountered: