rust-lang / rust-lang/rust

rustdoc does not pickup dev dependencies when the dev-dep adds a feature to an existing dependency

Open
#151,217 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-rustdoc-scrape-examples C-bug T-cargo T-rustdoc
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

When scraping examples, there is a bug (?) where a dev-dependency that only adds new features does not get used causing example scraping to fail.

This happened in real life here: https://docs.rs/crate/metrique-aggregation/latest/builds/2825680

Code

I made a reproduction package here: https://github.com/rcoh/rustdoc-scrape-examples-reproducer

[package]
name = "example-scrape-bug"
version = "0.1.0"
edition = "2024"

[dependencies]
serde = { version = "1" }

[dev-dependencies]
serde = { version = "1", features = ["rc", "derive"] }
serde_json = "1"

[[example]]
name = "demo"
doc-scrape-examples = true

[package.metadata.docs.rs]
all-features = true
targets = ["x86_64-unknown-linux-gnu"]
rustdoc-args = ["--cfg", "docsrs"]
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
// examples/demo.rs
use example_scrape_bug::MyStruct;
use serde::Serialize;
use std::rc::Rc;

fn main() {
    let data = MyStruct { value: 42 };
    println!("{:?}", serde_json::to_string(&data).unwrap());

    // This uses the "rc" feature from dev-dependencies
    let _rc_data: Rc<i32> = Rc::new(42);
}

Reproduction Steps

  1. Run cargo package, then execute a docs.rs simulated build (e.g. with cargo-docs-rs) on the resulting target:
cargo package && (cd target/package/example-scrape-bug-0.1.0 && cargo +nightly docs-rs)
  1. The build will fail because the serialize feature didn't get enabled:

Expected Outcome

Docs build succeeds. NOTE: the docs build does not fail if you run it directly from the package, only if you run it from the packaged crate.

Actual Output

warning: manifest has no description, license, license-file, documentation, homepage or repository
  |
  = note: see https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info
   Packaging example-scrape-bug v0.1.0 (/Users/rcoh/code/example-scrape-bug)
    Updating crates.io index
    Packaged 8 files, 5.3KiB (2.3KiB compressed)
   Verifying example-scrape-bug v0.1.0 (/Users/rcoh/code/example-scrape-bug)
   Compiling example-scrape-bug v0.1.0 (/Users/rcoh/code/example-scrape-bug/target/package/example-scrape-bug-0.1.0)
error: cannot find derive macro `Serialize` in this scope
 --> src/lib.rs:3:10
  |
3 | #[derive(Serialize)]
  |          ^^^^^^^^^
  |
note: `Serialize` is imported here, but it is only a trait, without a derive macro
 --> src/lib.rs:1:5
  |
1 | use serde::Serialize;
  |     ^^^^^^^^^^^^^^^^

error: could not compile `example-scrape-bug` (lib) due to 1 previous error
error: failed to verify package tarball

Version

rustdoc 1.94.0-nightly (22c74ba91 2026-01-15)

Additional Details

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction package's Cargo.toml and examples/demo.rs, then run cargo package followed by cargo +nightly docs-rs in the packaged directory. Trace how rustdoc scrape examples handles the dev-dependency feature during the packaged build. Done means the packaged docs-rs simulation succeeds with serde's derive feature enabled, while the direct package build remains successful.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system, documentation
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.