about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJulian Wollersberger <julian.wollersberger@gmx.at>2020-11-28 19:44:31 +0100
committerJulian Wollersberger <julian.wollersberger@gmx.at>2020-11-28 19:44:31 +0100
commit1fa43257ebb2ad0e5681b2cdcfc4d7d79ede770f (patch)
treeea1690663f752cd4bfb6fba2c080651ed6830b14 /src
parent4ae328bef47dffcbf363e5ae873f419c06a5511d (diff)
downloadrust-1fa43257ebb2ad0e5681b2cdcfc4d7d79ede770f.tar.gz
rust-1fa43257ebb2ad0e5681b2cdcfc4d7d79ede770f.zip
Add test for issue #54121:
"simple type inference fails depending on order of trait bounds"
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/associated-type-bounds/order-dependent-bounds-issue-54121.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/test/ui/associated-type-bounds/order-dependent-bounds-issue-54121.rs b/src/test/ui/associated-type-bounds/order-dependent-bounds-issue-54121.rs
new file mode 100644
index 00000000000..77e4bd4d6f5
--- /dev/null
+++ b/src/test/ui/associated-type-bounds/order-dependent-bounds-issue-54121.rs
@@ -0,0 +1,47 @@
+// check-pass
+
+// From https://github.com/rust-lang/rust/issues/54121/
+//
+// Whether the code compiled depended on the order of the trait bounds in
+// `type T: Tr<u8, u8> + Tr<u16, u16>`
+// But both should compile as order shouldn't matter.
+
+trait Tr<A, B> {
+    fn exec(a: A, b: B);
+}
+
+trait P {
+    // This compiled successfully
+    type T: Tr<u16, u16> + Tr<u8, u8>;
+}
+
+trait Q {
+    // This didn't compile
+    type T: Tr<u8, u8> + Tr<u16, u16>;
+}
+
+#[allow(dead_code)]
+fn f<S: P>() {
+    <S as P>::T::exec(0u8, 0u8)
+}
+
+#[allow(dead_code)]
+fn g<S: Q>() {
+    // A mismatched types error was emitted on this line.
+    <S as Q>::T::exec(0u8, 0u8)
+}
+
+// Another reproduction of the same issue
+trait Trait {
+    type Type: Into<Self::Type1> + Into<Self::Type2> + Copy;
+    type Type1;
+    type Type2;
+}
+
+#[allow(dead_code)]
+fn foo<T: Trait>(x: T::Type) {
+    let _1: T::Type1 = x.into();
+    let _2: T::Type2 = x.into();
+}
+
+fn main() { }