3 #![feature(specialization)]
5 // Test that default methods are cascaded correctly
7 // First, test only use of explicit `default` items:
10 fn foo(&self) -> bool;
13 // Specialization tree for Foo:
20 default fn foo(&self) -> bool { false }
26 fn foo(&self) -> bool { true }
35 // Next, test mixture of explicit `default` and provided methods:
38 fn bar(&self) -> i32 { 0 }
41 // Specialization tree for Bar.
42 // Uses of $ designate that method is provided
59 default fn bar(&self) -> i32 { 0 }
63 fn bar(&self) -> i32 { 1 }
65 impl<'a> Bar for &'a str {}
67 impl<T> Bar for Vec<T> {
68 default fn bar(&self) -> i32 { 2 }
70 impl Bar for Vec<i32> {}
71 impl Bar for Vec<i64> {
72 fn bar(&self) -> i32 { 3 }
76 assert!(0u8.bar() == 0);
77 assert!(0i32.bar() == 1);
78 assert!("hello".bar() == 0);
79 assert!(vec![()].bar() == 2);
80 assert!(vec![0i32].bar() == 2);
81 assert!(vec![0i64].bar() == 3);