Implement trait inheritance for bounded type parameters
This commit is contained in:
parent
daa89e0861
commit
78ee821154
38 changed files with 1004 additions and 176 deletions
18
src/test/run-pass/trait-inheritance-call-bound-inherited.rs
Normal file
18
src/test/run-pass/trait-inheritance-call-bound-inherited.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
trait Foo { fn f() -> int; }
|
||||
trait Bar : Foo { fn g() -> int; }
|
||||
|
||||
struct A { x: int }
|
||||
|
||||
impl A : Foo { fn f() -> int { 10 } }
|
||||
impl A : Bar { fn g() -> int { 20 } }
|
||||
|
||||
// Call a function on Foo, given a T: Bar
|
||||
fn gg<T:Bar>(a: &T) -> int {
|
||||
a.f()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let a = &A { x: 3 };
|
||||
assert gg(a) == 10;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue