Skip to content

Add check to not doc-scrape proc-macro units. Fixes #10571. #11423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/cargo/ops/cargo_compile/mod.rs
Original file line number Diff line number Diff line change
@@ -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::<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()
};
30 changes: 30 additions & 0 deletions tests/testsuite/docscrape.rs
Original file line number Diff line number Diff line change
@@ -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()