gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 07:57:34 26 4
gpt4 key购买 nike

这段代码:

#[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) 在宏的情况下没有帮助。

最佳答案

编译器警告状态:

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

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

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

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

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

关于macros - 如何禁用未使用的宏警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45449525/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com