2014-02-05 16:33:10 -06:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2012-12-14 21:12:29 -06:00
|
|
|
trait Foo<T> {
|
|
|
|
fn f(&self, x: &T);
|
|
|
|
}
|
|
|
|
|
2013-01-30 21:42:06 -06:00
|
|
|
trait Bar : Foo<Self> {
|
2012-12-14 21:12:29 -06:00
|
|
|
fn g(&self);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct S {
|
2015-03-25 19:06:52 -05:00
|
|
|
x: isize
|
2012-12-14 21:12:29 -06:00
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl Foo<S> for S {
|
2012-12-14 21:12:29 -06:00
|
|
|
fn f(&self, x: &S) {
|
2014-01-09 04:06:55 -06:00
|
|
|
println!("{}", x.x);
|
2012-12-14 21:12:29 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl Bar for S {
|
2012-12-14 21:12:29 -06:00
|
|
|
fn g(&self) {
|
|
|
|
self.f(self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-01 21:43:17 -06:00
|
|
|
pub fn main() {
|
2012-12-14 21:12:29 -06:00
|
|
|
let s = S { x: 1 };
|
|
|
|
s.g();
|
|
|
|
}
|