当在Rust中使用no_main外部属性时,cargo doc抱怨unused attribute和那个crate-level attribute should be in the root module。
我每晚使用Cargo 1.42.0。
相关代码:
// main.rs
#![no_main]只有在调用cargo doc时才会发生这种情况;cargo build按预期工作。
我看过https://github.com/rust-lang/rust/issues/62184,但是它没有包含任何答案。我还看到了https://github.com/rust-lang/rust/issues/43144,从那里我跟踪到了https://github.com/rust-lang/rust/pull/64471,但即使合并请求已经合并,问题仍然存在。
如何解决此警告?
发布于 2020-02-10 02:02:38
此警告是由known bug in cargo/rustdoc引起的,但尚未修复。
到目前为止,通过将cfg_attr attribute与rustdoc的cfg(doc)结合使用,可以通过以下方式轻松解决此问题:
// main.rs
#![cfg_attr(not(doc), no_main)]此代码在所有情况下都应用no_main属性,构建文档时除外。
https://stackoverflow.com/questions/60139645
复制相似问题