2017-08-02 41 views
-1

此代码:如何禁用未使用的宏警告?

#[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)在宏的情况下不起作用。

+3

我不知道生锈,但看起来像'#[allow(unused_macros)]'可能是值得一试。 –

回答

3

的编译器警告美国:

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

这是非常相似,所造成的未使用的功能警告:

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

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

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