Skip to content

Duplicate metavariables allowed in unused macro definitions #4409

@powerboat9

Description

@powerboat9

Summary

Duplicate metavariables are allowed in macro definitions, as long as those macro definitions are unused. Also, we don't warn when a macro definition is unused. See #4405

Reproducer

I tried this code:

macro_rules! foo {
    ($a:ident, $a:ident) => {()}
}

pub fn foo() {
    //foo!(a, b)
}

Does the code make use of any (1.49) nightly feature ?

  • Nightly

Godbolt link

https://godbolt.org/z/5G3ad4bTo

Actual behavior

No error

Expected behavior

error: duplicate matcher binding
 --> <source>:2:16
  |
2 |     ($a:ident, $a:ident) => {()}
  |      --------  ^^^^^^^^ duplicate binding
  |      |
  |      previous binding

warning: unused macro definition
 --> <source>:1:1
  |
1 | / macro_rules! foo {
2 | |     ($a:ident, $a:ident) => {()}
3 | | }
  | |_^
  |
  = note: `#[warn(unused_macros)]` on by default

GCC Version

d47331f

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions