about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-12-19 11:51:46 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-12-19 11:51:46 +0000
commite62b75ef5f666de561726e44738de63ae4aa7726 (patch)
tree37bc60ff5d59a4f2bb335e543f4113e6ffd95c31
parent10723378900ba2d25fc5d8baf785e1082f385832 (diff)
downloadrust-e62b75ef5f666de561726e44738de63ae4aa7726.tar.gz
rust-e62b75ef5f666de561726e44738de63ae4aa7726.zip
Test that we don't add a new kind of breaking change with TAITs
-rw-r--r--src/test/ui/type-alias-impl-trait/auxiliary/coherence_cross_crate_trait_decl.rs9
-rw-r--r--src/test/ui/type-alias-impl-trait/coherence_cross_crate.rs24
-rw-r--r--src/test/ui/type-alias-impl-trait/coherence_cross_crate.stderr13
3 files changed, 46 insertions, 0 deletions
diff --git a/src/test/ui/type-alias-impl-trait/auxiliary/coherence_cross_crate_trait_decl.rs b/src/test/ui/type-alias-impl-trait/auxiliary/coherence_cross_crate_trait_decl.rs
new file mode 100644
index 00000000000..712ed55438e
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/auxiliary/coherence_cross_crate_trait_decl.rs
@@ -0,0 +1,9 @@
+pub trait SomeTrait {}
+
+impl SomeTrait for () {}
+
+// Adding this `impl` would cause errors in this crate's dependent,
+// so it would be a breaking change. We explicitly don't add this impl,
+// as the dependent crate already assumes this impl exists and thus already
+// does not compile.
+//impl SomeTrait for i32 {}
diff --git a/src/test/ui/type-alias-impl-trait/coherence_cross_crate.rs b/src/test/ui/type-alias-impl-trait/coherence_cross_crate.rs
new file mode 100644
index 00000000000..a63e0a1ee6f
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/coherence_cross_crate.rs
@@ -0,0 +1,24 @@
+// aux-build: coherence_cross_crate_trait_decl.rs
+// This test ensures that adding an `impl SomeTrait for i32` within
+// `coherence_cross_crate_trait_decl` is not a breaking change, by
+// making sure that even without such an impl this test fails to compile.
+
+#![feature(type_alias_impl_trait)]
+
+extern crate coherence_cross_crate_trait_decl;
+
+use coherence_cross_crate_trait_decl::SomeTrait;
+
+trait OtherTrait {}
+
+type Alias = impl SomeTrait;
+
+fn constrain() -> Alias {
+    ()
+}
+
+impl OtherTrait for Alias {}
+impl OtherTrait for i32 {}
+//~^ ERROR: conflicting implementations of trait `OtherTrait` for type `Alias`
+
+fn main() {}
diff --git a/src/test/ui/type-alias-impl-trait/coherence_cross_crate.stderr b/src/test/ui/type-alias-impl-trait/coherence_cross_crate.stderr
new file mode 100644
index 00000000000..63a3ce29cc7
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/coherence_cross_crate.stderr
@@ -0,0 +1,13 @@
+error[E0119]: conflicting implementations of trait `OtherTrait` for type `Alias`
+  --> $DIR/coherence_cross_crate.rs:21:1
+   |
+LL | impl OtherTrait for Alias {}
+   | ------------------------- first implementation here
+LL | impl OtherTrait for i32 {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Alias`
+   |
+   = note: upstream crates may add a new impl of trait `coherence_cross_crate_trait_decl::SomeTrait` for type `i32` in future versions
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0119`.