Skip to content

Commit 9978fd7

Browse files
committed
Auto merge of #10324 - ehuss:fix-doc-undocumented-dep, r=alexcrichton
Fix documenting with undocumented dependencies. #10201 introduced a bug where dependencies that have `doc=false` weren't being built at all when running `cargo doc` if the project did not have any binaries. That means the rmeta file was missing, and the `--extern` flag was not being passed to rustdoc. The solution is to ensure the `rmeta` file gets generated, but only skip generating the `CompileMode::Doc` unit for undocumented dependencies. This unblocks the bootstrap bump.
2 parents 58790d3 + fdeb38b commit 9978fd7

File tree

2 files changed

+61
-14
lines changed

2 files changed

+61
-14
lines changed

src/cargo/core/compiler/unit_dependencies.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ fn compute_deps_doc(
431431
let mut ret = Vec::new();
432432
for (id, _deps) in deps {
433433
let dep = state.get(id);
434-
let lib = match dep.targets().iter().find(|t| t.is_lib() && t.documented()) {
434+
let lib = match dep.targets().iter().find(|t| t.is_lib()) {
435435
Some(lib) => lib,
436436
None => continue,
437437
};
@@ -449,18 +449,20 @@ fn compute_deps_doc(
449449
mode,
450450
)?;
451451
ret.push(lib_unit_dep);
452-
if let CompileMode::Doc { deps: true } = unit.mode {
453-
// Document this lib as well.
454-
let doc_unit_dep = new_unit_dep(
455-
state,
456-
unit,
457-
dep,
458-
lib,
459-
dep_unit_for,
460-
unit.kind.for_target(lib),
461-
unit.mode,
462-
)?;
463-
ret.push(doc_unit_dep);
452+
if lib.documented() {
453+
if let CompileMode::Doc { deps: true } = unit.mode {
454+
// Document this lib as well.
455+
let doc_unit_dep = new_unit_dep(
456+
state,
457+
unit,
458+
dep,
459+
lib,
460+
dep_unit_for,
461+
unit.kind.for_target(lib),
462+
unit.mode,
463+
)?;
464+
ret.push(doc_unit_dep);
465+
}
464466
}
465467
}
466468

tests/testsuite/doc.rs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2557,7 +2557,7 @@ fn doc_lib_false() {
25572557
bar = {path = "bar"}
25582558
"#,
25592559
)
2560-
.file("src/lib.rs", "")
2560+
.file("src/lib.rs", "extern crate bar;")
25612561
.file("src/bin/some-bin.rs", "fn main() {}")
25622562
.file(
25632563
"bar/Cargo.toml",
@@ -2588,3 +2588,48 @@ fn doc_lib_false() {
25882588
assert!(!p.build_dir().join("doc/bar").exists());
25892589
assert!(p.build_dir().join("doc/some_bin").exists());
25902590
}
2591+
2592+
#[cargo_test]
2593+
fn doc_lib_false_dep() {
2594+
// doc = false for a dependency
2595+
// Ensures that the rmeta gets produced
2596+
let p = project()
2597+
.file(
2598+
"Cargo.toml",
2599+
r#"
2600+
[package]
2601+
name = "foo"
2602+
version = "0.1.0"
2603+
2604+
[dependencies]
2605+
bar = { path = "bar" }
2606+
"#,
2607+
)
2608+
.file("src/lib.rs", "extern crate bar;")
2609+
.file(
2610+
"bar/Cargo.toml",
2611+
r#"
2612+
[package]
2613+
name = "bar"
2614+
version = "0.1.0"
2615+
2616+
[lib]
2617+
doc = false
2618+
"#,
2619+
)
2620+
.file("bar/src/lib.rs", "")
2621+
.build();
2622+
2623+
p.cargo("doc")
2624+
.with_stderr(
2625+
"\
2626+
[CHECKING] bar v0.1.0 [..]
2627+
[DOCUMENTING] foo v0.1.0 [..]
2628+
[FINISHED] [..]
2629+
",
2630+
)
2631+
.run();
2632+
2633+
assert!(p.build_dir().join("doc/foo").exists());
2634+
assert!(!p.build_dir().join("doc/bar").exists());
2635+
}

0 commit comments

Comments
 (0)