-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Support arbitrary token streams in list attributes. #45244
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
Conversation
With this feature, given an attribute #[foo(..)], the `..` can be an arbitrary token stream.
(rust_highfive has picked a reviewer for you, use r? to override) |
r? @jseyfried |
Added a test which doesn't pass, still figuring out what's wrong here. |
@withoutboats how goes -- any progress here? |
@withoutboats would you like someone to take a closer look? (I've not looked closely at this PR yet) |
@nikomatsakis Would be good! I thought adding a fallback to |
cc @petrochenkov -- any thoughts on this? (I'll try to dig into it later on, ran out of time today.) |
I didn't follow development of token streams and procedural macros 2.0, so I'm not aware of any possible subtleties this change can result in, but in general, if custom attributes are procedural macros, then it seems they should indeed accept arbitrary token trees. Possible issues:
Well, at least it's feature gated, so it's won't be a big problem if something goes unexpectedly wrong. |
@petrochenkov The way I intended the code to work (though it seems like it isn't) is to fallback to TokenStream if it can't parse the attribute as a NestedMetaItem. That way anything that conforms to our existing built in attributes will continue to be parsed as a NestedMetaItem, avoiding rewriting all the code that walks that variant to process built in attributes. |
Also I'd like to stabilize this feature this cycle so that the custom attributes registered by derive can use this syntax. |
Sorry for delay getting to this; I'll investigate test failure this weekend. |
Triage ping -- looks like this is in @nikomatsakis and @jseyfried 's courts to investigate? |
OK, @withoutboats, I'm building a copy of this branch locally and will try to investigate. |
@withoutboats I took a peek. I believe the problem is that the parser "eagerly commits" to a parse error sometimes. Fixing this will require some mild refactoring. Let me show you what I mean. As part of parsing a metadata item, we invoke rust/src/libsyntax/parse/parser.rs Lines 980 to 990 in cbf5d39
rust/src/libsyntax/parse/parser.rs Lines 995 to 1003 in cbf5d39
In fact, it invokes So basically this is the problem. We need to refactor |
Howdy from triage, @withoutboats! It's been over a week since we last heard from you here. Will you have time to work on the test failures soon? |
Thanks for the pr @withoutboats ! Unfortunately, we haven't heard from you in a few weeks, so I'm going to close this to keep things tidy. Please reopen when you have a chance to address the remaining issues! |
With this feature, given an attribute
#[foo(..)]
, the..
can be anarbitrary token stream.