From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- src/test/ui/const-generics/dyn-supertraits.rs | 80 +++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/test/ui/const-generics/dyn-supertraits.rs (limited to 'src/test/ui/const-generics/dyn-supertraits.rs') 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 000000000..3dee326a1 --- /dev/null +++ b/src/test/ui/const-generics/dyn-supertraits.rs @@ -0,0 +1,80 @@ +// run-pass + +trait Foo { + fn myfun(&self) -> usize; +} +trait Bar : Foo {} +trait Baz: Foo<3> {} + +struct FooType; +struct BarType; +struct BazType; + +impl Foo for FooType { + fn myfun(&self) -> usize { N } +} +impl Foo for BarType { + fn myfun(&self) -> usize { N + 1 } +} +impl Bar for BarType {} +impl Foo<3> for BazType { + fn myfun(&self) -> usize { 999 } +} +impl Baz for BazType {} + +trait Foz {} +trait Boz: Foo<3> + Foz {} +trait Bok: Foo + Foz {} + +struct FozType; +struct BozType; +struct BokType; + +impl Foz for FozType {} + +impl Foz for BozType {} +impl Foo<3> for BozType { + fn myfun(&self) -> usize { 9999 } +} +impl Boz for BozType {} + +impl Foz for BokType {} +impl Foo for BokType { + fn myfun(&self) -> usize { N + 2 } +} +impl Bok for BokType {} + +fn a(x: &dyn Foo) -> usize { x.myfun() } +fn b(x: &dyn Foo<3>) -> usize { x.myfun() } +fn c, const N: usize>(x: T) -> usize { a::(&x) } +fn d>(x: &T) -> usize { x.myfun() } +fn e(x: &dyn Bar<3>) -> usize { d(x) } + +fn main() { + let foo = FooType::<3> {}; + assert!(a(&foo) == 3); + assert!(b(&foo) == 3); + assert!(d(&foo) == 3); + + let bar = BarType::<3> {}; + assert!(a(&bar) == 4); + assert!(b(&bar) == 4); + assert!(d(&bar) == 4); + assert!(e(&bar) == 4); + + let baz = BazType {}; + assert!(a(&baz) == 999); + assert!(b(&baz) == 999); + assert!(d(&baz) == 999); + + let boz = BozType {}; + assert!(a(&boz) == 9999); + assert!(b(&boz) == 9999); + assert!(d(&boz) == 9999); + + let bok = BokType::<3> {}; + assert!(a(&bok) == 5); + assert!(b(&bok) == 5); + assert!(d(&bok) == 5); + assert!(c(BokType::<3> {}) == 5); +} -- cgit v1.2.3