Skip to content

Commit 28adaba

Browse files
committed
Auto merge of #7023 - ehuss:doc-example, r=alexcrichton
Fix documenting an example. It was missing the dependency on the local library. Fixes #7014.
2 parents d5723eb + a59ea45 commit 28adaba

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/cargo/core/compiler/context/unit_dependencies.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,8 @@ fn compute_deps_doc<'a, 'cfg, 'tmp>(
339339
// Be sure to build/run the build script for documented libraries.
340340
ret.extend(dep_build_script(unit, bcx));
341341

342-
// If we document a binary, we need the library available.
343-
if unit.target.is_bin() {
342+
// If we document a binary/example, we need the library available.
343+
if unit.target.is_bin() || unit.target.is_example() {
344344
ret.extend(maybe_lib(unit, bcx, UnitFor::new_normal()));
345345
}
346346
Ok(ret)

tests/testsuite/doc.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,3 +1364,41 @@ fn short_message_format() {
13641364
)
13651365
.run();
13661366
}
1367+
1368+
#[cargo_test]
1369+
fn doc_example() {
1370+
let p = project()
1371+
.file(
1372+
"Cargo.toml",
1373+
r#"
1374+
[package]
1375+
name = "foo"
1376+
version = "0.1.0"
1377+
edition = "2018"
1378+
1379+
[[example]]
1380+
crate-type = ["lib"]
1381+
name = "ex1"
1382+
doc = true
1383+
"#,
1384+
)
1385+
.file("src/lib.rs", "pub fn f() {}")
1386+
.file(
1387+
"examples/ex1.rs",
1388+
r#"
1389+
use foo::f;
1390+
1391+
/// Example
1392+
pub fn x() { f(); }
1393+
"#,
1394+
)
1395+
.build();
1396+
1397+
p.cargo("doc").run();
1398+
assert!(p
1399+
.build_dir()
1400+
.join("doc")
1401+
.join("ex1")
1402+
.join("fn.x.html")
1403+
.exists());
1404+
}

0 commit comments

Comments
 (0)