Skip to content

${count(t,)} is interpreted as ${count(t, 0)} #111904

Closed
@lowr

Description

@lowr

I tried this code:

#![feature(macro_metavar_expr)]

macro_rules! foo {
    ( $( $($t:ident),* );* ) => { ${count(t,)} }
}

fn test() {
    foo!(a, a; b, b);
}

I expected to see this happen:

Either:

  • The macro definition is rejected, leading to a compile error.
  • ${count(t,)} is interpreted as ${count(t)}, the macro call is expanded to 4.

Instead, this happened:
Compiled successfully, ${count(t,)} is interpreted as ${count(t, 0)}, the macro call is expanded to 2.

This form of ${count()} metavar expression is not specified in RFC 3086, so this is more of an ask for clarification than a bug report.

Meta

rustc --version --verbose:

1.71.0-nightly (2023-05-23 5ea3f0ae08c07472239a)

cc #83527
@rustbot label requires-nightly F-macro-metavar-expr

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-macro_metavar_expr`#![feature(macro_metavar_expr)]`requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions