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> {
struct context_res {
ctx : int,
+}
- drop { }
+impl context_res : Drop {
+ fn finalize() {}
}
fn context_res() -> context_res {
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 {
struct rsrc {
x: i32,
- drop { foo(self.x); }
+}
+
+impl rsrc : Drop {
+ fn finalize() {
+ foo(self.x);
+ }
}
fn rsrc(x: i32) -> rsrc {
rsrc {
x: x
}
-}
\ No newline at end of file
+}
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> {
struct r {
_l: @nillist,
- drop {}
+}
+
+impl r : Drop {
+ fn finalize() {}
}
fn r(l: @nillist) -> r {
-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: () });
-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: () }));
-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 }
-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: () }));
-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: () });
-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() {
-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: () });
// error-pattern:mismatched types: expected `()` but found `bool`
-struct r {
- drop { true }
+struct r {}
+
+impl r : Drop {
+ fn finalize() {
+ true
+ }
}
fn main() {
-}
\ No newline at end of file
+}
struct defer {
x: &[&str],
- drop { error!("%?", self.x); }
+}
+
+impl defer : Drop {
+ fn finalize() {
+ error!("%?", self.x);
+ }
}
fn defer(x: &r/[&r/str]) -> defer/&r {
struct noncopyable {
- i: (), drop { error!("dropped"); }
+ i: (),
+}
+
+impl noncopyable : Drop {
+ fn finalize() {
+ error!("dropped");
+ }
}
fn noncopyable() -> noncopyable {
// 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 {
struct foo {
i: int,
- drop {}
+}
+
+impl foo : Drop {
+ fn finalize() {}
}
fn foo(i:int) -> foo {
struct X {
x: ~str,
- drop {
+}
+
+impl X : Drop {
+ fn finalize() {
error!("value: %s", self.x);
}
}
struct Bar {
x: int,
- drop { io::println("Goodbye, cruel world"); }
+}
+
+impl Bar : Drop {
+ fn finalize() {
+ io::println("Goodbye, cruel world");
+ }
}
struct Foo {
struct socket {
sock: int,
+}
- drop { }
+impl socket : Drop {
+ fn finalize() {}
}
impl socket {
x: @mut int,
- drop {
+}
+
+impl foo : Drop {
+ fn finalize() {
io::println("Goodbye, World!");
*self.x += 1;
}
struct S {
x: int,
- drop {}
+}
+
+impl S : Drop {
+ fn finalize() {}
}
fn S(x: int) -> S { S { x: x } }
struct C {
x: int,
- drop {
+}
+
+impl C : Drop {
+ fn finalize() {
error!("dropping: %?", self.x);
}
}
let c = C{ x: 2};
let d = copy c; //~ ERROR copying a noncopyable value
error!("%?", d.x);
-}
\ No newline at end of file
+}
+++ /dev/null
-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();
-}
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() { }
// 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
fn main() {
struct foo {
_x: comm::Port<()>,
- drop {}
+ }
+
+ impl foo : Drop {
+ fn finalize() {}
}
fn foo(x: comm::Port<()>) -> foo {
struct r {
x:int,
- drop {}
+}
+
+impl r : Drop {
+ fn finalize() {}
}
fn r(x:int) -> r {
struct r2 {
x:@mut int,
- drop {}
+}
+
+impl r2 : Drop {
+ fn finalize() {}
}
fn r2(x:@mut int) -> r2 {
// copied
struct bar {
x: int,
- drop {}
+}
+
+impl bar : Drop {
+ fn finalize() {}
}
fn bar(x:int) -> bar {
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 {
log(debug, x);
}
log(error, *i);
-}
\ No newline at end of file
+}
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 {
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() {}
\ No newline at end of file
+impl yes2 : Drop {
+ fn finalize() {}
+}
+
+fn main() {}
struct Foo {
x: int,
- drop {
+}
+
+impl Foo : Drop {
+ fn finalize() {
io::println("Goodbye!");
}
}
struct Bar {
x: int,
- drop {}
+}
+
+impl Bar : Drop {
+ fn finalize() {}
}
impl Bar : Foo {
struct r {
b:bool,
- drop {}
+}
+
+impl r : Drop {
+ fn finalize() {}
}
fn main() {
let i = move ~r { b: true };
let j = i;
log(debug, i);
-}
\ No newline at end of file
+}
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]) {
f(r1, r2);
log(debug, (r2, *i1));
log(debug, (r1, *i2));
-}
\ No newline at end of file
+}
struct r {
let i:int;
new(i:int) {self.i = i;}
- drop {}
+}
+
+impl r : Drop {
+ fn finalize() {}
}
fn main() {
// error-pattern: ran out of stack
struct R {
b: int,
- drop {
+}
+
+impl R : Drop {
+ fn finalize() {
let _y = R { b: self.b };
}
}
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 {
let r = and_then_get_big_again(4);
getbig_call_c_and_fail(10000);
};
-}
\ No newline at end of file
+}
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 {
do task::spawn {
getbig_and_fail(400);
};
-}
\ No newline at end of file
+}
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 {
do task::spawn {
getbig_and_fail(1);
};
-}
\ No newline at end of file
+}
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 {
let i = r(5);
};
fail;
-}
\ No newline at end of file
+}
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 {
let x = @r(i1p);
failfn();
log(error, x);
-}
\ No newline at end of file
+}
fn main() {
@0;
let r = move r(0);
-}
\ No newline at end of file
+}
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() {
// 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,} }
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]
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 {
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 {
struct socket {
sock: int,
- drop { }
+}
+
+impl socket : Drop {
+ fn finalize() {}
}
impl socket {
cairo_font: uint,
font_dtor: uint,
- drop { }
+}
+
+impl Font : Drop {
+ fn finalize() {}
}
fn Font() -> Font {
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;
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;
// 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 {
// 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 {
struct Kitty {
x: int,
- drop {}
+}
+
+impl Kitty : Drop {
+ fn finalize() {}
}
#[cfg(target_arch = "x86_64")]
-struct thing { x: int, drop { } }
+struct thing { x: int, }
+
+impl thing : Drop {
+ fn finalize() {}
+}
+
fn thing() -> thing {
thing {
x: 0
struct r {
b: @mut int,
- drop { *(self.b) += 1; }
+}
+
+impl r : Drop {
+ fn finalize() {
+ *(self.b) += 1;
+ }
}
fn r(b: @mut int) -> r {
}
assert *b == 1;
-}
\ No newline at end of file
+}
struct dtor {
x: @mut int,
- drop {
+}
+
+impl dtor : Drop {
+ fn finalize() {
// abuse access to shared mutable state to write this code
*self.x -= 1;
}
}
assert *x == 0;
-}
\ No newline at end of file
+}
struct Buffer {
foo: (),
- drop { }
+}
+
+impl Buffer : Drop {
+ fn finalize() {}
}
proto! double_buffer (
struct r {
i: @mut int,
- drop { *(self.i) += 1; }
+}
+
+impl r : Drop {
+ fn finalize() {
+ *(self.i) += 1;
+ }
}
fn r(i: @mut int) -> r {
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 {
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 {
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 {
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 {
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> {
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 {
struct test {
f: int,
- drop {}
+}
+
+impl test : Drop {
+ fn finalize() {}
}
fn test(f: int) -> test {
}
p.recv().send(test(42));
-}
\ No newline at end of file
+}
struct foo {
x: ~str,
- drop { error!("%s", self.x); }
+}
+
+impl foo : Drop {
+ fn finalize() {
+ error!("%s", self.x);
+ }
}
fn main() {
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,
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,
struct r {
i: int,
- drop {}
+}
+
+impl r : Drop {
+ fn finalize() {}
}
fn r(i:int) -> r {
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 {
let j = ~r(i);
}
assert *i == 1;
-}
\ No newline at end of file
+}
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 {
struct complainer {
c: @int,
- drop {}
+}
+
+impl complainer : Drop {
+ fn finalize() {}
}
fn complainer(c: @int) -> complainer {
// 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 {