Convert the test suite to use the Drop trait
This commit is contained in:
parent
6e650f2d2c
commit
f4a5a76aa4
75 changed files with 462 additions and 161 deletions
|
@ -9,7 +9,10 @@ export context;
|
|||
|
||||
struct arc_destruct<T:Const> {
|
||||
_data: int,
|
||||
drop {}
|
||||
}
|
||||
|
||||
impl<T:Const> arc_destruct<T> : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
fn arc_destruct<T: Const>(data: int) -> arc_destruct<T> {
|
||||
|
@ -28,8 +31,10 @@ fn init() -> arc_destruct<context_res> unsafe {
|
|||
|
||||
struct context_res {
|
||||
ctx : int,
|
||||
}
|
||||
|
||||
drop { }
|
||||
impl context_res : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
fn context_res() -> context_res {
|
||||
|
|
|
@ -9,7 +9,12 @@ export socket_handle;
|
|||
|
||||
struct socket_handle {
|
||||
sockfd: libc::c_int,
|
||||
drop { /* c::close(self.sockfd); */ }
|
||||
}
|
||||
|
||||
impl socket_handle : Drop {
|
||||
fn finalize() {
|
||||
/* c::close(self.sockfd); */
|
||||
}
|
||||
}
|
||||
|
||||
fn socket_handle(x: libc::c_int) -> socket_handle {
|
||||
|
|
|
@ -5,11 +5,16 @@ fn foo(_x: i32) {
|
|||
|
||||
struct rsrc {
|
||||
x: i32,
|
||||
drop { foo(self.x); }
|
||||
}
|
||||
|
||||
impl rsrc : Drop {
|
||||
fn finalize() {
|
||||
foo(self.x);
|
||||
}
|
||||
}
|
||||
|
||||
fn rsrc(x: i32) -> rsrc {
|
||||
rsrc {
|
||||
x: x
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,23 +29,28 @@ fn port<T: Send>() -> port<T> {
|
|||
|
||||
struct port_ptr<T:Send> {
|
||||
po: *rust_port,
|
||||
drop unsafe {
|
||||
debug!("in the port_ptr destructor");
|
||||
do task::unkillable {
|
||||
let yield = 0u;
|
||||
let yieldp = ptr::addr_of(&yield);
|
||||
rustrt::rust_port_begin_detach(self.po, yieldp);
|
||||
if yield != 0u {
|
||||
task::yield();
|
||||
}
|
||||
rustrt::rust_port_end_detach(self.po);
|
||||
}
|
||||
|
||||
while rustrt::rust_port_size(self.po) > 0u as size_t {
|
||||
recv_::<T>(self.po);
|
||||
impl<T:Send> port_ptr<T> : Drop {
|
||||
fn finalize() {
|
||||
unsafe {
|
||||
debug!("in the port_ptr destructor");
|
||||
do task::unkillable {
|
||||
let yield = 0u;
|
||||
let yieldp = ptr::addr_of(&yield);
|
||||
rustrt::rust_port_begin_detach(self.po, yieldp);
|
||||
if yield != 0u {
|
||||
task::yield();
|
||||
}
|
||||
rustrt::rust_port_end_detach(self.po);
|
||||
|
||||
while rustrt::rust_port_size(self.po) > 0u as size_t {
|
||||
recv_::<T>(self.po);
|
||||
}
|
||||
rustrt::del_port(self.po);
|
||||
}
|
||||
}
|
||||
rustrt::del_port(self.po);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn port_ptr<T: Send>(po: *rust_port) -> port_ptr<T> {
|
||||
|
|
|
@ -42,7 +42,10 @@ enum st {
|
|||
|
||||
struct r {
|
||||
_l: @nillist,
|
||||
drop {}
|
||||
}
|
||||
|
||||
impl r : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
fn r(l: @nillist) -> r {
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
struct X { x: (), drop { error!("destructor runs"); } }
|
||||
struct X { x: () }
|
||||
|
||||
impl X : Drop {
|
||||
fn finalize() {
|
||||
error!("destructor runs");
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = Some(X { x: () });
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
struct X { x: (), drop { error!("destructor runs"); } }
|
||||
struct X { x: (), }
|
||||
|
||||
impl X : Drop {
|
||||
fn finalize() {
|
||||
error!("destructor runs");
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = Some((X { x: () }, X { x: () }));
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
struct X { x: (), drop { error!("destructor runs"); } }
|
||||
struct X { x: (), }
|
||||
|
||||
impl X : Drop {
|
||||
fn finalize() {
|
||||
error!("destructor runs");
|
||||
}
|
||||
}
|
||||
|
||||
enum double_option<T,U> { some2(T,U), none2 }
|
||||
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
struct X { x: (), drop { error!("destructor runs"); } }
|
||||
struct X { x: (), }
|
||||
|
||||
impl X : Drop {
|
||||
fn finalize() {
|
||||
error!("destructor runs");
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = Some((X { x: () }, X { x: () }));
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
struct X { x: (), drop { error!("destructor runs"); } }
|
||||
struct X { x: (), }
|
||||
|
||||
impl X : Drop {
|
||||
fn finalize() {
|
||||
error!("destructor runs");
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = Some(X { x: () });
|
||||
|
|
|
@ -1,4 +1,11 @@
|
|||
struct X { x: (), drop { error!("destructor runs"); } }
|
||||
struct X { x: (), }
|
||||
|
||||
impl X : Drop {
|
||||
fn finalize() {
|
||||
error!("destructor runs");
|
||||
}
|
||||
}
|
||||
|
||||
struct Y { y: Option<X> }
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
struct X { x: (), drop { error!("destructor runs"); } }
|
||||
struct X { x: (), }
|
||||
|
||||
impl X : Drop {
|
||||
fn finalize() {
|
||||
error!("destructor runs");
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = Some(X { x: () });
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
// error-pattern:mismatched types: expected `()` but found `bool`
|
||||
|
||||
struct r {
|
||||
drop { true }
|
||||
struct r {}
|
||||
|
||||
impl r : Drop {
|
||||
fn finalize() {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
struct defer {
|
||||
x: &[&str],
|
||||
drop { error!("%?", self.x); }
|
||||
}
|
||||
|
||||
impl defer : Drop {
|
||||
fn finalize() {
|
||||
error!("%?", self.x);
|
||||
}
|
||||
}
|
||||
|
||||
fn defer(x: &r/[&r/str]) -> defer/&r {
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
struct noncopyable {
|
||||
i: (), drop { error!("dropped"); }
|
||||
i: (),
|
||||
}
|
||||
|
||||
impl noncopyable : Drop {
|
||||
fn finalize() {
|
||||
error!("dropped");
|
||||
}
|
||||
}
|
||||
|
||||
fn noncopyable() -> noncopyable {
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
// error-pattern: copying a noncopyable value
|
||||
|
||||
struct foo { x: int, drop { } }
|
||||
struct foo { x: int, }
|
||||
|
||||
impl foo : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
fn foo(x: int) -> foo {
|
||||
foo {
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
|
||||
struct foo {
|
||||
i: int,
|
||||
drop {}
|
||||
}
|
||||
|
||||
impl foo : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
fn foo(i:int) -> foo {
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
struct X {
|
||||
x: ~str,
|
||||
drop {
|
||||
}
|
||||
|
||||
impl X : Drop {
|
||||
fn finalize() {
|
||||
error!("value: %s", self.x);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
struct Bar {
|
||||
x: int,
|
||||
drop { io::println("Goodbye, cruel world"); }
|
||||
}
|
||||
|
||||
impl Bar : Drop {
|
||||
fn finalize() {
|
||||
io::println("Goodbye, cruel world");
|
||||
}
|
||||
}
|
||||
|
||||
struct Foo {
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
struct socket {
|
||||
sock: int,
|
||||
}
|
||||
|
||||
drop { }
|
||||
impl socket : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
impl socket {
|
||||
|
|
|
@ -4,7 +4,10 @@ struct foo {
|
|||
x: @mut int,
|
||||
|
||||
|
||||
drop {
|
||||
}
|
||||
|
||||
impl foo : Drop {
|
||||
fn finalize() {
|
||||
io::println("Goodbye, World!");
|
||||
*self.x += 1;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,10 @@ fn bar<T>(+_t: T) { fail; }
|
|||
|
||||
struct S {
|
||||
x: int,
|
||||
drop {}
|
||||
}
|
||||
|
||||
impl S : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
fn S(x: int) -> S { S { x: x } }
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
struct C {
|
||||
x: int,
|
||||
drop {
|
||||
}
|
||||
|
||||
impl C : Drop {
|
||||
fn finalize() {
|
||||
error!("dropping: %?", self.x);
|
||||
}
|
||||
}
|
||||
|
@ -9,4 +12,4 @@ fn main() {
|
|||
let c = C{ x: 2};
|
||||
let d = copy c; //~ ERROR copying a noncopyable value
|
||||
error!("%?", d.x);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
struct example {
|
||||
x: int,
|
||||
drop {} //~ ERROR First destructor declared
|
||||
drop {
|
||||
debug!("Goodbye, cruel world");
|
||||
}
|
||||
}
|
||||
|
||||
fn example() -> example {
|
||||
example {
|
||||
x: 1
|
||||
}
|
||||
}
|
||||
|
||||
fn main(_args: ~[~str]) {
|
||||
let e: example = example();
|
||||
}
|
|
@ -2,7 +2,10 @@ fn foo<T>() {
|
|||
struct foo {
|
||||
mut x: T, //~ ERROR attempt to use a type argument out of scope
|
||||
//~^ ERROR use of undeclared type name
|
||||
drop { }
|
||||
}
|
||||
|
||||
impl<T> foo<T> : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
}
|
||||
fn main() { }
|
||||
|
|
|
@ -50,8 +50,12 @@ fn f4b() -> int {
|
|||
// leave this in here just to trigger compile-fail:
|
||||
struct r {
|
||||
x: (),
|
||||
drop {}
|
||||
}
|
||||
|
||||
impl r : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = r { x: () };
|
||||
fn@(move x) { copy x; }; //~ ERROR copying a noncopyable value
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
fn main() {
|
||||
struct foo {
|
||||
_x: comm::Port<()>,
|
||||
drop {}
|
||||
}
|
||||
|
||||
impl foo : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
fn foo(x: comm::Port<()>) -> foo {
|
||||
|
|
|
@ -4,7 +4,10 @@ fn foo<T: Const>(_x: T) { }
|
|||
|
||||
struct r {
|
||||
x:int,
|
||||
drop {}
|
||||
}
|
||||
|
||||
impl r : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
fn r(x:int) -> r {
|
||||
|
@ -15,7 +18,10 @@ fn r(x:int) -> r {
|
|||
|
||||
struct r2 {
|
||||
x:@mut int,
|
||||
drop {}
|
||||
}
|
||||
|
||||
impl r2 : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
fn r2(x:@mut int) -> r2 {
|
||||
|
|
|
@ -4,7 +4,10 @@
|
|||
// copied
|
||||
struct bar {
|
||||
x: int,
|
||||
drop {}
|
||||
}
|
||||
|
||||
impl bar : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
fn bar(x:int) -> bar {
|
||||
|
|
|
@ -2,7 +2,12 @@
|
|||
|
||||
struct r {
|
||||
i: @mut int,
|
||||
drop { *(self.i) = *(self.i) + 1; }
|
||||
}
|
||||
|
||||
impl r : Drop {
|
||||
fn finalize() {
|
||||
*(self.i) = *(self.i) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
fn r(i: @mut int) -> r {
|
||||
|
@ -20,4 +25,4 @@ fn main() {
|
|||
log(debug, x);
|
||||
}
|
||||
log(error, *i);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,12 @@
|
|||
|
||||
struct my_resource {
|
||||
x: int,
|
||||
drop { log(error, self.x); }
|
||||
}
|
||||
|
||||
impl my_resource : Drop {
|
||||
fn finalize() {
|
||||
log(error, self.x);
|
||||
}
|
||||
}
|
||||
|
||||
fn my_resource(x: int) -> my_resource {
|
||||
|
|
|
@ -1,16 +1,25 @@
|
|||
struct yes0 {
|
||||
x: &uint,
|
||||
drop {}
|
||||
}
|
||||
|
||||
impl yes0 : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
struct yes1 {
|
||||
x: &self/uint,
|
||||
drop {}
|
||||
}
|
||||
|
||||
impl yes1 : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
struct yes2 {
|
||||
x: &foo/uint, //~ ERROR named regions other than `self` are not allowed as part of a type declaration
|
||||
drop {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
impl yes2 : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -4,7 +4,10 @@
|
|||
struct Foo {
|
||||
x: int,
|
||||
|
||||
drop {
|
||||
}
|
||||
|
||||
impl Foo : Drop {
|
||||
fn finalize() {
|
||||
io::println("Goodbye!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,10 @@ trait Foo {
|
|||
|
||||
struct Bar {
|
||||
x: int,
|
||||
drop {}
|
||||
}
|
||||
|
||||
impl Bar : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
impl Bar : Foo {
|
||||
|
|
|
@ -2,11 +2,14 @@
|
|||
|
||||
struct r {
|
||||
b:bool,
|
||||
drop {}
|
||||
}
|
||||
|
||||
impl r : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let i = move ~r { b: true };
|
||||
let j = i;
|
||||
log(debug, i);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,12 @@
|
|||
|
||||
struct r {
|
||||
i: @mut int,
|
||||
drop { *(self.i) = *(self.i) + 1; }
|
||||
}
|
||||
|
||||
impl r : Drop {
|
||||
fn finalize() {
|
||||
*(self.i) = *(self.i) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
fn f<T>(+i: ~[T], +j: ~[T]) {
|
||||
|
@ -17,4 +22,4 @@ fn main() {
|
|||
f(r1, r2);
|
||||
log(debug, (r2, *i1));
|
||||
log(debug, (r1, *i2));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,10 @@
|
|||
struct r {
|
||||
let i:int;
|
||||
new(i:int) {self.i = i;}
|
||||
drop {}
|
||||
}
|
||||
|
||||
impl r : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
// error-pattern: ran out of stack
|
||||
struct R {
|
||||
b: int,
|
||||
drop {
|
||||
}
|
||||
|
||||
impl R : Drop {
|
||||
fn finalize() {
|
||||
let _y = R { b: self.b };
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,14 +23,17 @@ fn getbig_call_c_and_fail(i: int) {
|
|||
|
||||
struct and_then_get_big_again {
|
||||
x:int,
|
||||
drop {
|
||||
fn getbig(i: int) {
|
||||
if i != 0 {
|
||||
getbig(i - 1);
|
||||
}
|
||||
|
||||
impl and_then_get_big_again : Drop {
|
||||
fn finalize() {
|
||||
fn getbig(i: int) {
|
||||
if i != 0 {
|
||||
getbig(i - 1);
|
||||
}
|
||||
}
|
||||
getbig(10000);
|
||||
}
|
||||
getbig(10000);
|
||||
}
|
||||
}
|
||||
|
||||
fn and_then_get_big_again(x:int) -> and_then_get_big_again {
|
||||
|
@ -44,4 +47,4 @@ fn main() {
|
|||
let r = and_then_get_big_again(4);
|
||||
getbig_call_c_and_fail(10000);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,14 +15,17 @@ fn getbig_and_fail(&&i: int) {
|
|||
|
||||
struct and_then_get_big_again {
|
||||
x:int,
|
||||
drop {
|
||||
fn getbig(i: int) {
|
||||
if i != 0 {
|
||||
getbig(i - 1);
|
||||
}
|
||||
|
||||
impl and_then_get_big_again : Drop {
|
||||
fn finalize() {
|
||||
fn getbig(i: int) {
|
||||
if i != 0 {
|
||||
getbig(i - 1);
|
||||
}
|
||||
}
|
||||
getbig(100);
|
||||
}
|
||||
getbig(100);
|
||||
}
|
||||
}
|
||||
|
||||
fn and_then_get_big_again(x:int) -> and_then_get_big_again {
|
||||
|
@ -35,4 +38,4 @@ fn main() {
|
|||
do task::spawn {
|
||||
getbig_and_fail(400);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,10 @@ fn getbig_and_fail(&&i: int) {
|
|||
|
||||
struct and_then_get_big_again {
|
||||
x:int,
|
||||
drop {}
|
||||
}
|
||||
|
||||
impl and_then_get_big_again : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
fn and_then_get_big_again(x:int) -> and_then_get_big_again {
|
||||
|
@ -28,4 +31,4 @@ fn main() {
|
|||
do task::spawn {
|
||||
getbig_and_fail(1);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,12 +2,15 @@
|
|||
|
||||
struct r {
|
||||
x:int,
|
||||
// Setting the exit status after the runtime has already
|
||||
// failed has no effect and the process exits with the
|
||||
// runtime's exit code
|
||||
drop {
|
||||
os::set_exit_status(50);
|
||||
}
|
||||
}
|
||||
|
||||
// Setting the exit status after the runtime has already
|
||||
// failed has no effect and the process exits with the
|
||||
// runtime's exit code
|
||||
impl r : Drop {
|
||||
fn finalize() {
|
||||
os::set_exit_status(50);
|
||||
}
|
||||
}
|
||||
|
||||
fn r(x:int) -> r {
|
||||
|
@ -22,4 +25,4 @@ fn main() {
|
|||
let i = r(5);
|
||||
};
|
||||
fail;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,14 @@ fn failfn() {
|
|||
|
||||
struct r {
|
||||
v: *int,
|
||||
drop unsafe {
|
||||
let _v2: ~int = cast::reinterpret_cast(&self.v);
|
||||
}
|
||||
}
|
||||
|
||||
impl r : Drop {
|
||||
fn finalize() {
|
||||
unsafe {
|
||||
let _v2: ~int = cast::reinterpret_cast(&self.v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn r(v: *int) -> r {
|
||||
|
@ -24,4 +29,4 @@ fn main() unsafe {
|
|||
let x = @r(i1p);
|
||||
failfn();
|
||||
log(error, x);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,4 +9,4 @@ class r {
|
|||
fn main() {
|
||||
@0;
|
||||
let r = move r(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,12 @@ class faily_box {
|
|||
let i: @int;
|
||||
new(i: @int) { self.i = i; }
|
||||
// What happens to the box pointer owned by this class?
|
||||
drop { fail "quux"; }
|
||||
}
|
||||
|
||||
impl faily_box : Drop {
|
||||
fn finalize() {
|
||||
fail "quux";
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
// pp-exact - Make sure we actually print the attributes
|
||||
|
||||
struct cat {
|
||||
#[cat_dropper]
|
||||
drop { error!("%s landed on hir feet",self.name); }
|
||||
name: ~str,
|
||||
}
|
||||
|
||||
impl cat: Drop {
|
||||
#[cat_dropper]
|
||||
fn finalize() { error!("%s landed on hir feet",self.name); }
|
||||
}
|
||||
|
||||
|
||||
#[cat_maker]
|
||||
fn cat(name: ~str) -> cat { cat{name: name,} }
|
||||
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
struct cat {
|
||||
name: ~str,
|
||||
#[cat_dropper]
|
||||
/**
|
||||
Actually, cats don't always land on their feet when you drop them.
|
||||
*/
|
||||
drop { error!("%s landed on hir feet", self.name); }
|
||||
}
|
||||
|
||||
impl cat : Drop {
|
||||
#[cat_dropper]
|
||||
/**
|
||||
Actually, cats don't always land on their feet when you drop them.
|
||||
*/
|
||||
fn finalize() {
|
||||
error!("%s landed on hir feet", self.name);
|
||||
}
|
||||
}
|
||||
|
||||
#[cat_maker]
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
struct cat {
|
||||
done : extern fn(uint),
|
||||
meows : uint,
|
||||
drop { self.done(self.meows); }
|
||||
}
|
||||
|
||||
impl cat : Drop {
|
||||
fn finalize() {
|
||||
self.done(self.meows);
|
||||
}
|
||||
}
|
||||
|
||||
fn cat(done: extern fn(uint)) -> cat {
|
||||
|
|
|
@ -3,7 +3,12 @@
|
|||
|
||||
struct r {
|
||||
i: @mut int,
|
||||
drop { *(self.i) = *(self.i) + 1; }
|
||||
}
|
||||
|
||||
impl r : Drop {
|
||||
fn finalize() {
|
||||
*(self.i) = *(self.i) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
fn r(i: @mut int) -> r {
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
struct socket {
|
||||
sock: int,
|
||||
|
||||
drop { }
|
||||
}
|
||||
|
||||
impl socket : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
impl socket {
|
||||
|
|
|
@ -3,7 +3,10 @@ struct Font {
|
|||
cairo_font: uint,
|
||||
font_dtor: uint,
|
||||
|
||||
drop { }
|
||||
}
|
||||
|
||||
impl Font : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
fn Font() -> Font {
|
||||
|
|
|
@ -141,7 +141,10 @@ mod pipes {
|
|||
|
||||
struct send_packet<T: Send> {
|
||||
mut p: Option<*packet<T>>,
|
||||
drop {
|
||||
}
|
||||
|
||||
impl<T: Send> send_packet<T> : Drop {
|
||||
fn finalize() {
|
||||
if self.p != None {
|
||||
let mut p = None;
|
||||
p <-> self.p;
|
||||
|
@ -166,7 +169,10 @@ mod pipes {
|
|||
|
||||
struct recv_packet<T: Send> {
|
||||
mut p: Option<*packet<T>>,
|
||||
drop {
|
||||
}
|
||||
|
||||
impl<T: Send> recv_packet<T> : Drop {
|
||||
fn finalize() {
|
||||
if self.p != None {
|
||||
let mut p = None;
|
||||
p <-> self.p;
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
// This test should behave exactly like issue-2735-3
|
||||
struct defer {
|
||||
b: &mut bool,
|
||||
drop { *(self.b) = true; }
|
||||
}
|
||||
|
||||
impl defer : Drop {
|
||||
fn finalize() {
|
||||
*(self.b) = true;
|
||||
}
|
||||
}
|
||||
|
||||
fn defer(b: &r/mut bool) -> defer/&r {
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
// This test should behave exactly like issue-2735-2
|
||||
struct defer {
|
||||
b: &mut bool,
|
||||
drop { *(self.b) = true; }
|
||||
}
|
||||
|
||||
impl defer : Drop {
|
||||
fn finalize() {
|
||||
*(self.b) = true;
|
||||
}
|
||||
}
|
||||
|
||||
fn defer(b: &r/mut bool) -> defer/&r {
|
||||
|
|
|
@ -7,7 +7,10 @@ struct Cat {
|
|||
|
||||
struct Kitty {
|
||||
x: int,
|
||||
drop {}
|
||||
}
|
||||
|
||||
impl Kitty : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
struct thing { x: int, drop { } }
|
||||
struct thing { x: int, }
|
||||
|
||||
impl thing : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
fn thing() -> thing {
|
||||
thing {
|
||||
x: 0
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
struct r {
|
||||
b: @mut int,
|
||||
drop { *(self.b) += 1; }
|
||||
}
|
||||
|
||||
impl r : Drop {
|
||||
fn finalize() {
|
||||
*(self.b) += 1;
|
||||
}
|
||||
}
|
||||
|
||||
fn r(b: @mut int) -> r {
|
||||
|
@ -16,4 +21,4 @@ fn main() {
|
|||
}
|
||||
|
||||
assert *b == 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
struct dtor {
|
||||
x: @mut int,
|
||||
|
||||
drop {
|
||||
}
|
||||
|
||||
impl dtor : Drop {
|
||||
fn finalize() {
|
||||
// abuse access to shared mutable state to write this code
|
||||
*self.x -= 1;
|
||||
}
|
||||
|
@ -23,4 +26,4 @@ fn main() {
|
|||
}
|
||||
|
||||
assert *x == 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,10 @@ macro_rules! select (
|
|||
struct Buffer {
|
||||
foo: (),
|
||||
|
||||
drop { }
|
||||
}
|
||||
|
||||
impl Buffer : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
proto! double_buffer (
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
struct r {
|
||||
i: @mut int,
|
||||
drop { *(self.i) += 1; }
|
||||
}
|
||||
|
||||
impl r : Drop {
|
||||
fn finalize() {
|
||||
*(self.i) += 1;
|
||||
}
|
||||
}
|
||||
|
||||
fn r(i: @mut int) -> r {
|
||||
|
|
|
@ -2,12 +2,18 @@
|
|||
|
||||
struct r {
|
||||
v: *int,
|
||||
drop unsafe {
|
||||
debug!("r's dtor: self = %x, self.v = %x, self.v's value = %x",
|
||||
cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(&self)),
|
||||
cast::reinterpret_cast::<**int, uint>(&ptr::addr_of(&(self.v))),
|
||||
cast::reinterpret_cast::<*int, uint>(&self.v));
|
||||
let v2: ~int = cast::reinterpret_cast(&self.v); }
|
||||
}
|
||||
|
||||
impl r : Drop {
|
||||
fn finalize() {
|
||||
unsafe {
|
||||
debug!("r's dtor: self = %x, self.v = %x, self.v's value = %x",
|
||||
cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(&self)),
|
||||
cast::reinterpret_cast::<**int, uint>(&ptr::addr_of(&(self.v))),
|
||||
cast::reinterpret_cast::<*int, uint>(&self.v));
|
||||
let v2: ~int = cast::reinterpret_cast(&self.v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn r(v: *int) -> r unsafe {
|
||||
|
|
|
@ -8,9 +8,14 @@ type u = {
|
|||
|
||||
struct r {
|
||||
v: u,
|
||||
drop unsafe {
|
||||
let v2: ~int = cast::reinterpret_cast(&self.v.c);
|
||||
}
|
||||
}
|
||||
|
||||
impl r : Drop {
|
||||
fn finalize() {
|
||||
unsafe {
|
||||
let v2: ~int = cast::reinterpret_cast(&self.v.c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn r(v: u) -> r {
|
||||
|
|
|
@ -12,10 +12,15 @@ struct r {
|
|||
v: u,
|
||||
w: int,
|
||||
x: *int,
|
||||
drop unsafe {
|
||||
let _v2: ~int = cast::reinterpret_cast(&self.v.c);
|
||||
// let _v3: ~int = unsafe::reinterpret_cast(self.x);
|
||||
}
|
||||
}
|
||||
|
||||
impl r : Drop {
|
||||
fn finalize() {
|
||||
unsafe {
|
||||
let _v2: ~int = cast::reinterpret_cast(&self.v.c);
|
||||
// let _v3: ~int = unsafe::reinterpret_cast(self.x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn r(v: u, w: int, _x: *int) -> r unsafe {
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
struct shrinky_pointer {
|
||||
i: @@mut int,
|
||||
drop { log(error, ~"Hello!"); **(self.i) -= 1; }
|
||||
}
|
||||
|
||||
impl shrinky_pointer : Drop {
|
||||
fn finalize() {
|
||||
log(error, ~"Hello!"); **(self.i) -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
impl shrinky_pointer {
|
||||
|
|
|
@ -3,7 +3,12 @@
|
|||
|
||||
struct finish<T: Copy> {
|
||||
arg: {val: T, fin: extern fn(T)},
|
||||
drop { self.arg.fin(self.arg.val); }
|
||||
}
|
||||
|
||||
impl<T: Copy> finish<T> : Drop {
|
||||
fn finalize() {
|
||||
self.arg.fin(self.arg.val);
|
||||
}
|
||||
}
|
||||
|
||||
fn finish<T: Copy>(arg: {val: T, fin: extern fn(T)}) -> finish<T> {
|
||||
|
|
|
@ -5,8 +5,13 @@ type closable = @mut bool;
|
|||
|
||||
struct close_res {
|
||||
i: closable,
|
||||
|
||||
drop { *(self.i) = false; }
|
||||
|
||||
}
|
||||
|
||||
impl close_res : Drop {
|
||||
fn finalize() {
|
||||
*(self.i) = false;
|
||||
}
|
||||
}
|
||||
|
||||
fn close_res(i: closable) -> close_res {
|
||||
|
|
|
@ -3,7 +3,10 @@ use comm::*;
|
|||
|
||||
struct test {
|
||||
f: int,
|
||||
drop {}
|
||||
}
|
||||
|
||||
impl test : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
fn test(f: int) -> test {
|
||||
|
@ -24,4 +27,4 @@ fn main() {
|
|||
}
|
||||
|
||||
p.recv().send(test(42));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
struct foo {
|
||||
x: ~str,
|
||||
drop { error!("%s", self.x); }
|
||||
}
|
||||
|
||||
impl foo : Drop {
|
||||
fn finalize() {
|
||||
error!("%s", self.x);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -9,7 +9,10 @@ fn child() { }
|
|||
|
||||
struct notify {
|
||||
ch: comm::Chan<bool>, v: @mut bool,
|
||||
drop {
|
||||
}
|
||||
|
||||
impl notify : Drop {
|
||||
fn finalize() {
|
||||
error!("notify: task=%? v=%x unwinding=%b b=%b",
|
||||
task::get_task(),
|
||||
ptr::addr_of(&(*(self.v))) as uint,
|
||||
|
|
|
@ -7,7 +7,10 @@ extern mod std;
|
|||
|
||||
struct notify {
|
||||
ch: comm::Chan<bool>, v: @mut bool,
|
||||
drop {
|
||||
}
|
||||
|
||||
impl notify : Drop {
|
||||
fn finalize() {
|
||||
error!("notify: task=%? v=%x unwinding=%b b=%b",
|
||||
task::get_task(),
|
||||
ptr::addr_of(&(*(self.v))) as uint,
|
||||
|
|
|
@ -7,7 +7,10 @@ fn u_foo<T: Send>(unique: T) { }
|
|||
|
||||
struct r {
|
||||
i: int,
|
||||
drop {}
|
||||
}
|
||||
|
||||
impl r : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
fn r(i:int) -> r {
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
struct r {
|
||||
i: @mut int,
|
||||
drop { *(self.i) = *(self.i) + 1; }
|
||||
}
|
||||
|
||||
impl r : Drop {
|
||||
fn finalize() {
|
||||
*(self.i) = *(self.i) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
fn r(i: @mut int) -> r {
|
||||
|
@ -15,4 +20,4 @@ fn main() {
|
|||
let j = ~r(i);
|
||||
}
|
||||
assert *i == 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,14 @@ extern mod std;
|
|||
|
||||
struct complainer {
|
||||
c: comm::Chan<bool>,
|
||||
drop { error!("About to send!");
|
||||
comm::send(self.c, true);
|
||||
error!("Sent!"); }
|
||||
}
|
||||
|
||||
impl complainer : Drop {
|
||||
fn finalize() {
|
||||
error!("About to send!");
|
||||
comm::send(self.c, true);
|
||||
error!("Sent!");
|
||||
}
|
||||
}
|
||||
|
||||
fn complainer(c: comm::Chan<bool>) -> complainer {
|
||||
|
|
|
@ -3,7 +3,10 @@ extern mod std;
|
|||
|
||||
struct complainer {
|
||||
c: @int,
|
||||
drop {}
|
||||
}
|
||||
|
||||
impl complainer : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
fn complainer(c: @int) -> complainer {
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
// Make sure that destructors get run on slice literals
|
||||
struct foo {
|
||||
x: @mut int,
|
||||
drop { *self.x += 1; }
|
||||
}
|
||||
|
||||
impl foo : Drop {
|
||||
fn finalize() {
|
||||
*self.x += 1;
|
||||
}
|
||||
}
|
||||
|
||||
fn foo(x: @mut int) -> foo {
|
||||
|
|
Loading…
Reference in a new issue