2017-08-02 40 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) => {{}} 
}