1 // check-pass 2 3 pub trait Trait1 { 4 type C; 5 } 6 7 struct T1; 8 impl Trait1 for T1 { 9 type C = usize; 10 } 11 pub trait Callback<T: Trait1>: FnMut(<T as Trait1>::C) {} 12 impl<T: Trait1, F: FnMut(<T as Trait1>::C)> Callback<T> for F {} 13 14 pub struct State<T: Trait1> { 15 callback: Option<Box<dyn Callback<T>>>, 16 } 17 impl<T: Trait1> State<T> { new() -> Self18 fn new() -> Self { 19 Self { callback: None } 20 } test_cb(&mut self, d: <T as Trait1>::C)21 fn test_cb(&mut self, d: <T as Trait1>::C) { 22 (self.callback.as_mut().unwrap())(d) 23 } 24 } 25 main()26fn main() { 27 let mut s = State::<T1>::new(); 28 s.test_cb(1); 29 } 30