Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo-doc overwrites similarly-named library target with binary target #5549

Closed
Aehmlo opened this issue May 18, 2018 · 2 comments
Closed

cargo-doc overwrites similarly-named library target with binary target #5549

Aehmlo opened this issue May 18, 2018 · 2 comments
Labels
A-layout Area: target output directory layout, naming, and organization Command-doc S-triage Status: This issue is waiting on initial triage.

Comments

@Aehmlo
Copy link

Aehmlo commented May 18, 2018

Consider the following Cargo.toml (some contents are redundant, but they're there to be explicit).

[package]
name = "foo"
version = "0.1.0"
authors = ["Some Body <nobody@nowhere.org>"]

[lib]
name = "foo_bar"
path = "src/lib.rs"
doc = true

[[bin]]
name = "foo-bar"
path = "src/main.rs"
doc = true

When cargo doc is run, the resulting documentation has one entry for the crate foo_bar, displaying the documentation extracted from the binary target foo-bar. I presume this has something to do with the the historical "hyphens are underscores in crate names," and I recognize it's quite the edge case, but it just took me about half an hour to figure this out just now and I figured I'd say something about it anyway. It'd be nice if the result would be something more like foo_bar and foo-bar docs, or even something like foo_bar_lib and foo_bar_bin.

I'm using cargo 1.26.0 and rustdoc 1.26.0, though I first noticed the issue using cargo nightly (2018-05-07).

@aidanhs
Copy link
Member

aidanhs commented May 19, 2018

This also happens with crates, e.g. if you have a binary called libc and depend on the libc crate:

Cargo.toml:

[package]
name = "x"
version = "0.1.0"
authors = []

[dependencies]
libc = "*"

src/bin/libc.rs

fn main() {}

src/main.rs (unnecessary, but cargo doc --open won't work without it)

fn main() {}

Running cargo doc --open will show you docs, and the libc documentation will show a blank page.

@epage epage added S-triage Status: This issue is waiting on initial triage. A-layout Area: target output directory layout, naming, and organization labels Oct 23, 2023
@epage
Copy link
Contributor

epage commented Oct 25, 2023

Thanks to #6998, this is mostly resolved

arning: output filename collision.
The bin target `foo-bar` in package `foo v0.1.0 (/home/epage/src/personal/dump/foo)` has the same output filename as the lib target `foo_bar` in package `foo v0.1.0 (/home/epage/src/personal
/dump/foo)`.
Colliding filename is: /home/epage/src/personal/dump/foo/target/doc/foo_bar/index.html
The output filenames should be unique.
This is a known bug where multiple crates with the same name use
the same path; see <https://github.com/rust-lang/cargo/issues/6313>.
If this looks unexpected, it may be a bug in Cargo. Please file a bug report at
https://github.com/rust-lang/cargo/issues/ with as much information as you
can provide.
cargo 1.73.0 (9c4383fb5 2023-08-26) running on `x86_64-unknown-linux-gnu` target `x86_64-unknown-linux-gnu`
First unit: Unit { pkg: Package { id: PackageId { name: "foo", version: "0.1.0", source: "/home/epage/src/personal/dump/foo" }, ..: ".." }, target: TargetInner { name: "foo-bar", doc: true,
..: with_path("/home/epage/src/personal/dump/foo/src/main.rs", Edition2015) }, profile: Profile { ..: default_dev() }, kind: Host, mode: Doc { deps: true }, features: [], artifact: false, ar
tifact_target_for_features: None, is_std: false, dep_hash: 17975679418527223829 }
Second unit: Unit { pkg: Package { id: PackageId { name: "foo", version: "0.1.0", source: "/home/epage/src/personal/dump/foo" }, ..: ".." }, target: TargetInner { ..: lib_target("foo_bar", [
"lib"], "/home/epage/src/personal/dump/foo/src/lib.rs", Edition2015) }, profile: Profile { ..: default_dev() }, kind: Host, mode: Doc { deps: true }, features: [], artifact: false, artifact_
target_for_features: None, is_std: false, dep_hash: 2202906307356721367 }
 Documenting foo v0.1.0 (/home/epage/src/personal/dump/foo)
    Finished dev [unoptimized + debuginfo] target(s) in 0.28s

See #6313 for any next steps on where this might go.

@epage epage closed this as not planned Won't fix, can't repro, duplicate, stale Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-layout Area: target output directory layout, naming, and organization Command-doc S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

4 participants