diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index 0d07dafa347..023da986b69 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -1515,7 +1515,7 @@ impl<'cfg> Workspace<'cfg> { // (not documented) or proc macros (have no scrape-able exports). Additionally, // naively passing a proc macro's unit_for to new_unit_dep will currently cause // Cargo to panic, see issue #10545. - self.is_member(&unit.pkg) && !unit.target.for_host() + self.is_member(&unit.pkg) && !(unit.target.for_host() || unit.pkg.proc_macro()) } } diff --git a/src/cargo/ops/cargo_compile/mod.rs b/src/cargo/ops/cargo_compile/mod.rs index 6e149241be8..b520275bf87 100644 --- a/src/cargo/ops/cargo_compile/mod.rs +++ b/src/cargo/ops/cargo_compile/mod.rs @@ -375,19 +375,15 @@ pub fn create_bcx<'a, 'cfg>( mode: CompileMode::Docscrape, ..generator }; - let all_units = scrape_generator.generate_root_units()?; - - let valid_units = all_units - .into_iter() - .filter(|unit| { - ws.unit_needs_doc_scrape(unit) - && !matches!( - unit.target.doc_scrape_examples(), - RustdocScrapeExamples::Disabled - ) - }) - .collect::>(); - valid_units + let mut scrape_units = scrape_generator.generate_root_units()?; + scrape_units.retain(|unit| { + ws.unit_needs_doc_scrape(unit) + && !matches!( + unit.target.doc_scrape_examples(), + RustdocScrapeExamples::Disabled + ) + }); + scrape_units } else { Vec::new() }; diff --git a/tests/testsuite/docscrape.rs b/tests/testsuite/docscrape.rs index 681b92489a9..b5f8abbcaf2 100644 --- a/tests/testsuite/docscrape.rs +++ b/tests/testsuite/docscrape.rs @@ -595,3 +595,27 @@ fn only_scrape_documented_targets() { // be scraped. run_with_config("doc = false\ndoc-scrape-examples = true", true); } + +#[cargo_test(nightly, reason = "rustdoc scrape examples flags are unstable")] +fn issue_11496() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "repro" + version = "0.1.0" + edition = "2021" + + [lib] + proc-macro = true + "#, + ) + .file("src/lib.rs", "") + .file("examples/ex.rs", "fn main(){}") + .build(); + + p.cargo("doc -Zunstable-options -Zrustdoc-scrape-examples") + .masquerade_as_nightly_cargo(&["rustdoc-scrape-examples"]) + .run(); +}