如何禁用未使用的宏警告?

时间:2017-08-02 00:16:54

标签: macros rust

此代码:

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

fn main() {

    println!("Results:")

}

对未使用的宏定义产生以下警告:

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

有可能抑制它吗?正如您所看到的,#[allow(dead_code)在宏的情况下没有帮助。

1 个答案:

答案 0 :(得分:5)

编译器警告说明:

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

这与未使用的功能引起的警告非常相似:

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

您可以以相同的方式禁用这些警告,但需要使用匹配的宏属性:

#[allow(unused_macros)]
macro_rules! test {
    ($x:expr) => {{}}
}
相关问题