diff --git a/src/cargo/ops/cargo_compile/mod.rs b/src/cargo/ops/cargo_compile/mod.rs index 622255f893c2..da3213e5d08a 100644 --- a/src/cargo/ops/cargo_compile/mod.rs +++ b/src/cargo/ops/cargo_compile/mod.rs @@ -394,13 +394,16 @@ pub fn create_bcx<'a, 'cfg>( } } + // We further eliminate units for scraping if they are explicitly marked to not be scraped, + // or if they aren't eligible for scraping (see [`Workspace::unit_needs_doc_scrape`]). let valid_units = all_units .into_iter() .filter(|unit| { - !matches!( - unit.target.doc_scrape_examples(), - RustdocScrapeExamples::Disabled - ) + ws.unit_needs_doc_scrape(unit) + && !matches!( + unit.target.doc_scrape_examples(), + RustdocScrapeExamples::Disabled + ) }) .collect::>(); valid_units diff --git a/tests/testsuite/docscrape.rs b/tests/testsuite/docscrape.rs index f205e8b61e62..6e09ac57f68b 100644 --- a/tests/testsuite/docscrape.rs +++ b/tests/testsuite/docscrape.rs @@ -281,6 +281,36 @@ fn issue_10545() { .run(); } +#[cargo_test(nightly, reason = "rustdoc scrape examples flags are unstable")] +fn no_scrape_proc_macros_issue_10571() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [lib] + proc-macro = true + "#, + ) + .file("src/lib.rs", "") + .build(); + + // proc-macro library should not be scraped + p.cargo("doc -Zunstable-options -Zrustdoc-scrape-examples") + .masquerade_as_nightly_cargo(&["rustdoc-scrape-examples"]) + .with_stderr( + "\ +[DOCUMENTING] foo v0.0.1 ([CWD]) +[FINISHED] [..] +", + ) + .run(); +} + #[cargo_test(nightly, reason = "rustdoc scrape examples flags are unstable")] fn cache() { let p = project()