3 #![feature(associated_type_bounds)]
7 trait Tr1 { type As1; fn mk(&self) -> Self::As1; }
8 trait Tr2<'a> { fn tr2(self) -> &'a Self; }
10 fn assert_copy<T: Copy>(x: T) { let _x = x; let _x = x; }
11 fn assert_static<T: 'static>(_: T) {}
12 fn assert_forall_tr2<T: for<'a> Tr2<'a>>(_: T) {}
15 #[derive(Copy, Clone)]
17 impl Tr1 for S1 { type As1 = S2; fn mk(&self) -> Self::As1 { S2 } }
19 type Et1 = Box<dyn Tr1<As1: Copy>>;
20 fn def_et1() -> Et1 { Box::new(S1) }
21 pub fn use_et1() { assert_copy(def_et1().mk()); }
23 type Et2 = Box<dyn Tr1<As1: 'static>>;
24 fn def_et2() -> Et2 { Box::new(S1) }
25 pub fn use_et2() { assert_static(def_et2().mk()); }
27 type Et3 = Box<dyn Tr1<As1: Clone + Iterator<Item: Add<u8, Output: Into<u8>>>>>;
31 type As1 = core::ops::Range<u8>;
32 fn mk(&self) -> Self::As1 { 0..10 }
37 let _0 = def_et3().mk().clone();
43 assert_eq!(s, (0..10).map(|x| x + 1).sum());
46 type Et4 = Box<dyn Tr1<As1: for<'a> Tr2<'a>>>;
48 #[derive(Copy, Clone)]
52 fn mk(&self) -> A { A }
54 impl<'a> Tr2<'a> for A {
55 fn tr2(self) -> &'a Self { &A }
59 pub fn use_et4() { assert_forall_tr2(def_et4().mk()); }