Skip to content

-Zrustdoc-scrape-examples not working if there is no workspace #13074

Closed
@GuillaumeGomez

Description

@GuillaumeGomez

Problem

In killercup/test-rustdoc-example-scraping-across-workspace-on-docrs#1 and in rust-lang/docs.rs#2305, we were able to find out that if you re-export non-workspace members, examples would not be scraped for them

Steps

$ git clone https://github.com/killercup/test-rustdoc-example-scraping-across-workspace-on-docrs.git
$ cargo +nightly doc -Zunstable-options -Zrustdoc-scrape-examples
$ ... open in browser and see no examples
$ git checkout HEAD~
$ cargo +nightly doc -Zunstable-options -Zrustdoc-scrape-examples
$ ... open in browser and see examples

Possible Solution(s)

When scraping examples from a package, cargo only asks for examples that use APIs from specific crates, presumably for performance reasons

        // Only scrape example for items from crates in the workspace, to reduce generated file size
        for pkg in cx.bcx.ws.members() {
            let names = pkg
                .targets()
                .iter()
                .map(|target| target.crate_name())
                .collect::<HashSet<_>>();
            for name in names {
                rustdoc.arg("--scrape-examples-target-crate").arg(name);
            }
        }

This is filtered to workspace members. Really what is needed is filtering for public dependencies which has recently been revived (rust-lang/rfcs#3516).

If the performance hit is not noticeable enough, we likely can remove this completely.

If the performance his is noticeable enough, the path forward:

  • Long term: switch this to filtering on public normal dependencies (recursively)
  • Short term: decide whether to
    • keep filtering by workspace members
    • take the perf hit and do no filtering
    • filter for all normal dependencies, recursively

Notes

No response

Version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bugS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or reviewZ-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