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, )?); } 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.