Rust-GCC / Rust-GCC/gccrs

Duplicate metavariables allowed in unused macro definitions

Open
#4,409 1 comment 0 reactions 1 assignee View on GitHub

@hriztam is already working on this.

Since Feb 21, 2026.

Dominant language
C++
Stars
2.9k
Forks
231
Avg merge
19h 55m
Merged PRs (30d)
67

Description

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

d47331f13c3f16262ffa4fbe6f919b83f1056d7f

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.