Skip to content

Commit c56140f

Browse files
committed
Auto merge of #13640 - ehuss:fix-doc-dash-collision, r=epage
Fix doc collision for lib/bin with a dash in the inferred name. This fixes an issue where `cargo doc` would report a collision if the project has a `-` in the name, and both a lib and bin. As a consequence of the change in #12783, the target name for the library no longer has a `-`. The code that checks for the lib/bin doc collision was only checking if the target names were equal, which is no longer the case after #12783. The solution here is to use the `crate_name` and not the target name, which has the appropriate `_` translation done. This is the more correct method to use, even before #12783, because rustdoc uses crate names, not target names (and thus even documenting bins have their filenames converted to underscores). Fixes #13628
2 parents bc844af + 3adb796 commit c56140f

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/cargo/ops/cargo_compile/unit_generator.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ impl<'a> UnitGenerator<'a, '_> {
198198
.filter(|t| {
199199
t.documented()
200200
&& (!t.is_bin()
201-
|| !targets.iter().any(|l| l.is_lib() && l.name() == t.name()))
201+
|| !targets
202+
.iter()
203+
.any(|l| l.is_lib() && l.crate_name() == t.crate_name()))
202204
})
203205
.collect()
204206
}

tests/testsuite/doc.rs

+22
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,28 @@ fn doc_lib_bin_same_name_documents_lib_when_requested() {
478478
assert!(!doc_html.contains("Binary"));
479479
}
480480

481+
#[cargo_test]
482+
fn doc_lib_bin_same_name_with_dash() {
483+
// Checks `doc` behavior when there is a dash in the package name, and
484+
// there is a lib and bin, and the lib name is inferred.
485+
let p = project()
486+
.file("Cargo.toml", &basic_manifest("foo-bar", "1.0.0"))
487+
.file("src/lib.rs", "")
488+
.file("src/main.rs", "fn main() {}")
489+
.build();
490+
p.cargo("doc")
491+
.with_stderr(
492+
"\
493+
[DOCUMENTING] foo-bar v1.0.0 ([ROOT]/foo)
494+
[FINISHED] [..]
495+
[GENERATED] [ROOT]/foo/target/doc/foo_bar/index.html
496+
",
497+
)
498+
.run();
499+
assert!(p.build_dir().join("doc/foo_bar/index.html").exists());
500+
assert!(!p.build_dir().join("doc/foo_bar/fn.main.html").exists());
501+
}
502+
481503
#[cargo_test]
482504
fn doc_lib_bin_same_name_documents_named_bin_when_requested() {
483505
let p = project()

0 commit comments

Comments
 (0)