Skip to content

Remove $:meta matcher in decl macros #49629

Closed

Description

@dtolnay

$:meta is intended for matching the content of attributes, as in the following:

#![feature(decl_macro)]

macro m(
    $(#[$m:meta])*
    struct $n:ident;
) {
    $(#[$m])*
    struct $n(usize);
}

m! {
    #[derive(Debug)]
    struct S;
}

fn main() {
    println!("{:?}", S(1));
}

According to #34981 (comment) we intend to support arbitrary token streams inside of attributes rather than the limited grammar of $:meta. Let's have decl macros drop support for $:meta and encourage #[$($meta:tt)*] instead.

Activity

  1. eddyb commented on Apr 3, 2018

    @eddyb
    Contributor

    The less fragment specifiers the better! We might even want to change the macro_rules meta to ident followed by any number of tt's, just to keep things simple.

  2. dtolnay commented on Apr 3, 2018

    @dtolnay
    MemberAuthor

    Changing macro_rules's meta is tricky because it is currently allowed to be followed by tokens.

    macro_rules! eddyb {
        ($m:meta $n:tt) => {}
    }
    
    eddyb!(a ~);
  3. eddyb commented on Apr 3, 2018

    @eddyb
    Contributor

    So, the only generalization we can make is to have meta allow ident = tt and ident(tt*)?

  4. petrochenkov commented on Apr 3, 2018

    @petrochenkov
    Contributor

    we intend to support arbitrary token streams inside of attributes

    I thought the idea was to support attribute invocations identical to bang macro invocations

    a::b::c!(tt*)
    a::b::c![tt*]
    a::b::c!{tt*}
    
    =>
    
    #[a::b::c(tt*)]
    #[a::b::c[tt*]]
    #[a::b::c{tt*}]

    + two "legacy" forms

    #[a::b::c] // Maybe not so "legacy" with https://internals.rust-lang.org/t/idea-elide-parens-brackets-on-unparametrized-macros/6527
    #[a::b::c = not_sure_what_exactly_but_probably_tt]

    , but not arbitrary "token streams" (aka tt* without delimiters)

    #[a::b::c e f + c ,,, ;_:] // Nope
    

    In this case, I think, we can fit it into existing meta with all its following token rules.

  5. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Apr 5, 2018
  6. sgrif commented on Aug 2, 2018

    @sgrif
    Contributor

    This seems like something that should get done for Rust 2018 -- Should this be nominated for more discussion?

  7. petrochenkov commented on Aug 2, 2018

    @petrochenkov
    Contributor

    #50120 restricted the attribute grammar to delimited token trees, so it's at least technically possible to keep meta as a matcher now.

  8. self-assigned this
    on Aug 14, 2019
  9. petrochenkov commented on Aug 17, 2019

    @petrochenkov
    Contributor

    #63674 supports the modern attribute syntax in meta.

  10. added a commit that references this issue on Aug 17, 2019
  11. added 2 commits that reference this issue on Oct 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-decl-macros-2-0Area: Declarative macros 2.0 (#39412)C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions