11

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
  • 326,504
  • 69
  • 892
  • 1,159
user1244932
  • 6,781
  • 3
  • 37
  • 88

1 Answers1

13

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
  • 17,806
  • 3
  • 63
  • 86
  • 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