2 // Check that a trait is still object-safe (and usable) if it has
3 // methods that return `Self` so long as they require `Self : Sized`.
7 fn new() -> Self where Self : Sized;
8 fn tick(&mut self) -> u32;
15 impl Counter for CCounter {
16 fn new() -> CCounter { CCounter { c: 0 } }
17 fn tick(&mut self) -> u32 { self.c += 1; self.c }
20 fn preticked<C:Counter>() -> C {
21 let mut c: C = Counter::new();
26 fn tick(c: &mut dyn Counter) {
30 fn tick_generic<C:?Sized+Counter>(c: &mut C) {
36 let mut c = preticked::<CCounter>();
38 assert_eq!(c.tick(), 5);