1 #![feature(generic_associated_types)] 2 3 pub trait SubTrait {} 4 5 pub trait SuperTrait { 6 type SubType<'a>: SubTrait where Self: 'a; 7 get_sub<'a>(&'a mut self) -> Self::SubType<'a>8 fn get_sub<'a>(&'a mut self) -> Self::SubType<'a>; 9 } 10 11 pub struct SubStruct<'a> { 12 sup: &'a mut SuperStruct, 13 } 14 15 impl<'a> SubTrait for SubStruct<'a> {} 16 17 pub struct SuperStruct { 18 value: u8, 19 } 20 21 impl SuperStruct { new(value: u8) -> SuperStruct22 pub fn new(value: u8) -> SuperStruct { 23 SuperStruct { value } 24 } 25 } 26 27 impl SuperTrait for SuperStruct { 28 type SubType<'a> = SubStruct<'a>; 29 get_sub<'a>(&'a mut self) -> Self::SubType<'a>30 fn get_sub<'a>(&'a mut self) -> Self::SubType<'a> { 31 SubStruct { sup: self } 32 } 33 } 34 main()35fn main() { 36 let sub: Box<dyn SuperTrait<SubType = SubStruct>> = Box::new(SuperStruct::new(0)); 37 //~^ ERROR missing generics for associated type 38 //~^^ ERROR the trait 39 //~| ERROR the trait 40 } 41