Description
https://github.com/huonw/bad-error-messages-a contains a crate a
. https://github.com/huonw/bad-error-messages-bc contains two crates, b
and c
.
a
contains a traitFoo
and a functiontest
that requires that trait.b
depends on a specific revision (8b532f5, not the HEAD) ofa
and contains a typeBar
that implementsa::Foo
.c
depends ona
's HEAD (happens to be 84cfe230) andb
, and tries to useb::Bar
witha::test
.
c
fails to compile despite Bar
"clearly" implementing Foo
... it's even displayed in the docs!
Cloning https://github.com/huonw/bad-error-messages-bc and running cargo build
in the root (which is c
) gives
Compiling a v0.0.1 (https://github.com/huonw/bad-error-messages-a#84cfe230)
Compiling a v0.0.1 (https://github.com/huonw/bad-error-messages-a?rev=8b532f5#8b532f51)
Compiling b v0.0.1 (file:///home/huon/projects/test-rust/error-messages/c)
Compiling c v0.0.1 (file:///home/huon/projects/test-rust/error-messages/c)
src/lib.rs:5:5: 5:12 error: the trait `a::Foo` is not implemented for the type `b::Bar` [E0277]
src/lib.rs:5 a::test(b::Bar);
^~~~~~~
error: aborting due to previous error
There's no indication of the fundamental problem from either rustdoc
or rustc
: that there's two different versions of a
being used, meaning a#84cfe230::Foo
and a#8b532f5::Foo
are different. Bar
only implements the latter, but in c
, the name a
refers to a#84cfe230
so a::test(...)
requires the former. (Using name#rev
to represent the crate with that version.)
There is an indication of the difference in the example above, since a
is compiled twice, but that comes from cargo
, not rustc
. This issue is focusing on the fact that rustc
itself does not give helpful errors and/or allow tools like cargo to control those errors.
It would be nice if rustc:
- disambiguated ambiguous names, probably by filepath/name by default
- allowed cargo to specify semantically relevant info for the disambiguation e.g. pass in the version/revision/..., so that rustc can print
foo#0.2.3
instead of the filepath/name - detected errors that may be caused by ambiguous names and noted it explicitly, e.g. when there is a error involving an ambiguous crate print (once) some extra lines like
"note: there's multiple versions of crate
...in use"
: along with a listing of the possibilities.
(NB. I've used cargo
to construct this example because it is the easiest way I can get two different versions of a crate. This appears in rust-lang/rust's makefiles too, where the std
test runner is called "std" internally, but links against another crate called "std", i.e. the conventional standard library.)