gpt4 book ai didi

rust - 有没有办法只在测试期间从外部 crate 导入宏,而没有任何警告?

转载 作者:行者123 更新时间:2023-11-29 07:47:44 25 4
gpt4 key购买 nike

我有这样的东西:

#[macro_use] extern crate log;

pub fn do_nothing() { let _ = log::Level::Info; }

#[cfg(test)]
mod tests {
#[test]
fn test_a() { debug!("Message."); }
}

编译时出现警告:

warning: unused `#[macro_use]` import

如果我删除宏导入,并将第一行更改为:

extern crate log;

然后我在编译时得到以下错误:

error: cannot find macro `debug!` in this scope

如果我然后尝试只为测试模块导入宏,即:

extern crate log;

pub fn do_nothing() { let _ = log::Level::Info; }

#[cfg(test)]

mod tests {
#[macro_use] extern crate log;
#[test]
fn test_a() { debug!("Message."); }
}

然后我得到编译器错误:

error[E0468]: an `extern crate` loading macros must be at the crate root

是否有一种解决方案可以避免所有警告而不仅仅是抑制它们?

最佳答案

关于rust - 有没有办法只在测试期间从外部 crate 导入宏,而没有任何警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49365334/

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