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

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

Open
lowr opened this issue May 24, 2023 · 1 comment
Open

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

lowr opened this issue May 24, 2023 · 1 comment
Labels
C-bug Category: This is a bug. F-macro_metavar_expr `#![feature(macro_metavar_expr)]` requires-nightly This issue requires a nightly compiler in some way.

Comments

@lowr
Copy link
Contributor

lowr commented May 24, 2023

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

@lowr lowr added the C-bug Category: This is a bug. label May 24, 2023
@rustbot rustbot added F-macro_metavar_expr `#![feature(macro_metavar_expr)]` requires-nightly This issue requires a nightly compiler in some way. labels May 24, 2023
TaKO8Ki added a commit to TaKO8Ki/rust that referenced this issue Jun 27, 2023
[RFC-3086] Consider out-of-bound depths of `count`

Fix rust-lang#111905

In the matching of macro calls and their respective declarations (transcribe), a warning is issued if `count` has a depth greater than the number of nested `NamedMatch`s through be verification of `MatchedSeq` with empty elements.

Doesn't affect `( $( { $( [ $( ( $( $t:ident )* ) )* ] )* } )* ) => { ${count(t, 1)} }` called with `bar!( { [] [] } )` which will still continue to output `2`.
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 30, 2023
[RFC-3086] Consider out-of-bound depths of `count`

Fix rust-lang#111905

In the matching of macro calls and their respective declarations (transcribe), a warning is issued if `count` has a depth greater than the number of nested `NamedMatch`s through be verification of `MatchedSeq` with empty elements.

Doesn't affect `( $( { $( [ $( ( $( $t:ident )* ) )* ] )* } )* ) => { ${count(t, 1)} }` called with `bar!( { [] [] } )` which will still continue to output `2`.
@c410-f3r
Copy link
Contributor

For anyone interested, a fix is available at #111923. The only problem is a i686 diagnostic issue (???????) that I couldn't solve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-macro_metavar_expr `#![feature(macro_metavar_expr)]` requires-nightly This issue requires a nightly compiler in some way.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@c410-f3r @lowr @rustbot and others