From 90fc7dcf85736732c9d40c0b5ad0017da6e481bd Mon Sep 17 00:00:00 2001 From: Will Crichton Date: Tue, 29 Mar 2022 09:59:15 +0200 Subject: [PATCH 1/2] properly memoize Docscrape units --- src/cargo/core/compiler/unit_dependencies.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cargo/core/compiler/unit_dependencies.rs b/src/cargo/core/compiler/unit_dependencies.rs index c3ad24645c0..503db7fc012 100644 --- a/src/cargo/core/compiler/unit_dependencies.rs +++ b/src/cargo/core/compiler/unit_dependencies.rs @@ -717,7 +717,7 @@ fn compute_deps_doc( unit_for.root_compile_kind(), ); deps_of(scrape_unit, state, unit_for)?; - ret.push(new_unit_dep( + ret.push(new_unit_dep_with_profile( state, scrape_unit, &scrape_unit.pkg, @@ -725,6 +725,7 @@ fn compute_deps_doc( unit_for, scrape_unit.kind, scrape_unit.mode, + scrape_unit.profile.clone(), IS_NO_ARTIFACT_DEP, )?); } From 41b6810480b44d93e7d27b4da30f30dca16dc178 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Tue, 29 Mar 2022 09:57:56 +0200 Subject: [PATCH 2/2] add test for `-Z rustdoc-scrape-examples` issue #10500 --- tests/testsuite/doc.rs | 54 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/testsuite/doc.rs b/tests/testsuite/doc.rs index 917981d4949..547879a5292 100644 --- a/tests/testsuite/doc.rs +++ b/tests/testsuite/doc.rs @@ -2560,6 +2560,60 @@ fn scrape_examples_missing_flag() { .run(); } +#[cargo_test] +fn scrape_examples_with_overriden_profiles() { + if !is_nightly() { + // -Z rustdoc-scrape-examples is unstable + return; + } + + // #10500 is an issue where different profile overrides would make `cargo -Z + // rustdoc-scrape-examples` panic due to incomplete memoization of some + // units to scrape. + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [profile.dev] + panic = "abort" + "#, + ) + .file("examples/ex.rs", "fn main() { foo::foo(); }") + .file("src/lib.rs", "pub fn foo() {}\npub fn bar() { foo(); }") + .build(); + + p.cargo("doc --all -Zunstable-options -Z rustdoc-scrape-examples=all") + .masquerade_as_nightly_cargo() + .run(); + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [profile.dev.build-override] + debug = 0 + "#, + ) + .file("examples/ex.rs", "fn main() { foo::foo(); }") + .file("src/lib.rs", "pub fn foo() {}\npub fn bar() { foo(); }") + .build(); + + p.cargo("doc --all -Zunstable-options -Z rustdoc-scrape-examples=all") + .masquerade_as_nightly_cargo() + .run(); +} + #[cargo_test] fn lib_before_bin() { // Checks that the library is documented before the binary.