rust-lang / rust-lang/rust-clippy

Lint suggestion: Mismatched macro repetition operator

Open
#16,138 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

What it does

In a macro_rules! definition, there are three different repetition operators that can be used: *, +, ?. Rust accepts the code even if the repetition operator in the macro matcher is different from the repetition operator in the macro transcriber. This lint would warn against such a mismatch.

Advantage
  • Having mismatched repetition operators can be confusing, since the kind of repetition operator used in the macro transcriber is ignored, and therefore can be misleading.
  • Mismatched repetition operators can be a sign of a bug, where the macro author intended to refer to a different "repetition group".
Drawbacks

No response

Example
macro_rules! my_macro {
    ($($i:ident)?) => {
        $($i)*
    }
}

Could be written as:

macro_rules! my_macro {
    ($($i:ident)?) => {
        $($i)?
    }
}
Comparison with existing lints

No response

Additional Context

No response

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.

Research direction

The issue does not name implementation files or tests. Start by comparing the macro_rules! examples with Rust's repetition documentation and determine how Clippy should detect differing matcher and transcriber operators; done means the mismatch is warned about without warning for matching operators.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.