Skip to content

Commit

Permalink
Fix documenting an example.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Jun 8, 2019
1 parent d5723eb commit a59ea45
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 a59ea45

Please sign in to comment.