librustc: Implement explicit @self and ~self for objects. r=nmatsakis
This commit is contained in:
parent
3afd6c3d79
commit
54ae377ec2
4 changed files with 149 additions and 27 deletions
24
src/test/run-pass/explicit-self-objects-box.rs
Normal file
24
src/test/run-pass/explicit-self-objects-box.rs
Normal 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();
|
||||
}
|
||||
|
||||
|
||||
23
src/test/run-pass/explicit-self-objects-uniq.rs
Normal file
23
src/test/run-pass/explicit-self-objects-uniq.rs
Normal 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();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue