Skip to content

meta_variable_misuse trips on ${count($foo)} outside of a repetition #109245

Open
@PatchMixolydic

Description

@PatchMixolydic

Code

(playground, updated 2024-01-25 to account for a change to the syntax of macro metavariable expressions)

#![feature(macro_metavar_expr)]
#![warn(meta_variable_misuse)]

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

fn main() {
    assert_eq!(foo!(a, b, c), 3);
}

Current output

warning: variable 'id' is still repeating at this depth
 --> src/main.rs:6:10
  |
5 |     ($($id:ident),* $(,)?) => {
  |                   - expected repetition
6 |         ${count($id)}
  |          ^^^^^^^^^^^^
  |
note: the lint level is defined here
 --> src/main.rs:2:9
  |
2 | #![warn(meta_variable_misuse)]
  |         ^^^^^^^^^^^^^^^^^^^^

Desired output

No diagnostics should be emitted.

Rationale and extra context

This code builds and runs just fine; ${count($foo)} doesn't have to be in a repetition of $foo.

Anything else?

@rustbot modify labels +A-macros +D-papercut +F-macro-metavar-expr

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)D-papercutDiagnostics: An error or lint that needs small tweaks.F-macro_metavar_expr`#![feature(macro_metavar_expr)]`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