Skip to content

Commit 178f8bf

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

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

src/cargo/ops/cargo_compile/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,16 @@ pub fn create_bcx<'a, 'cfg>(
394394
}
395395
}
396396

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`]).
397399
let valid_units = all_units
398400
.into_iter()
399401
.filter(|unit| {
400-
!matches!(
401-
unit.target.doc_scrape_examples(),
402-
RustdocScrapeExamples::Disabled
403-
)
402+
ws.unit_needs_doc_scrape(unit)
403+
&& !matches!(
404+
unit.target.doc_scrape_examples(),
405+
RustdocScrapeExamples::Disabled
406+
)
404407
})
405408
.collect::<Vec<_>>();
406409
valid_units

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)