summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs4
-rw-r--r--tests/run-make/crate-loading-crate-depends-on-itself/foo-current.rs14
-rw-r--r--tests/run-make/crate-loading-crate-depends-on-itself/foo-prev.rs6
-rw-r--r--tests/run-make/crate-loading-crate-depends-on-itself/rmake.rs32
4 files changed, 56 insertions, 0 deletions
diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs
index 4e7d7b79ff4..20cef5e06a4 100644
--- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs
+++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs
@@ -1732,6 +1732,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
             span.push_span_label(self.tcx.def_span(trait_def_id), "this is the required trait");
             for (sp, label) in [trait_def_id, other_trait_def_id]
                 .iter()
+                // The current crate-version might depend on another version of the same crate
+                // (Think "semver-trick"). Do not call `extern_crate` in that case for the local
+                // crate as that doesn't make sense and ICEs (#133563).
+                .filter(|def_id| !def_id.is_local())
                 .filter_map(|def_id| self.tcx.extern_crate(def_id.krate))
                 .map(|data| {
                     let dependency = if data.dependency_of == LOCAL_CRATE {
diff --git a/tests/run-make/crate-loading-crate-depends-on-itself/foo-current.rs b/tests/run-make/crate-loading-crate-depends-on-itself/foo-current.rs
new file mode 100644
index 00000000000..71b27cd85bf
--- /dev/null
+++ b/tests/run-make/crate-loading-crate-depends-on-itself/foo-current.rs
@@ -0,0 +1,14 @@
+#![crate_type = "lib"]
+#![crate_name = "foo"]
+
+extern crate foo;
+
+pub struct Struct;
+pub trait Trait {}
+impl Trait for Struct {}
+
+fn check_trait<T: Trait>() {}
+
+fn ice() {
+    check_trait::<foo::Struct>();
+}
diff --git a/tests/run-make/crate-loading-crate-depends-on-itself/foo-prev.rs b/tests/run-make/crate-loading-crate-depends-on-itself/foo-prev.rs
new file mode 100644
index 00000000000..19d3f3c972b
--- /dev/null
+++ b/tests/run-make/crate-loading-crate-depends-on-itself/foo-prev.rs
@@ -0,0 +1,6 @@
+#![crate_type = "lib"]
+#![crate_name = "foo"]
+
+pub struct Struct;
+pub trait Trait {}
+impl Trait for Struct {}
diff --git a/tests/run-make/crate-loading-crate-depends-on-itself/rmake.rs b/tests/run-make/crate-loading-crate-depends-on-itself/rmake.rs
new file mode 100644
index 00000000000..f52f3d791a7
--- /dev/null
+++ b/tests/run-make/crate-loading-crate-depends-on-itself/rmake.rs
@@ -0,0 +1,32 @@
+//@ only-linux
+//@ ignore-wasm32
+//@ ignore-wasm64
+// ignore-tidy-linelength
+
+// Verify that if the current crate depends on a different version of the same crate, *and* types
+// and traits of the different versions are mixed, we produce diagnostic output and not an ICE.
+// #133563
+
+use run_make_support::{rust_lib_name, rustc};
+
+fn main() {
+    rustc().input("foo-prev.rs").run();
+
+    rustc()
+        .extra_filename("current")
+        .metadata("current")
+        .input("foo-current.rs")
+        .extern_("foo", rust_lib_name("foo"))
+        .run_fail()
+        .assert_stderr_contains(r#"
+note: there are multiple different versions of crate `foo` in the dependency graph
+  --> foo-current.rs:7:1
+   |
+4  | extern crate foo;
+   | ----------------- one version of crate `foo` is used here, as a direct dependency of the current crate
+5  |
+6  | pub struct Struct;
+   | ----------------- this type implements the required trait
+7  | pub trait Trait {}
+   | ^^^^^^^^^^^^^^^ this is the required trait"#);
+}