Skip to content

Commit fab79c2

Browse files
committed
Extend test to cover dyn methods/functions.
1 parent 9e60f45 commit fab79c2

File tree

1 file changed

+44
-20
lines changed

1 file changed

+44
-20
lines changed
+44-20
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,82 @@
1-
// check-pass
1+
// run-pass
22
// revisions: full min
33

44
#![cfg_attr(full, feature(const_generics))]
55
#![cfg_attr(full, allow(incomplete_features))]
66
#![cfg_attr(min, feature(min_const_generics))]
77

8-
trait Foo<const N: usize> {}
8+
trait Foo<const N: usize> {
9+
fn myfun(&self) -> usize;
10+
}
911
trait Bar<const N: usize> : Foo<N> {}
1012
trait Baz: Foo<3> {}
1113

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;
1517

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+
}
1824
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+
}
2028
impl Baz for BazType {}
2129

2230
trait Foz {}
2331
trait Boz: Foo<3> + Foz {}
2432
trait Bok<const N: usize>: Foo<N> + Foz {}
2533

26-
struct FozType {}
27-
struct BozType {}
28-
struct BokType<const N: usize> {}
34+
struct FozType;
35+
struct BozType;
36+
struct BokType<const N: usize>;
2937

3038
impl Foz for FozType {}
3139

3240
impl Foz for BozType {}
33-
impl Foo<3> for BozType {}
41+
impl Foo<3> for BozType {
42+
fn myfun(&self) -> usize { 9999 }
43+
}
3444
impl Boz for BozType {}
3545

3646
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+
}
3850
impl<const N: usize> Bok<N> for BokType<N> {}
3951

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() }
4259

4360
fn main() {
4461
let foo = FooType::<3> {};
45-
a(&foo); b(&foo);
62+
a(&foo); b(&foo); d(&foo);
63+
assert!(get_myfun(&foo) == 3);
4664

4765
let bar = BarType::<3> {};
48-
a(&bar); b(&bar);
66+
a(&bar); b(&bar); d(&bar); e(&bar);
67+
assert!(get_myfun(&bar) == 4);
4968

5069
let baz = BazType {};
51-
a(&baz); b(&baz);
70+
a(&baz); b(&baz); d(&baz);
71+
assert!(get_myfun(&baz) == 999);
5272

5373
let boz = BozType {};
54-
a(&boz); b(&boz);
74+
a(&boz); b(&boz); d(&boz);
75+
assert!(get_myfun(&boz) == 9999);
5576

5677
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> {});
5882
}

0 commit comments

Comments
 (0)