Skip to content

Allow using reverse-dependencies for -Zrustdoc-scrape-examples, not just examples #10041

Closed
@jyn514

Description

@jyn514

Problem

Many repositories don't have examples written, or the examples are not very long and don't show what the call looks like in context.

Proposed Solution

However, almost any library will have people actually using it. What cargo could do is instead of running rustdoc like this:

rustc --emit=metadata --name=foo crate_a/src/lib.rs
rustc --emit=metadata --name=foo crate_b/src/lib.rs
rustdoc --scrape-examples-target-crate=crate_a --scrape-examples-target-crate=crate_b examples/foo.rs
rustdoc --with-examples=foo.examples crate_a/src/lib.rs

Scrape the examples from the other crates in the workspace as well:

rustc --emit=metadata --name=foo crate_a/src/lib.rs
rustc --emit=metadata --name=foo crate_b/src/lib.rs
rustdoc --scrape-examples-target-crate=crate_a crate_b/src/lib.rs
rustdoc --with-examples=crate_ b.examples crate_a/src/lib.rs

This can be extended to all the dependencies in the whole tree if desired. This does have the drawback that it will take about twice as long to run rustdoc, but since it's opt-in I think the tradeoff is worth it.

Notes

Here's a proof of concept which runs those commands by hand on cargo-deadlinks:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Z-scrape-examplesNightly: rustdoc scrape examples

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions