// run-pass trait Foo: Bar + Bar {} trait Bar { fn bar(&self) -> String { T::default().to_string() } } struct S1; impl Bar for S1 {} impl Foo for S1 {} struct S2; impl Bar for S2 {} impl Bar for S2 {} impl Foo for S2 {} fn test1(x: &dyn Foo) { let s = x as &dyn Bar; assert_eq!("0", &s.bar().to_string()); } fn test2(x: &dyn Foo) { let p = x as &dyn Bar; assert_eq!("0", &p.bar().to_string()); let q = x as &dyn Bar; assert_eq!("false", &q.bar().to_string()); } fn main() { let s1 = S1; test1(&s1); let s2 = S2; test2(&s2); }