Skip to content

Commit

Permalink
Auto merge of #7023 - ehuss:doc-example, r=alexcrichton
Browse files Browse the repository at this point in the history
Fix documenting an example.

It was missing the dependency on the local library.

Fixes #7014.
  • Loading branch information
bors committed Jun 10, 2019
2 parents d5723eb + a59ea45 commit 28adaba
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/cargo/core/compiler/context/unit_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ fn compute_deps_doc<'a, 'cfg, 'tmp>(
// Be sure to build/run the build script for documented libraries.
ret.extend(dep_build_script(unit, bcx));

// If we document a binary, we need the library available.
if unit.target.is_bin() {
// If we document a binary/example, we need the library available.
if unit.target.is_bin() || unit.target.is_example() {
ret.extend(maybe_lib(unit, bcx, UnitFor::new_normal()));
}
Ok(ret)
Expand Down
38 changes: 38 additions & 0 deletions tests/testsuite/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1364,3 +1364,41 @@ fn short_message_format() {
)
.run();
}

#[cargo_test]
fn doc_example() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2018"
[[example]]
crate-type = ["lib"]
name = "ex1"
doc = true
"#,
)
.file("src/lib.rs", "pub fn f() {}")
.file(
"examples/ex1.rs",
r#"
use foo::f;
/// Example
pub fn x() { f(); }
"#,
)
.build();

p.cargo("doc").run();
assert!(p
.build_dir()
.join("doc")
.join("ex1")
.join("fn.x.html")
.exists());
}

0 comments on commit 28adaba

Please sign in to comment.