【问题标题】:How to disable the unused macros warning?如何禁用未使用的宏警告?
【发布时间】:2017-08-02 00:16:53
【问题描述】:

这段代码:

#[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) 在宏的情况下无济于事。

【问题讨论】:

  • 我不知道 rust,但看起来 #[allow(unused_macros)] 可能值得一试。

标签: macros rust


【解决方案1】:

编译器警告状态:

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

这与未使用函数引起的警告非常相似:

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

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

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

【讨论】:

  • 值得注意的是,这应该只禁用此特定宏的警告,对吧? For future newbies
猜你喜欢
  • 2016-04-30
  • 2022-09-23
  • 1970-01-01
  • 1970-01-01
  • 2023-03-12
  • 2020-06-25
  • 2021-11-07
  • 2014-11-10
  • 1970-01-01
相关资源
最近更新 更多