Description
Problem
In Cargo, currently the crate name you use in [dependencies]
marks where the crate is supposed to come from; it matches the package.name
key in the dependency's Cargo.toml
.
The crate name you use in extern crate foo
or foo::
has to match the actual on-disk compiled artifact name. This is not the package name, but is instead the lib.name
key in the dependency's Cargo.toml
.
If these don't match, you can have unexpected behavior (being unable to use crates by the name you'd expect them to use) as well as nonlocal bugs where one transitive dependency can break another by choosing the same [lib]
Steps
- Publish two crates with different
package
keys but the samelib
key - Try to use both in a single crate
- Get this
multiple rlib candidates
error:
error[E0465]: multiple rlib candidates for `manish_test_crate_clashes` found
--> src/main.rs:1:1
|
1 | extern crate manish_test_crate_clashes;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: candidate #1: /home/manishearth/sand/bar/crates/manish_test/target/debug/deps/libmanish_test_crate_clashes-6647f0eb7f7797e9.rlib
--> src/main.rs:1:1
|
1 | extern crate manish_test_crate_clashes;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: candidate #2: /home/manishearth/sand/bar/crates/manish_test/target/debug/deps/libmanish_test_crate_clashes-a2862f19598a10de.rlib
--> src/main.rs:1:1
|
1 | extern crate manish_test_crate_clashes;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Possible Solution(s)
I'm not actually sure if this is a bug: Having this ability doesn't seem completely useless. And for unpublished git/path packages the lib
name does matter.
It may be worth forbidding crates with a lib.name
that doesn't match package.name
from being published, after checking crates.io
for any offenders. https://github.com/messense/rustc-test is one (and is how I discovered this bug, we've been confused about a libtest thing for a while and it seems like this crate is the culprit)
Notes
Output of cargo version
: cargo 1.34.0-nightly (5c6aa46 2019-02-22)