Skip to content

Commit

Permalink
Fix examples of proc-macro crates being scraped for examples
Browse files Browse the repository at this point in the history
  • Loading branch information
willcrichton committed Dec 18, 2022
1 parent e517d5a commit d588298
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down
22 changes: 9 additions & 13 deletions src/cargo/ops/cargo_compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();
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()
};
Expand Down
24 changes: 24 additions & 0 deletions tests/testsuite/docscrape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit d588298

Please sign in to comment.