diff options
| author | Hameer Abbasi <einstein.edison@gmail.com> | 2020-10-28 12:29:13 +0000 | 
|---|---|---|
| committer | Hameer Abbasi <einstein.edison@gmail.com> | 2020-10-28 12:29:13 +0000 | 
| commit | fab79c27ef184ee3620681bfbdc1fd89ad10b4df (patch) | |
| tree | 3257c47b2e6b91da1ecf3a1cd4aade45297669c5 | |
| parent | 9e60f4511e39d012d5a21c10c55d706ec1e75e53 (diff) | |
| download | rust-fab79c27ef184ee3620681bfbdc1fd89ad10b4df.tar.gz rust-fab79c27ef184ee3620681bfbdc1fd89ad10b4df.zip  | |
Extend test to cover dyn methods/functions.
| -rw-r--r-- | src/test/ui/const-generics/dyn-supertraits.rs | 64 | 
1 files changed, 44 insertions, 20 deletions
diff --git a/src/test/ui/const-generics/dyn-supertraits.rs b/src/test/ui/const-generics/dyn-supertraits.rs index b72dd9cc90c..8b956988c7c 100644 --- a/src/test/ui/const-generics/dyn-supertraits.rs +++ b/src/test/ui/const-generics/dyn-supertraits.rs @@ -1,58 +1,82 @@ -// check-pass +// run-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 Foo<const N: usize> { + fn myfun(&self) -> usize; +} trait Bar<const N: usize> : Foo<N> {} trait Baz: Foo<3> {} -struct FooType<const N: usize> {} -struct BarType<const N: usize> {} -struct BazType {} +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> Foo<N> for FooType<N> { + fn myfun(&self) -> usize { N } +} +impl<const N: usize> Foo<N> for BarType<N> { + fn myfun(&self) -> usize { N + 1 } +} impl<const N: usize> Bar<N> for BarType<N> {} -impl Foo<3> for BazType {} +impl Foo<3> for BazType { + fn myfun(&self) -> usize { 999 } +} 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> {} +struct FozType; +struct BozType; +struct BokType<const N: usize>; impl Foz for FozType {} impl Foz for BozType {} -impl Foo<3> for BozType {} +impl Foo<3> for BozType { + fn myfun(&self) -> usize { 9999 } +} 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> Foo<N> for BokType<N> { + fn myfun(&self) -> usize { N + 2 } +} 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 a<const N: usize>(_: &dyn Foo<N>) {} +fn b(_: &dyn Foo<3>) {} +fn c<T: Bok<N>, const N: usize>(x: T) { a::<N>(&x); } +fn d<T: ?Sized + Foo<3>>(_: &T) {} +fn e(x: &dyn Bar<3>) { d(x); } + +fn get_myfun<const N: usize>(x: &dyn Foo<N>) -> usize { x.myfun() } fn main() { let foo = FooType::<3> {}; - a(&foo); b(&foo); + a(&foo); b(&foo); d(&foo); + assert!(get_myfun(&foo) == 3); let bar = BarType::<3> {}; - a(&bar); b(&bar); + a(&bar); b(&bar); d(&bar); e(&bar); + assert!(get_myfun(&bar) == 4); let baz = BazType {}; - a(&baz); b(&baz); + a(&baz); b(&baz); d(&baz); + assert!(get_myfun(&baz) == 999); let boz = BozType {}; - a(&boz); b(&boz); + a(&boz); b(&boz); d(&boz); + assert!(get_myfun(&boz) == 9999); let bok = BokType::<3> {}; - a(&bok); b(&bok); + a(&bok); b(&bok); d(&bok); + assert!(get_myfun(&bok) == 5); + + c(BokType::<3> {}); }  | 
