Skip to content

disallowed_macros false negatives #11431

Open
@ojeda

Description

@ojeda

Summary

disallowed_macros has several false negatives. See reproducer.

Lint Name

disallowed_macros

Reproducer

With clippy.toml:

disallowed-macros = [ "x::m" ]

And a command line like:

clippy-driver --edition=2021 -Dclippy::disallowed_macros x.rs

This works (similar to an existing test in Clippy):

macro_rules! m (
    ($t:tt) => (1)
);

fn main() {
    let _ = m!(42);
}

However, this does not:

macro_rules! m (
    ($t:tt) => ($t)
);

fn main() {
    let _ = m!(42);
}

Nor:

macro_rules! m (
    ($t:tt) => ($t + $t)
);

fn main() {
    let _ = m!(42);
}

In addition, empty expansions also do not work -- this may be due to the lint not having a pre-expansion part, but still, it would be nice to handle:

macro_rules! m (
    ($t:tt) => ()
);

fn main() {
    m!(42);
}

Version

rustc 1.72.0 (5680fa18f 2023-08-23)
rustc 1.74.0-nightly (84a9f4c6e 2023-08-29)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions