Skip to content

Unused lint warnings for macros #34938

Description

@est31

If you declare a variable, and not use it, you get an unused code warning.

The same should be true for macros (that don't have the #[macro_export] attribute). So if you have a private macro like:

fn main() {
    macro_rules! do_something {
        ($x:expr) => {$x + 20}
    }
}

It should give you a warning. Same goes if you use a macro, but not all of its match arms:

fn main() {
    macro_rules! do_something {
        ($x:expr) => {$x + 20};
        ($i:ident, $x:expr) => {$i = $x + 20};
    }
    println!("done: {}", do_something!(2));
}

Note that this is no dupe or not even against #24580. That issue is about unused code inside macro expansions, but my issue is about macro use.

By description, this falls under the definition of the dead-code lint.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions