Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix examples of proc-macro crates being scraped for examples #11497

Merged
merged 1 commit into from
Dec 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1515,7 +1515,7 @@ impl<'cfg> Workspace<'cfg> {
// (not documented) or proc macros (have no scrape-able exports). Additionally,
// naively passing a proc macro's unit_for to new_unit_dep will currently cause
// Cargo to panic, see issue #10545.
self.is_member(&unit.pkg) && !unit.target.for_host()
self.is_member(&unit.pkg) && !(unit.target.for_host() || unit.pkg.proc_macro())
}
}

Expand Down
22 changes: 9 additions & 13 deletions src/cargo/ops/cargo_compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,19 +375,15 @@ pub fn create_bcx<'a, 'cfg>(
mode: CompileMode::Docscrape,
..generator
};
let all_units = scrape_generator.generate_root_units()?;

let valid_units = all_units
.into_iter()
.filter(|unit| {
ws.unit_needs_doc_scrape(unit)
&& !matches!(
unit.target.doc_scrape_examples(),
RustdocScrapeExamples::Disabled
)
})
.collect::<Vec<_>>();
valid_units
let mut scrape_units = scrape_generator.generate_root_units()?;
scrape_units.retain(|unit| {
ws.unit_needs_doc_scrape(unit)
&& !matches!(
unit.target.doc_scrape_examples(),
RustdocScrapeExamples::Disabled
)
});
scrape_units
} else {
Vec::new()
};
Expand Down
24 changes: 24 additions & 0 deletions tests/testsuite/docscrape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,27 @@ fn only_scrape_documented_targets() {
// be scraped.
run_with_config("doc = false\ndoc-scrape-examples = true", true);
}

#[cargo_test(nightly, reason = "rustdoc scrape examples flags are unstable")]
fn issue_11496() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "repro"
version = "0.1.0"
edition = "2021"

[lib]
proc-macro = true
"#,
)
.file("src/lib.rs", "")
.file("examples/ex.rs", "fn main(){}")
.build();

p.cargo("doc -Zunstable-options -Zrustdoc-scrape-examples")
.masquerade_as_nightly_cargo(&["rustdoc-scrape-examples"])
.run();
}