diff --git a/src/cargo/ops/cargo_compile/mod.rs b/src/cargo/ops/cargo_compile/mod.rs index 622255f893c..3ba119841a1 100644 --- a/src/cargo/ops/cargo_compile/mod.rs +++ b/src/cargo/ops/cargo_compile/mod.rs @@ -370,7 +370,7 @@ pub fn create_bcx<'a, 'cfg>( let should_scrape = build_config.mode.is_doc() && config.cli_unstable().rustdoc_scrape_examples; let mut scrape_units = if should_scrape { let scrape_filter = filter.refine_for_docscrape(&to_builds, has_dev_units); - let all_units = generate_targets( + let mut all_units = generate_targets( ws, &to_builds, &scrape_filter, @@ -394,16 +394,17 @@ pub fn create_bcx<'a, 'cfg>( } } - let valid_units = all_units - .into_iter() - .filter(|unit| { - !matches!( - unit.target.doc_scrape_examples(), - RustdocScrapeExamples::Disabled - ) - }) - .collect::>(); - valid_units + // 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`]). + all_units.retain(|unit| { + let not_marked_unscrapable = !matches!( + unit.target.doc_scrape_examples(), + RustdocScrapeExamples::Disabled + ); + not_marked_unscrapable && ws.unit_needs_doc_scrape(unit) + }); + + all_units } else { Vec::new() }; diff --git a/tests/testsuite/docscrape.rs b/tests/testsuite/docscrape.rs index f205e8b61e6..6e09ac57f68 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()