Skip to content

Commit

Permalink
Add check to not doc-scrape proc-macro units. Fixes rust-lang#10571.
Browse files Browse the repository at this point in the history
  • Loading branch information
willcrichton committed Nov 25, 2022
1 parent 79fe757 commit 390383e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/cargo/ops/cargo_compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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::<Vec<_>>();
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()
};
Expand Down
30 changes: 30 additions & 0 deletions tests/testsuite/docscrape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 390383e

Please sign in to comment.