Skip to content

Commit

Permalink
Fix scrape-examples incorrectly handling proc macros
Browse files Browse the repository at this point in the history
  • Loading branch information
willcrichton committed Apr 2, 2022
1 parent b1603eb commit e55c40f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
5 changes: 0 additions & 5 deletions src/cargo/core/compiler/unit_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
Expand Down
33 changes: 33 additions & 0 deletions tests/testsuite/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit e55c40f

Please sign in to comment.