Files
rust/tests/run-make/duplicate-dependency/rmake.rs
Martin Nordholts eeb7cb1b8a compiler: Hint at multiple crate versions if trait impl is for wrong ADT
If a user does e.g.

    impl From<Bar> for foo::Foo

and get a compilation error about that `From<Bar>` is not implemented
for `Foo`, check if multiple versions of the crate with `Foo` is present
in the dependency graph. If so, give a hint about it.

I encountered this case in the wild and didn't realize I had multiple
versions of a crate in my dependency graph. So I was a bit confused at
first. This fix will make life easier for others.
2025-10-06 06:21:45 +02:00

46 lines
1.2 KiB
Rust

//@ needs-target-std
use run_make_support::{Rustc, cwd, diff, rust_lib_name, rustc};
fn rustc_with_common_args() -> Rustc {
let mut rustc = rustc();
rustc.remap_path_prefix(cwd(), "$DIR");
rustc.edition("2018"); // Don't require `extern crate`
rustc
}
fn main() {
rustc_with_common_args()
.input("foo-v1.rs")
.crate_type("rlib")
.crate_name("foo")
.extra_filename("-v1")
.metadata("-v1")
.run();
rustc_with_common_args()
.input("foo-v2.rs")
.crate_type("rlib")
.crate_name("foo")
.extra_filename("-v2")
.metadata("-v2")
.run();
rustc_with_common_args()
.input("re-export-foo.rs")
.crate_type("rlib")
.extern_("foo", rust_lib_name("foo-v2"))
.run();
let stderr = rustc_with_common_args()
.input("main.rs")
.extern_("foo", rust_lib_name("foo-v1"))
.extern_("re_export_foo", rust_lib_name("re_export_foo"))
.library_search_path(cwd())
.ui_testing()
.run_fail()
.stderr_utf8();
diff().expected_file("main.stderr").normalize(r"\\", "/").actual_text("(rustc)", &stderr).run();
}