Silencing the warn-main-not-called warning in doctests
โ Rust ๐ 2026-02-05 ๐ค surdeus ๐๏ธ 6I have the following doc comment for a trait :
/// ```
#[doc = include_str!("../examples/download_track.rs")]
/// # main();
/// ```
pub trait Download: RootEntity {
// not important
}
And example/download_track.rs looks like this :
#[tokio::main]
async fn main() {
// irrelevant test/example code
}
The example code being reasonably long, I'd like to avoid copying it to the doc comment.
Now when I run cargo test, I am warned as follows:
warning: the `main` function of this doctest won't be run as it contains expressions at the top level, meaning that the whole doctest code will be wrapped in a function
As can be seen above, I made sure to run the main() function created by tokio (no need to await it, it's tokio's wrapper and not my async function that I'm calling).
Now how can I silence this warning which has been taken care of?
It seems to be raised here: rust/src/librustdoc/doctest/make.rs at f889772d6500faebcac5bb70fa44b5e6581c38cd ยท rust-lang/rust ยท GitHub
I'm guessing this is not supported yet...
3 posts - 2 participants
๐ท๏ธ Rust_feed