Skip to content

${count()} disregards depth parameter when captured repetition is empty #111905

Open
@lowr

Description

@lowr

I tried this code:

#![feature(macro_metavar_expr)]

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

macro_rules! bar {
    ( $( { $( [ $( ( $( $t:ident )* ) )* ] )* } )* ) => { ${count(t, 4294967296)} }
}

fn test() {
    foo!();
    bar!( { [] [] } );
}

I expected to see this happen: Fails to expand both macro calls, because the depth parameter (4294967296) is out of bounds for $t fragment in both macros.

Instead, this happened: Compiled successfully, both macro calls expand to 0.

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