Skip to content

Commit 01c06b0

Browse files
committed
Auto merge of #10533 - willcrichton:fix-scrape-profile, r=epage
Fix how scrape-examples handles proc macros ### What does this PR try to resolve? This PR fixes #10500. Previously, the scrape-examples extension did some shenanigans in `build_unit_dependencies` in order to scrape `proc-macro` crates. But this code is useless since `proc-macro` crates cannot export functions, so we avoid this issue entirely by filtering proc-macro targets. ### How should we test and review this PR? I added the test `scrape_examples_configure_profile` to ensure that the issue in #10500 is fixed. r? `@ehuss`
2 parents b1603eb + e55c40f commit 01c06b0

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

src/cargo/core/compiler/unit_dependencies.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -711,11 +711,6 @@ fn compute_deps_doc(
711711
// Add all units being scraped for examples as a dependency of Doc units.
712712
if state.ws.is_member(&unit.pkg) {
713713
for scrape_unit in state.scrape_units.iter() {
714-
// This needs to match the FeaturesFor used in cargo_compile::generate_targets.
715-
let unit_for = UnitFor::new_host(
716-
scrape_unit.target.proc_macro(),
717-
unit_for.root_compile_kind(),
718-
);
719714
deps_of(scrape_unit, state, unit_for)?;
720715
ret.push(new_unit_dep(
721716
state,

src/cargo/ops/cargo_compile.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,10 @@ pub fn create_bcx<'a, 'cfg>(
546546
&profiles,
547547
interner,
548548
)?
549+
.into_iter()
550+
// Proc macros should not be scraped for functions, since they only export macros
551+
.filter(|unit| !unit.target.proc_macro())
552+
.collect::<Vec<_>>()
549553
}
550554
None => Vec::new(),
551555
};

tests/testsuite/doc.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2560,6 +2560,39 @@ fn scrape_examples_missing_flag() {
25602560
.run();
25612561
}
25622562

2563+
#[cargo_test]
2564+
fn scrape_examples_configure_profile() {
2565+
if !is_nightly() {
2566+
// -Z rustdoc-scrape-examples is unstable
2567+
return;
2568+
}
2569+
2570+
let p = project()
2571+
.file(
2572+
"Cargo.toml",
2573+
r#"
2574+
[package]
2575+
name = "foo"
2576+
version = "0.0.1"
2577+
authors = []
2578+
2579+
[profile.dev]
2580+
panic = "abort"
2581+
"#,
2582+
)
2583+
.file("examples/ex.rs", "fn main() { foo::foo(); }")
2584+
.file("src/lib.rs", "pub fn foo() {}\npub fn bar() { foo(); }")
2585+
.build();
2586+
2587+
p.cargo("doc -Zunstable-options -Z rustdoc-scrape-examples=all")
2588+
.masquerade_as_nightly_cargo()
2589+
.run();
2590+
2591+
let doc_html = p.read_file("target/doc/foo/fn.foo.html");
2592+
assert!(doc_html.contains("Examples found in repository"));
2593+
assert!(doc_html.contains("More examples"));
2594+
}
2595+
25632596
#[cargo_test]
25642597
fn lib_before_bin() {
25652598
// Checks that the library is documented before the binary.

0 commit comments

Comments
 (0)