diff --git a/src/cargo/core/compiler/unit_dependencies.rs b/src/cargo/core/compiler/unit_dependencies.rs index c3ad24645c0..cf1b74a7367 100644 --- a/src/cargo/core/compiler/unit_dependencies.rs +++ b/src/cargo/core/compiler/unit_dependencies.rs @@ -711,11 +711,6 @@ fn compute_deps_doc( // Add all units being scraped for examples as a dependency of Doc units. if state.ws.is_member(&unit.pkg) { for scrape_unit in state.scrape_units.iter() { - // This needs to match the FeaturesFor used in cargo_compile::generate_targets. - let unit_for = UnitFor::new_host( - scrape_unit.target.proc_macro(), - unit_for.root_compile_kind(), - ); deps_of(scrape_unit, state, unit_for)?; ret.push(new_unit_dep( state, diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 0d28f51696f..2a5d09f520b 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -546,6 +546,10 @@ pub fn create_bcx<'a, 'cfg>( &profiles, interner, )? + .into_iter() + // Proc macros should not be scraped for functions, since they only export macros + .filter(|unit| !unit.target.proc_macro()) + .collect::>() } None => Vec::new(), }; diff --git a/tests/testsuite/doc.rs b/tests/testsuite/doc.rs index 917981d4949..dd6a3ec46ca 100644 --- a/tests/testsuite/doc.rs +++ b/tests/testsuite/doc.rs @@ -2560,6 +2560,39 @@ fn scrape_examples_missing_flag() { .run(); } +#[cargo_test] +fn scrape_examples_configure_profile() { + if !is_nightly() { + // -Z rustdoc-scrape-examples is unstable + return; + } + + 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 -Zunstable-options -Z rustdoc-scrape-examples=all") + .masquerade_as_nightly_cargo() + .run(); + + let doc_html = p.read_file("target/doc/foo/fn.foo.html"); + assert!(doc_html.contains("Examples found in repository")); + assert!(doc_html.contains("More examples")); +} + #[cargo_test] fn lib_before_bin() { // Checks that the library is documented before the binary.