Skip to content

Commit e3f2953

Browse files
committed
Auto merge of #10037 - willcrichton:example-analyzer, r=alexcrichton
Fix --scrape-examples-target-crate using package name (with dashes) instead of crate name (with underscores) This PR fixes #10035.
2 parents 94ca096 + 7ee3ffc commit e3f2953

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/cargo/core/compiler/mod.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ mod unit;
2121
pub mod unit_dependencies;
2222
pub mod unit_graph;
2323

24+
use std::collections::HashSet;
2425
use std::env;
2526
use std::ffi::{OsStr, OsString};
2627
use std::fs::{self, File};
@@ -666,9 +667,14 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
666667

667668
// Only scrape example for items from crates in the workspace, to reduce generated file size
668669
for pkg in cx.bcx.ws.members() {
669-
rustdoc
670-
.arg("--scrape-examples-target-crate")
671-
.arg(pkg.name());
670+
let names = pkg
671+
.targets()
672+
.iter()
673+
.map(|target| target.crate_name())
674+
.collect::<HashSet<_>>();
675+
for name in names {
676+
rustdoc.arg("--scrape-examples-target-crate").arg(name);
677+
}
672678
}
673679
} else if cx.bcx.scrape_units.len() > 0 && cx.bcx.ws.is_member(&unit.pkg) {
674680
// We only pass scraped examples to packages in the workspace

tests/testsuite/doc.rs

+29
Original file line numberDiff line numberDiff line change
@@ -2297,3 +2297,32 @@ fn scrape_examples_complex_reverse_dependencies() {
22972297
.masquerade_as_nightly_cargo()
22982298
.run();
22992299
}
2300+
2301+
#[cargo_test]
2302+
fn scrape_examples_crate_with_dash() {
2303+
if !is_nightly() {
2304+
// -Z rustdoc-scrape-examples is unstable
2305+
return;
2306+
}
2307+
2308+
let p = project()
2309+
.file(
2310+
"Cargo.toml",
2311+
r#"
2312+
[package]
2313+
name = "da-sh"
2314+
version = "0.0.1"
2315+
authors = []
2316+
"#,
2317+
)
2318+
.file("src/lib.rs", "pub fn foo() {}")
2319+
.file("examples/a.rs", "fn main() { da_sh::foo(); }")
2320+
.build();
2321+
2322+
p.cargo("doc -Zunstable-options -Z rustdoc-scrape-examples=all")
2323+
.masquerade_as_nightly_cargo()
2324+
.run();
2325+
2326+
let doc_html = p.read_file("target/doc/da_sh/fn.foo.html");
2327+
assert!(doc_html.contains("Examples found in repository"));
2328+
}

0 commit comments

Comments
 (0)