about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHameer Abbasi <einstein.edison@gmail.com>2020-10-28 10:36:19 +0000
committerHameer Abbasi <einstein.edison@gmail.com>2020-10-28 10:36:19 +0000
commit9e60f4511e39d012d5a21c10c55d706ec1e75e53 (patch)
treebe2c886b2e01adc57b3900161e9126f18cd2b4a6
parent2eb4fc800aaf5006f89af3af591e2aa34f469d81 (diff)
downloadrust-9e60f4511e39d012d5a21c10c55d706ec1e75e53.tar.gz
rust-9e60f4511e39d012d5a21c10c55d706ec1e75e53.zip
Add const generics tests for supertraits + dyn traits.
-rw-r--r--src/test/ui/const-generics/dyn-supertraits.rs58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/test/ui/const-generics/dyn-supertraits.rs b/src/test/ui/const-generics/dyn-supertraits.rs
new file mode 100644
index 00000000000..b72dd9cc90c
--- /dev/null
+++ b/src/test/ui/const-generics/dyn-supertraits.rs
@@ -0,0 +1,58 @@
+// check-pass
+// revisions: full min
+
+#![cfg_attr(full, feature(const_generics))]
+#![cfg_attr(full, allow(incomplete_features))]
+#![cfg_attr(min, feature(min_const_generics))]
+
+trait Foo<const N: usize> {}
+trait Bar<const N: usize> : Foo<N> {}
+trait Baz: Foo<3> {}
+
+struct FooType<const N: usize> {}
+struct BarType<const N: usize> {}
+struct BazType {}
+
+impl<const N: usize> Foo<N> for FooType<N> {}
+impl<const N: usize> Foo<N> for BarType<N> {}
+impl<const N: usize> Bar<N> for BarType<N> {}
+impl Foo<3> for BazType {}
+impl Baz for BazType {}
+
+trait Foz {}
+trait Boz: Foo<3> + Foz {}
+trait Bok<const N: usize>: Foo<N> + Foz {}
+
+struct FozType {}
+struct BozType {}
+struct BokType<const N: usize> {}
+
+impl Foz for FozType {}
+
+impl Foz for BozType {}
+impl Foo<3> for BozType {}
+impl Boz for BozType {}
+
+impl<const N: usize> Foz for BokType<N> {}
+impl<const N: usize> Foo<N> for BokType<N> {}
+impl<const N: usize> Bok<N> for BokType<N> {}
+
+fn a<const N: usize>(x: &dyn Foo<N>) {}
+fn b(x: &dyn Foo<3>) {}
+
+fn main() {
+    let foo = FooType::<3> {};
+    a(&foo); b(&foo);
+
+    let bar = BarType::<3> {};
+    a(&bar); b(&bar);
+
+    let baz = BazType {};
+    a(&baz); b(&baz);
+
+    let boz = BozType {};
+    a(&boz); b(&boz);
+
+    let bok = BokType::<3> {};
+    a(&bok); b(&bok);
+}