Skip to content

Commit 390383e

Browse files
committed
Add check to not doc-scrape proc-macro units. Fixes #10571.
1 parent 79fe757 commit 390383e

File tree

2 files changed

+42
-11
lines changed

2 files changed

+42
-11
lines changed

src/cargo/ops/cargo_compile/mod.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ pub fn create_bcx<'a, 'cfg>(
370370
let should_scrape = build_config.mode.is_doc() && config.cli_unstable().rustdoc_scrape_examples;
371371
let mut scrape_units = if should_scrape {
372372
let scrape_filter = filter.refine_for_docscrape(&to_builds, has_dev_units);
373-
let all_units = generate_targets(
373+
let mut all_units = generate_targets(
374374
ws,
375375
&to_builds,
376376
&scrape_filter,
@@ -394,16 +394,17 @@ pub fn create_bcx<'a, 'cfg>(
394394
}
395395
}
396396

397-
let valid_units = all_units
398-
.into_iter()
399-
.filter(|unit| {
400-
!matches!(
401-
unit.target.doc_scrape_examples(),
402-
RustdocScrapeExamples::Disabled
403-
)
404-
})
405-
.collect::<Vec<_>>();
406-
valid_units
397+
// We further eliminate units for scraping if they are explicitly marked to not be scraped,
398+
// or if they aren't eligible for scraping (see [`Workspace::unit_needs_doc_scrape`]).
399+
all_units.retain(|unit| {
400+
let not_marked_unscrapable = !matches!(
401+
unit.target.doc_scrape_examples(),
402+
RustdocScrapeExamples::Disabled
403+
);
404+
not_marked_unscrapable && ws.unit_needs_doc_scrape(unit)
405+
});
406+
407+
all_units
407408
} else {
408409
Vec::new()
409410
};

tests/testsuite/docscrape.rs

+30
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,36 @@ fn issue_10545() {
281281
.run();
282282
}
283283

284+
#[cargo_test(nightly, reason = "rustdoc scrape examples flags are unstable")]
285+
fn no_scrape_proc_macros_issue_10571() {
286+
let p = project()
287+
.file(
288+
"Cargo.toml",
289+
r#"
290+
[package]
291+
name = "foo"
292+
version = "0.0.1"
293+
authors = []
294+
295+
[lib]
296+
proc-macro = true
297+
"#,
298+
)
299+
.file("src/lib.rs", "")
300+
.build();
301+
302+
// proc-macro library should not be scraped
303+
p.cargo("doc -Zunstable-options -Zrustdoc-scrape-examples")
304+
.masquerade_as_nightly_cargo(&["rustdoc-scrape-examples"])
305+
.with_stderr(
306+
"\
307+
[DOCUMENTING] foo v0.0.1 ([CWD])
308+
[FINISHED] [..]
309+
",
310+
)
311+
.run();
312+
}
313+
284314
#[cargo_test(nightly, reason = "rustdoc scrape examples flags are unstable")]
285315
fn cache() {
286316
let p = project()

0 commit comments

Comments
 (0)