mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
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`
This commit is contained in:
commit
01c06b0360
@ -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,
|
||||
|
@ -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::<Vec<_>>()
|
||||
}
|
||||
None => Vec::new(),
|
||||
};
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user