Skip to content
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

Macro item fragment lumps item component tokens together so they can't be parsed separately #38442

Closed
abonander opened this issue Dec 18, 2016 · 1 comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot.

Comments

@abonander
Copy link
Contributor

abonander commented Dec 18, 2016

Simplest reproduction (playpen):

macro_rules! takes_item {
    ($item:item) => (takes_fn!{ $item });
}

macro_rules! takes_fn {
    (fn $fnname:ident() {}) => ();
}

takes_item! {
    fn foo() {}
}

Yields the following, very confusing error:

error: no rules expected the token `fn foo() { }`
 --> <anon>:2:33
  |
2 |     ($item:item) => (takes_fn!{ $item });
  |          

This makes it very difficult to use the item fragment type to accept valid function items and then parse them out in nested macros.

For a more detailed use-case, see this file.

I'm trying to use nested macros to make parsing optional generics and where clauses a lot less clunky, but since the item fragment lumps the tokens together, the method_proto! macro can't parse the individual tokens anymore.

@abonander abonander changed the title Macro item fragment lumps item tokens together so they can't be parsed separately Macro item fragment lumps item component tokens together so they can't be parsed separately Dec 18, 2016
@jseyfried jseyfried added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. labels Dec 19, 2016
@jseyfried jseyfried self-assigned this Dec 19, 2016
@jseyfried
Copy link
Contributor

Closing in favor of #26361.

@jseyfried jseyfried removed their assignment Jan 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot.
Projects
None yet
Development

No branches or pull requests

2 participants