about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJonas Schievink <jonasschievink@gmail.com>2019-06-13 22:03:42 +0200
committerJonas Schievink <jonasschievink@gmail.com>2020-02-21 19:41:21 +0100
commita549bbdc3230b44d18d8828610053c521fe95d9e (patch)
tree08dcf7b1e6311a9936237fd81808c42cbbc22be3
parenta323ff2c864801fdc8e044e88f11efb49a565ed1 (diff)
downloadrust-a549bbdc3230b44d18d8828610053c521fe95d9e.tar.gz
rust-a549bbdc3230b44d18d8828610053c521fe95d9e.zip
Add regression test for #54182
-rw-r--r--src/test/ui/associated-types/issue-54182-1.rs79
-rw-r--r--src/test/ui/associated-types/issue-54182-2.rs15
2 files changed, 94 insertions, 0 deletions
diff --git a/src/test/ui/associated-types/issue-54182-1.rs b/src/test/ui/associated-types/issue-54182-1.rs
new file mode 100644
index 00000000000..bfbf7ed1f22
--- /dev/null
+++ b/src/test/ui/associated-types/issue-54182-1.rs
@@ -0,0 +1,79 @@
+// run-pass
+
+#![feature(associated_type_defaults)]
+
+macro_rules! overload {
+    ($a:expr, $b:expr) => {
+        overload::overload2($a, $b)
+    };
+    ($a:expr, $b:expr, $c:expr) => {
+        overload::overload3($a, $b, $c)
+    }
+}
+
+fn main() {
+    let r = overload!(42, true);
+    println!("-> {:?}", r);
+
+    let r = overload!("Hello world", 13.0);
+    println!("-> {:?}", r);
+
+    let r = overload!(42, true, 42.5);
+    println!("-> {:?}", r);
+
+    let r = overload!("Hello world", 13.0, 42);
+    println!("-> {:?}", r);
+}
+
+mod overload {
+    pub trait Overload {
+        // type R;
+        type R = ();
+        fn overload(self) -> Self::R;
+    }
+
+    // overloads for 2 args
+    impl Overload for (i32, bool) {
+        // type R = ();
+        fn overload(self) /*-> Self::R*/ {
+            let (a, b) = self; // destructure args
+            println!("i32 and bool {:?}", (a, b));
+        }
+    }
+    impl<'a> Overload for (&'a str, f32) {
+        type R = f32;
+        fn overload(self) -> Self::R {
+            let (a, b) = self; // destructure args
+            println!("&str and f32 {:?}", (a, b));
+            b
+        }
+    }
+
+    // overloads for 3 args
+    impl Overload for (i32, bool, f32) {
+        // type R = ();
+        fn overload(self) /*-> Self::R*/ {
+            let (a, b, c) = self; // destructure args
+            println!("i32 and bool and f32 {:?}", (a, b, c));
+        }
+    }
+    impl<'a> Overload for (&'a str, f32, i32) {
+        type R = i32;
+        fn overload(self) -> Self::R {
+            let (a, b, c) = self; // destructure args
+            println!("&str and f32 and i32: {:?}", (a, b, c));
+            c
+        }
+    }
+
+    // overloads for more args
+    // ...
+
+    pub fn overload2<R, A, B>(a: A, b: B) -> R where (A, B): Overload<R = R> {
+        (a, b).overload()
+    }
+
+    pub fn overload3<R, A, B, C>(a: A, b: B, c: C) -> R where (A, B, C): Overload<R = R> {
+        (a, b, c).overload()
+    }
+}
diff --git a/src/test/ui/associated-types/issue-54182-2.rs b/src/test/ui/associated-types/issue-54182-2.rs
new file mode 100644
index 00000000000..cba1b1b3ca6
--- /dev/null
+++ b/src/test/ui/associated-types/issue-54182-2.rs
@@ -0,0 +1,15 @@
+// compile-pass
+
+#![feature(associated_type_defaults)]
+
+trait Tr {
+    type Assoc = ();
+}
+
+impl Tr for () {}
+
+fn f(thing: <() as Tr>::Assoc) {
+    let c: () = thing;
+}
+
+fn main() {}