I can't build local rustdoc due to a dependency

First of all, this is my first question here, so I might mistake something.
Please tell me if you find I have broken some rule or whatever.

I was building a doc for some crate, and I got errors like

error[E0554]: `#![feature]` may not be used on the stable release channel
 --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/bytes-1.4.0/src/lib.rs:7:21
  |
7 | #![cfg_attr(docsrs, feature(doc_cfg))]
  |                     ^^^^^^^^^^^^^^^^

error: Compilation failed, aborting rustdoc

For more information about this error, try `rustc --explain E0554`.
error: could not document `bytes`

So I used the nightly version of rustdoc, and then I got another error:

error[E0658]: `#[doc(cfg)]` is experimental
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/rxml-0.8.2/src/lib.rs:196:20
    |
196 | #[cfg_attr(docsrs, doc(cfg(feature = "async")))]
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: see issue #43781 <https://github.com/rust-lang/rust/issues/43781> for more information
    = help: add `#![feature(doc_cfg)]` to the crate attributes to enable

If I understand correctly, rxml is an external crate and I can't insert #![feature()] attribute in it.
To test my assumption, I created a fresh new library crate

cargo new --lib doc-rxml

Then I added only the rxml dependency with version 0.9.1

[dependencies]
rxml = "0.9.1"

Then I attempted to build a document with the nightly compiler, which gave me the exact same error.

error[E0658]: `#[doc(cfg)]` is experimental
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/rxml-0.9.1/src/lib.rs:196:20
    |
196 | #[cfg_attr(docsrs, doc(cfg(feature = "async")))]
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: see issue #43781 <https://github.com/rust-lang/rust/issues/43781> for more information
    = help: add `#![feature(doc_cfg)]` to the crate attributes to enable

For more information about this error, try `rustc --explain E0658`.
error: could not document `rxml`

So my question is, how can I actually build a document of dependency crate, which doesn't have #![feature(doc_cfg)] itself?

Thanks in advance and sorry for my poor English.

You should try to build your doc using the nightly toolchain. rxml seems to assume only docs.rs will build their doc, and docs.rs always use the nightly toolchain to build all docs.

cargo +nightly doc --open

Thanks for your response!

And yes, that was the exact command that I ran when the previous try.
Sorry for not mentioning every command that I tried earlier.

Can you reproduce this issue?
Maybe the problem is related to my own setup. (maybe rustup?)

rm -rf doc-rxml
cargo new --lib doc-rxml
cd doc-rxml
cargo add rxml@0.9.1
rustup install nightly # just make sure the nightly toolchain installed
RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc

I know that docs.rs uses nightly by default, but how can I produce the same output as docs.rs in locally, even though I run it with the nightly toolchain (as long as I am doing it correctly)?
Am I missing something, or is there any document that I should check out?

I really appreciate your help in advance!

This error happen because the unstable feature doc_cfg is not enabled in rxml.
Also if you look at the Cargo.toml file, they don't use the rust doc flags

You should probably open an issue on GitHub.

2 Likes

I see!

I just found that I can use cargo rustdoc to enable all unstable features by default without editing dependencies (which seems to run even on stable)

cargo rustdoc
   Compiling autocfg v1.1.0
   Compiling memchr v2.5.0
   Compiling version_check v0.9.4
    Checking bytes v1.4.0
    Checking pin-project-lite v0.2.9
    Checking static_assertions v1.1.0
    Checking rxml_validation v0.9.1
   Compiling tokio v1.26.0
   Compiling smartstring v1.0.1
    Checking rxml v0.9.1
 Documenting doc-rxml v0.1.0 (~/tmp/doc-rxml)
    Finished dev [unoptimized + debuginfo] target(s) in 3.46s

The problem was testing and viewing docs of my crate locally only, so it seems the 'original question' is now solved.
But I will further investigate rxml and open an issue about this If applicable, as you suggested.

Anyway, I appreciate all of you.
Thank you so much for your time!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.