]>
git.proxmox.com Git - rustc.git/blob - src/test/run-pass/specialization/specialization-default-methods.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![feature(specialization)]
13 // Test that default methods are cascaded correctly
15 // First, test only use of explicit `default` items:
18 fn foo(&self) -> bool
;
21 // Specialization tree for Foo:
28 default fn foo(&self) -> bool { false }
34 fn foo(&self) -> bool { true }
43 // Next, test mixture of explicit `default` and provided methods:
46 fn bar(&self) -> i32 { 0 }
49 // Specialization tree for Bar.
50 // Uses of $ designate that method is provided
66 // use the provided method
70 fn bar(&self) -> i32 { 1 }
72 impl<'a
> Bar
for &'a
str {}
74 impl<T
> Bar
for Vec
<T
> {
75 default fn bar(&self) -> i32 { 2 }
77 impl Bar
for Vec
<i32> {}
78 impl Bar
for Vec
<i64> {
79 fn bar(&self) -> i32 { 3 }
83 assert
!(0u8.bar() == 0);
84 assert
!(0i32.bar() == 1);
85 assert
!("hello".bar() == 0);
86 assert
!(vec
![()].bar() == 2);
87 assert
!(vec
![0i32].bar() == 2);
88 assert
!(vec
![0i64].bar() == 3);