about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOneirical <manchot@videotron.ca>2024-07-09 16:34:22 -0400
committerOneirical <manchot@videotron.ca>2024-07-09 16:34:22 -0400
commit80fb4cab4e831f8c2bc735b71c351a198e17c9c9 (patch)
treee9223ffcde2aa8e0c2a0c907d4f8f525e3d1446f
parent37599b2072cba572ae9dcf7d1be1445f46f8125c (diff)
downloadrust-80fb4cab4e831f8c2bc735b71c351a198e17c9c9.tar.gz
rust-80fb4cab4e831f8c2bc735b71c351a198e17c9c9.zip
rewrite type-mismatch-same-crate-name to rmake
-rw-r--r--src/tools/tidy/src/allowed_run_make_makefiles.txt1
-rw-r--r--tests/run-make/type-mismatch-same-crate-name/Makefile19
-rw-r--r--tests/run-make/type-mismatch-same-crate-name/rmake.rs29
3 files changed, 29 insertions, 20 deletions
diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt
index f71992cad23..52410382828 100644
--- a/src/tools/tidy/src/allowed_run_make_makefiles.txt
+++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt
@@ -142,6 +142,5 @@ run-make/test-benches/Makefile
 run-make/thumb-none-cortex-m/Makefile
 run-make/thumb-none-qemu/Makefile
 run-make/translation/Makefile
-run-make/type-mismatch-same-crate-name/Makefile
 run-make/unstable-flag-required/Makefile
 run-make/x86_64-fortanix-unknown-sgx-lvi/Makefile
diff --git a/tests/run-make/type-mismatch-same-crate-name/Makefile b/tests/run-make/type-mismatch-same-crate-name/Makefile
deleted file mode 100644
index a2a2a41c7a5..00000000000
--- a/tests/run-make/type-mismatch-same-crate-name/Makefile
+++ /dev/null
@@ -1,19 +0,0 @@
-include ../tools.mk
-
-all:
-	# compile two different versions of crateA
-	$(RUSTC) --crate-type=rlib crateA.rs -C metadata=-1 -C extra-filename=-1
-	$(RUSTC) --crate-type=rlib crateA.rs -C metadata=-2 -C extra-filename=-2
-	# make crateB depend on version 1 of crateA
-	$(RUSTC) --crate-type=rlib crateB.rs --extern crateA=$(TMPDIR)/libcrateA-1.rlib
-	# make crateC depend on version 2 of crateA
-	$(RUSTC) crateC.rs --extern crateA=$(TMPDIR)/libcrateA-2.rlib 2>&1 | \
-		tr -d '\r\n' | $(CGREP) -e \
-	"mismatched types.*\
-	crateB::try_foo\(foo2\);.*\
-	expected \`crateA::foo::Foo\`, found \`Foo\`.*\
-	different versions of crate \`crateA\`.*\
-	mismatched types.*\
-	crateB::try_bar\(bar2\);.*\
-	expected trait \`crateA::bar::Bar\`, found trait \`Bar\`.*\
-	different versions of crate \`crateA\`"
diff --git a/tests/run-make/type-mismatch-same-crate-name/rmake.rs b/tests/run-make/type-mismatch-same-crate-name/rmake.rs
new file mode 100644
index 00000000000..ecf80d88d51
--- /dev/null
+++ b/tests/run-make/type-mismatch-same-crate-name/rmake.rs
@@ -0,0 +1,29 @@
+// When a compilation failure deals with seemingly identical types, some helpful
+// errors should be printed.
+// The main use case of this error is when there are two crates
+// (generally different versions of the same crate) with the same name
+// causing a type mismatch. In this test, one of the crates
+// is only introduced as an indirect dependency and the type is accessed via a reexport.
+// See https://github.com/rust-lang/rust/pull/42826
+
+use run_make_support::{rust_lib_name, rustc};
+
+fn main() {
+    rustc().crate_type("rlib").input("crateA.rs").metadata("-1").extra_filename("-1").run();
+    rustc().crate_type("rlib").input("crateA.rs").metadata("-2").extra_filename("-2").run();
+    rustc()
+        .crate_type("rlib")
+        .input("crateB.rs")
+        .extern_("crateA", rust_lib_name("crateA-1"))
+        .run();
+    rustc()
+        .input("crateC.rs")
+        .extern_("crateA", rust_lib_name("crateA-2"))
+        .run_fail()
+        .assert_stderr_contains("mismatched types")
+        .assert_stderr_contains("crateB::try_foo(foo2);")
+        .assert_stderr_contains("different versions of crate `crateA`")
+        .assert_stderr_contains("crateB::try_bar(bar2);")
+        .assert_stderr_contains("expected trait `crateA::bar::Bar`, found trait `Bar`")
+        .assert_stderr_contains("different versions of crate `crateA`");
+}