Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/cargo/ops/cargo_compile/unit_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ impl<'a> UnitGenerator<'a, '_> {
.filter(|t| {
t.documented()
&& (!t.is_bin()
|| !targets.iter().any(|l| l.is_lib() && l.name() == t.name()))
|| !targets
.iter()
.any(|l| l.is_lib() && l.crate_name() == t.crate_name()))
})
.collect()
}
Expand Down
22 changes: 22 additions & 0 deletions tests/testsuite/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,28 @@ fn doc_lib_bin_same_name_documents_lib_when_requested() {
assert!(!doc_html.contains("Binary"));
}

#[cargo_test]
fn doc_lib_bin_same_name_with_dash() {
// Checks `doc` behavior when there is a dash in the package name, and
// there is a lib and bin, and the lib name is inferred.
let p = project()
.file("Cargo.toml", &basic_manifest("foo-bar", "1.0.0"))
.file("src/lib.rs", "")
.file("src/main.rs", "fn main() {}")
.build();
p.cargo("doc")
.with_stderr(
"\
[DOCUMENTING] foo-bar v1.0.0 ([ROOT]/foo)
[FINISHED] [..]
[GENERATED] [ROOT]/foo/target/doc/foo_bar/index.html
",
)
.run();
assert!(p.build_dir().join("doc/foo_bar/index.html").exists());
assert!(!p.build_dir().join("doc/foo_bar/fn.main.html").exists());
}

#[cargo_test]
fn doc_lib_bin_same_name_documents_named_bin_when_requested() {
let p = project()
Expand Down