14

This code:

#[allow(dead_code)]
macro_rules! test {
    ($x:expr) => {{}}
}

fn main() {

    println!("Results:")

}

produces the following warning about unused macro definition:

warning: unused macro definition
  --> /home/xxx/.emacs.d/rust-playground/at-2017-08-02-031315/snippet.rs:10:1
   |
10 | / macro_rules! test {
11 | |     ($x:expr) => {{}}
12 | | }
   | |_^
   |
   = note: #[warn(unused_macros)] on by default

Is it possible to suppress it? As you can see #[allow(dead_code) doesn't help in case of macros.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
user1244932
  • 7,352
  • 5
  • 46
  • 103

1 Answers1

15

The compiler warning states:

= note: #[warn(unused_macros)] on by default

Which is very similar to the warning caused by unused functions:

= note: #[warn(dead_code)] on by default

You can disable these warnings in the same way, but you need to use the matching macro attribute:

#[allow(unused_macros)]
macro_rules! test {
    ($x:expr) => {{}}
}
ljedrz
  • 20,316
  • 4
  • 69
  • 97
  • 1
    Notably, this should only disable the warning for this specific macro, right? [For future newbies](https://stackoverflow.com/a/25877389/2550406) – lucidbrot Sep 21 '19 at 12:11