|
1 |
| -// check-pass |
| 1 | +// run-pass |
2 | 2 | // revisions: full min
|
3 | 3 |
|
4 | 4 | #![cfg_attr(full, feature(const_generics))]
|
5 | 5 | #![cfg_attr(full, allow(incomplete_features))]
|
6 | 6 | #![cfg_attr(min, feature(min_const_generics))]
|
7 | 7 |
|
8 |
| -trait Foo<const N: usize> {} |
| 8 | +trait Foo<const N: usize> { |
| 9 | + fn myfun(&self) -> usize; |
| 10 | +} |
9 | 11 | trait Bar<const N: usize> : Foo<N> {}
|
10 | 12 | trait Baz: Foo<3> {}
|
11 | 13 |
|
12 |
| -struct FooType<const N: usize> {} |
13 |
| -struct BarType<const N: usize> {} |
14 |
| -struct BazType {} |
| 14 | +struct FooType<const N: usize>; |
| 15 | +struct BarType<const N: usize>; |
| 16 | +struct BazType; |
15 | 17 |
|
16 |
| -impl<const N: usize> Foo<N> for FooType<N> {} |
17 |
| -impl<const N: usize> Foo<N> for BarType<N> {} |
| 18 | +impl<const N: usize> Foo<N> for FooType<N> { |
| 19 | + fn myfun(&self) -> usize { N } |
| 20 | +} |
| 21 | +impl<const N: usize> Foo<N> for BarType<N> { |
| 22 | + fn myfun(&self) -> usize { N + 1 } |
| 23 | +} |
18 | 24 | impl<const N: usize> Bar<N> for BarType<N> {}
|
19 |
| -impl Foo<3> for BazType {} |
| 25 | +impl Foo<3> for BazType { |
| 26 | + fn myfun(&self) -> usize { 999 } |
| 27 | +} |
20 | 28 | impl Baz for BazType {}
|
21 | 29 |
|
22 | 30 | trait Foz {}
|
23 | 31 | trait Boz: Foo<3> + Foz {}
|
24 | 32 | trait Bok<const N: usize>: Foo<N> + Foz {}
|
25 | 33 |
|
26 |
| -struct FozType {} |
27 |
| -struct BozType {} |
28 |
| -struct BokType<const N: usize> {} |
| 34 | +struct FozType; |
| 35 | +struct BozType; |
| 36 | +struct BokType<const N: usize>; |
29 | 37 |
|
30 | 38 | impl Foz for FozType {}
|
31 | 39 |
|
32 | 40 | impl Foz for BozType {}
|
33 |
| -impl Foo<3> for BozType {} |
| 41 | +impl Foo<3> for BozType { |
| 42 | + fn myfun(&self) -> usize { 9999 } |
| 43 | +} |
34 | 44 | impl Boz for BozType {}
|
35 | 45 |
|
36 | 46 | impl<const N: usize> Foz for BokType<N> {}
|
37 |
| -impl<const N: usize> Foo<N> for BokType<N> {} |
| 47 | +impl<const N: usize> Foo<N> for BokType<N> { |
| 48 | + fn myfun(&self) -> usize { N + 2 } |
| 49 | +} |
38 | 50 | impl<const N: usize> Bok<N> for BokType<N> {}
|
39 | 51 |
|
40 |
| -fn a<const N: usize>(x: &dyn Foo<N>) {} |
41 |
| -fn b(x: &dyn Foo<3>) {} |
| 52 | +fn a<const N: usize>(_: &dyn Foo<N>) {} |
| 53 | +fn b(_: &dyn Foo<3>) {} |
| 54 | +fn c<T: Bok<N>, const N: usize>(x: T) { a::<N>(&x); } |
| 55 | +fn d<T: ?Sized + Foo<3>>(_: &T) {} |
| 56 | +fn e(x: &dyn Bar<3>) { d(x); } |
| 57 | + |
| 58 | +fn get_myfun<const N: usize>(x: &dyn Foo<N>) -> usize { x.myfun() } |
42 | 59 |
|
43 | 60 | fn main() {
|
44 | 61 | let foo = FooType::<3> {};
|
45 |
| - a(&foo); b(&foo); |
| 62 | + a(&foo); b(&foo); d(&foo); |
| 63 | + assert!(get_myfun(&foo) == 3); |
46 | 64 |
|
47 | 65 | let bar = BarType::<3> {};
|
48 |
| - a(&bar); b(&bar); |
| 66 | + a(&bar); b(&bar); d(&bar); e(&bar); |
| 67 | + assert!(get_myfun(&bar) == 4); |
49 | 68 |
|
50 | 69 | let baz = BazType {};
|
51 |
| - a(&baz); b(&baz); |
| 70 | + a(&baz); b(&baz); d(&baz); |
| 71 | + assert!(get_myfun(&baz) == 999); |
52 | 72 |
|
53 | 73 | let boz = BozType {};
|
54 |
| - a(&boz); b(&boz); |
| 74 | + a(&boz); b(&boz); d(&boz); |
| 75 | + assert!(get_myfun(&boz) == 9999); |
55 | 76 |
|
56 | 77 | let bok = BokType::<3> {};
|
57 |
| - a(&bok); b(&bok); |
| 78 | + a(&bok); b(&bok); d(&bok); |
| 79 | + assert!(get_myfun(&bok) == 5); |
| 80 | + |
| 81 | + c(BokType::<3> {}); |
58 | 82 | }
|
0 commit comments