about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOhad Ravid <ohad.rv@gmail.com>2019-06-04 17:22:03 +0200
committerOhad Ravid <ohad.rv@gmail.com>2019-07-09 17:35:30 +0200
commit194814065c5c1763db3cff3ac8d7fc260d0631f5 (patch)
tree9eb97e5f922549075ffc807577daaceb40b803cf
parent97c9437585edafb59dc24701578dc0f20756178c (diff)
downloadrust-194814065c5c1763db3cff3ac8d7fc260d0631f5.tar.gz
rust-194814065c5c1763db3cff3ac8d7fc260d0631f5.zip
Added a test for coherence when a generic type param has a default value from an associated type
-rw-r--r--src/test/run-pass/coherence/auxiliary/re_rebalance_coherence_lib.rs9
-rw-r--r--src/test/run-pass/coherence/re-rebalance-coherence-default-generic-associated-type.rs27
2 files changed, 36 insertions, 0 deletions
diff --git a/src/test/run-pass/coherence/auxiliary/re_rebalance_coherence_lib.rs b/src/test/run-pass/coherence/auxiliary/re_rebalance_coherence_lib.rs
index 41b9d64d5f7..9a191bad8b0 100644
--- a/src/test/run-pass/coherence/auxiliary/re_rebalance_coherence_lib.rs
+++ b/src/test/run-pass/coherence/auxiliary/re_rebalance_coherence_lib.rs
@@ -20,3 +20,12 @@ pub struct BatchInsert<'a, T: 'a, Tab> {
 impl<'a, T:'a, Tab, DB> QueryFragment<DB> for BatchInsert<'a, T, Tab>
 where DB: SupportsDefaultKeyword + Backend,
 {}
+
+pub trait LibToOwned {
+    type Owned;
+}
+
+pub struct LibCow<T: LibToOwned, Owned = <T as LibToOwned>::Owned> {
+    pub t: T,
+    pub o: Owned,
+}
diff --git a/src/test/run-pass/coherence/re-rebalance-coherence-default-generic-associated-type.rs b/src/test/run-pass/coherence/re-rebalance-coherence-default-generic-associated-type.rs
new file mode 100644
index 00000000000..4168b7a6146
--- /dev/null
+++ b/src/test/run-pass/coherence/re-rebalance-coherence-default-generic-associated-type.rs
@@ -0,0 +1,27 @@
+// run-pass
+// aux-build:re_rebalance_coherence_lib.rs
+
+#![allow(dead_code)]
+#![feature(re_rebalance_coherence)]
+// check that a generic type with a default value from an associated type can be used without
+// specifying the value, and without invoking coherence errors.
+
+extern crate re_rebalance_coherence_lib as lib;
+use lib::*;
+
+struct MyString {}
+
+impl LibToOwned for MyString {
+    type Owned = String;
+}
+
+impl PartialEq<MyString> for LibCow<MyString> {
+    fn eq(&self, _other: &MyString) -> bool {
+        // Test that the default type is used.
+        let _s: &String = &self.o;
+
+        false
+    }
+}
+
+fn main() {}