有没有办法在测试期间从外部包装箱导入宏,没有任何警告?

Dav*_*lis 6 rust

我有类似的东西:

#[macro_use] extern crate log;

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

#[cfg(test)]
mod tests {
    #[test]
    fn test_a() { debug!("Message."); }
}
Run Code Online (Sandbox Code Playgroud)

这会编译一个警告:

warning: unused `#[macro_use]` import
Run Code Online (Sandbox Code Playgroud)

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

extern crate log;
Run Code Online (Sandbox Code Playgroud)

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

error: cannot find macro `debug!` in this scope
Run Code Online (Sandbox Code Playgroud)

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

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."); }
}
Run Code Online (Sandbox Code Playgroud)

然后我得到编译器错误:

error[E0468]: an `extern crate` loading macros must be at the crate root
Run Code Online (Sandbox Code Playgroud)

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

归档时间:

查看次数:

465 次

最近记录:

7 年,5 月 前