diff options
Diffstat (limited to 'tests/ui/specialization/specialization-assoc-fns.rs')
-rw-r--r-- | tests/ui/specialization/specialization-assoc-fns.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/ui/specialization/specialization-assoc-fns.rs b/tests/ui/specialization/specialization-assoc-fns.rs new file mode 100644 index 000000000..cbfcb4719 --- /dev/null +++ b/tests/ui/specialization/specialization-assoc-fns.rs @@ -0,0 +1,29 @@ +// run-pass + +// Test that non-method associated functions can be specialized + +#![feature(specialization)] //~ WARN the feature `specialization` is incomplete + +trait Foo { + fn mk() -> Self; +} + +impl<T: Default> Foo for T { + default fn mk() -> T { + T::default() + } +} + +impl Foo for Vec<u8> { + fn mk() -> Vec<u8> { + vec![0] + } +} + +fn main() { + let v1: Vec<i32> = Foo::mk(); + let v2: Vec<u8> = Foo::mk(); + + assert!(v1.len() == 0); + assert!(v2.len() == 1); +} |