4 #![cfg_attr(full, feature(const_generics))]
5 #![cfg_attr(full, allow(incomplete_features))]
6 #![cfg_attr(min, feature(min_const_generics))]
8 trait Foo<const N: usize> {
9 fn myfun(&self) -> usize;
11 trait Bar<const N: usize> : Foo<N> {}
14 struct FooType<const N: usize>;
15 struct BarType<const N: usize>;
18 impl<const N: usize> Foo<N> for FooType<N> {
19 fn myfun(&self) -> usize { N }
21 impl<const N: usize> Foo<N> for BarType<N> {
22 fn myfun(&self) -> usize { N + 1 }
24 impl<const N: usize> Bar<N> for BarType<N> {}
25 impl Foo<3> for BazType {
26 fn myfun(&self) -> usize { 999 }
28 impl Baz for BazType {}
31 trait Boz: Foo<3> + Foz {}
32 trait Bok<const N: usize>: Foo<N> + Foz {}
36 struct BokType<const N: usize>;
38 impl Foz for FozType {}
40 impl Foz for BozType {}
41 impl Foo<3> for BozType {
42 fn myfun(&self) -> usize { 9999 }
44 impl Boz for BozType {}
46 impl<const N: usize> Foz for BokType<N> {}
47 impl<const N: usize> Foo<N> for BokType<N> {
48 fn myfun(&self) -> usize { N + 2 }
50 impl<const N: usize> Bok<N> for BokType<N> {}
52 fn a<const N: usize>(x: &dyn Foo<N>) -> usize { x.myfun() }
53 fn b(x: &dyn Foo<3>) -> usize { x.myfun() }
54 fn c<T: Bok<N>, const N: usize>(x: T) -> usize { a::<N>(&x) }
55 fn d<T: ?Sized + Foo<3>>(x: &T) -> usize { x.myfun() }
56 fn e(x: &dyn Bar<3>) -> usize { d(x) }
59 let foo = FooType::<3> {};
60 assert!(a(&foo) == 3);
61 assert!(b(&foo) == 3);
62 assert!(d(&foo) == 3);
64 let bar = BarType::<3> {};
65 assert!(a(&bar) == 4);
66 assert!(b(&bar) == 4);
67 assert!(d(&bar) == 4);
68 assert!(e(&bar) == 4);
71 assert!(a(&baz) == 999);
72 assert!(b(&baz) == 999);
73 assert!(d(&baz) == 999);
76 assert!(a(&boz) == 9999);
77 assert!(b(&boz) == 9999);
78 assert!(d(&boz) == 9999);
80 let bok = BokType::<3> {};
81 assert!(a(&bok) == 5);
82 assert!(b(&bok) == 5);
83 assert!(d(&bok) == 5);
84 assert!(c(BokType::<3> {}) == 5);