Convert the test suite to use the Drop trait

This commit is contained in:
Ben Striegel 2012-11-14 01:22:37 -05:00 committed by Brian Anderson
parent 6e650f2d2c
commit f4a5a76aa4
75 changed files with 462 additions and 161 deletions

View file

@ -9,7 +9,10 @@
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 {

View file

@ -9,7 +9,12 @@ mod socket {
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 {

View file

@ -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
}
}
}

View file

@ -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> {

View file

@ -42,7 +42,10 @@ enum st {
struct r {
_l: @nillist,
drop {}
}
impl r : Drop {
fn finalize() {}
}
fn r(l: @nillist) -> r {

View file

@ -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: () });

View file

@ -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: () }));

View file

@ -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 }

View file

@ -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: () }));

View file

@ -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: () });

View file

@ -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() {

View file

@ -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: () });

View file

@ -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() {
}
}

View file

@ -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 {

View file

@ -1,5 +1,11 @@
struct noncopyable {
i: (), drop { error!("dropped"); }
i: (),
}
impl noncopyable : Drop {
fn finalize() {
error!("dropped");
}
}
fn noncopyable() -> noncopyable {

View file

@ -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 {

View file

@ -2,7 +2,10 @@
struct foo {
i: int,
drop {}
}
impl foo : Drop {
fn finalize() {}
}
fn foo(i:int) -> foo {

View file

@ -1,6 +1,9 @@
struct X {
x: ~str,
drop {
}
impl X : Drop {
fn finalize() {
error!("value: %s", self.x);
}
}

View file

@ -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 {

View file

@ -1,7 +1,9 @@
struct socket {
sock: int,
}
drop { }
impl socket : Drop {
fn finalize() {}
}
impl socket {

View file

@ -4,7 +4,10 @@ struct foo {
x: @mut int,
drop {
}
impl foo : Drop {
fn finalize() {
io::println("Goodbye, World!");
*self.x += 1;
}

View file

@ -11,7 +11,10 @@
struct S {
x: int,
drop {}
}
impl S : Drop {
fn finalize() {}
}
fn S(x: int) -> S { S { x: x } }

View file

@ -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);
}
}

View file

@ -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();
}

View file

@ -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() { }

View file

@ -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

View file

@ -1,7 +1,10 @@
fn main() {
struct foo {
_x: comm::Port<()>,
drop {}
}
impl foo : Drop {
fn finalize() {}
}
fn foo(x: comm::Port<()>) -> foo {

View file

@ -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 {

View file

@ -4,7 +4,10 @@
// copied
struct bar {
x: int,
drop {}
}
impl bar : Drop {
fn finalize() {}
}
fn bar(x:int) -> bar {

View file

@ -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);
}
}

View file

@ -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 {

View file

@ -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() {}

View file

@ -4,7 +4,10 @@
struct Foo {
x: int,
drop {
}
impl Foo : Drop {
fn finalize() {
io::println("Goodbye!");
}
}

View file

@ -4,7 +4,10 @@ trait Foo {
struct Bar {
x: int,
drop {}
}
impl Bar : Drop {
fn finalize() {}
}
impl Bar : Foo {

View file

@ -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);
}
}

View file

@ -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));
}
}

View file

@ -4,7 +4,10 @@
struct r {
let i:int;
new(i:int) {self.i = i;}
drop {}
}
impl r : Drop {
fn finalize() {}
}
fn main() {

View file

@ -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 };
}
}

View file

@ -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);
};
}
}

View file

@ -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);
};
}
}

View file

@ -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);
};
}
}

View file

@ -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;
}
}

View file

@ -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);
}
}

View file

@ -9,4 +9,4 @@
fn main() {
@0;
let r = move r(0);
}
}

View file

@ -5,7 +5,12 @@
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() {

View file

@ -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,} }

View file

@ -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]

View file

@ -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 {

View file

@ -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 {

View file

@ -1,7 +1,10 @@
struct socket {
sock: int,
drop { }
}
impl socket : Drop {
fn finalize() {}
}
impl socket {

View file

@ -3,7 +3,10 @@ struct Font {
cairo_font: uint,
font_dtor: uint,
drop { }
}
impl Font : Drop {
fn finalize() {}
}
fn Font() -> Font {

View file

@ -141,7 +141,10 @@ fn receiver_terminate<T: Send>(p: *packet<T>) {
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 @@ fn send_packet<T: Send>(p: *packet<T>) -> send_packet<T> {
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;

View file

@ -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 {

View file

@ -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 {

View file

@ -7,7 +7,10 @@ struct Cat {
struct Kitty {
x: int,
drop {}
}
impl Kitty : Drop {
fn finalize() {}
}
#[cfg(target_arch = "x86_64")]

View file

@ -1,4 +1,9 @@
struct thing { x: int, drop { } }
struct thing { x: int, }
impl thing : Drop {
fn finalize() {}
}
fn thing() -> thing {
thing {
x: 0

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -66,7 +66,10 @@ macro_rules! select (
struct Buffer {
foo: (),
drop { }
}
impl Buffer : Drop {
fn finalize() {}
}
proto! double_buffer (

View file

@ -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 {

View file

@ -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 {

View file

@ -8,9 +8,14 @@
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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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> {

View file

@ -5,8 +5,13 @@
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 {

View file

@ -3,7 +3,10 @@
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));
}
}

View file

@ -1,6 +1,11 @@
struct foo {
x: ~str,
drop { error!("%s", self.x); }
}
impl foo : Drop {
fn finalize() {
error!("%s", self.x);
}
}
fn main() {

View file

@ -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,

View file

@ -7,7 +7,10 @@
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,

View file

@ -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 {

View file

@ -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;
}
}

View file

@ -3,9 +3,14 @@
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 {

View file

@ -3,7 +3,10 @@
struct complainer {
c: @int,
drop {}
}
impl complainer : Drop {
fn finalize() {}
}
fn complainer(c: @int) -> complainer {

View file

@ -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 {