3 #![feature(associated_type_bounds)]
4 #![feature(impl_trait_in_bindings)]
5 //~^ WARNING `impl_trait_in_bindings` is incomplete
6 #![allow(non_upper_case_globals)]
10 trait Tr1 { type As1; fn mk(&self) -> Self::As1; }
11 trait Tr2<'a> { fn tr2(self) -> &'a Self; }
13 fn assert_copy<T: Copy>(x: T) { let _x = x; let _x = x; }
14 fn assert_static<T: 'static>(_: T) {}
15 fn assert_forall_tr2<T: for<'a> Tr2<'a>>(_: T) {}
17 #[derive(Copy, Clone)]
19 #[derive(Copy, Clone)]
21 impl Tr1 for S1 { type As1 = S2; fn mk(&self) -> Self::As1 { S2 } }
23 const cdef_et1: &dyn Tr1<As1: Copy> = &S1;
24 const sdef_et1: &dyn Tr1<As1: Copy> = &S1;
25 pub fn use_et1() { assert_copy(cdef_et1.mk()); assert_copy(sdef_et1.mk()); }
27 const cdef_et2: &(dyn Tr1<As1: 'static> + Sync) = &S1;
28 static sdef_et2: &(dyn Tr1<As1: 'static> + Sync) = &S1;
29 pub fn use_et2() { assert_static(cdef_et2.mk()); assert_static(sdef_et2.mk()); }
31 const cdef_et3: &dyn Tr1<As1: Clone + Iterator<Item: Add<u8, Output: Into<u8>>>> = {
34 type As1 = core::ops::Range<u8>;
35 fn mk(&self) -> Self::As1 { 0..10 }
40 let _0 = cdef_et3.mk().clone();
46 assert_eq!(s, (0..10).map(|x| x + 1).sum());
49 const cdef_et4: &(dyn Tr1<As1: for<'a> Tr2<'a>> + Sync) = {
50 #[derive(Copy, Clone)]
54 fn mk(&self) -> A { A }
56 impl<'a> Tr2<'a> for A {
57 fn tr2(self) -> &'a Self { &A }
61 static sdef_et4: &(dyn Tr1<As1: for<'a> Tr2<'a>> + Sync) = cdef_et4;
62 pub fn use_et4() { assert_forall_tr2(cdef_et4.mk()); assert_forall_tr2(sdef_et4.mk()); }