Tokio + RUSTFLAGS="--cfg docsrs" = Trouble

I'm adding "This is supported on crate features whatever and this_too only." to some documentation. I'm following @alice's advice (thank you @alice!). Cargo.toml has been updated. I'm working in Windows so setting the environment variable is...

set RUSTFLAGS=--cfg docsrs

Building...

cargo +nightly doc --all-features

Results in Tokio related errors...

    Checking tokio v1.38.0
error[E0433]: failed to resolve: unresolved import
   --> C:\Users\bcook\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.38.0\src\fs\file.rs:913:16
    |
913 |     use crate::os::windows::io::{AsRawHandle, FromRawHandle, RawHandle, AsHandle, BorrowedHandle};
    |                ^^
    |                |
    |                unresolved import
    |                help: a similar path exists: `std::os`
    |
note: found an item that was configured out
   --> C:\Users\bcook\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.38.0\src\lib.rs:634:27
    |
634 | pub(crate) use self::doc::os;
    |                           ^^
    = note: the item is gated behind the `net` feature
note: found an item that was configured out
   --> C:\Users\bcook\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.38.0\src\lib.rs:638:21
    |
638 | pub(crate) use std::os;
    |                     ^^

For more information about this error, try `rustc --explain E0433`.
error: could not compile `tokio` (lib) due to 1 previous error

Is that expected? Do I need to use something other docsrs? Is that an issue with Tokio that should be reported?

So docsrs is special and probably what I need. Using docs_rs instead produces this...

warning: unexpected `cfg` condition name: `docs_rs`
  --> phazer\src\lib.rs:99:13
   |
99 | #![cfg_attr(docs_rs, feature(doc_cfg))]
   |             ^^^^^^^ help: there is a config with a similar name: `docsrs`
   |
   = help: consider using a Cargo feature instead
   = help: or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:
            [lints.rust]
            unexpected_cfgs = { level = "warn", check-cfg = ['cfg(docs_rs)'] }
   = help: or consider adding `println!("cargo::rustc-check-cfg=cfg(docs_rs)");` to the top of the `build.rs`
   = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
   = note: `#[warn(unexpected_cfgs)]` on by default

There's an issue for that.

And documentation.

Please file a bug with Tokio.

1 Like

Done.

And, apparently, there is a 64k limit on the body size of issues. That was annoying.

1 Like