Skip to content

New lint: checking for typos in macro_rules #12614

Closed as not planned
Closed as not planned
@sosthene-nitrokey

Description

@sosthene-nitrokey

What it does

This would lint against use of $smth in the expansion part of a macro_rules! if smth is not a capture. While such a pattern could be used in a recursive macro, it is being phased out, so in practice it is likely an typo, especially if the name of smth is close to an actual capture.

See dzamlo/rust-bitfield#40 for the case that prompted this lint suggestion.

Advantage

  • Detect potential bugs in macros.
    Macros are hard to debug and have very little compile-time validity checks. Complex recursive macros are very complex, and can have many rules. Any tool to improve that is good.

Drawbacks

There is a possibility of false positives

Example

macro_rules! testing {
    ($testing:ty)  => {$testin}
}

Will never be usable because testin is not a capture (notice the missing g) is not a capture.

it should instead be written as:

macro_rules! testing {
    ($testing:ty)  => {$testing}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsT-macrosType: Issues with macros and macro expansion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions