librustc: Implement explicit @self and ~self for objects. r=nmatsakis

This commit is contained in:
Patrick Walton 2012-11-29 10:59:49 -08:00
parent 3afd6c3d79
commit 54ae377ec2
4 changed files with 149 additions and 27 deletions

View file

@ -0,0 +1,24 @@
trait Foo {
fn f(@self);
}
struct S {
x: int
}
impl S : Foo {
fn f(@self) {
assert self.x == 3;
}
}
fn main() {
let x = @S { x: 3 };
let y = x as @Foo;
y.f();
y.f();
y.f();
y.f();
}

View file

@ -0,0 +1,23 @@
trait Foo {
fn f(~self);
}
struct S {
x: int
}
impl S : Foo {
fn f(~self) {
assert self.x == 3;
}
}
fn main() {
let x = ~S { x: 3 };
let y = x as ~Foo;
y.f();
y.f();
y.f();
}