mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 03:38:29 +00:00
Convert the test suite to use the Drop trait
This commit is contained in:
parent
6e650f2d2c
commit
f4a5a76aa4
@ -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,7 +5,12 @@ 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 {
|
||||
|
@ -29,7 +29,11 @@ fn port<T: Send>() -> port<T> {
|
||||
|
||||
struct port_ptr<T:Send> {
|
||||
po: *rust_port,
|
||||
drop unsafe {
|
||||
}
|
||||
|
||||
impl<T:Send> port_ptr<T> : Drop {
|
||||
fn finalize() {
|
||||
unsafe {
|
||||
debug!("in the port_ptr destructor");
|
||||
do task::unkillable {
|
||||
let yield = 0u;
|
||||
@ -47,6 +51,7 @@ struct port_ptr<T:Send> {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn port_ptr<T: Send>(po: *rust_port) -> port_ptr<T> {
|
||||
debug!("in the port_ptr constructor");
|
||||
|
@ -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,7 +1,11 @@
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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 {}
|
||||
}
|
||||
|
||||
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,7 +2,10 @@
|
||||
|
||||
struct r {
|
||||
b:bool,
|
||||
drop {}
|
||||
}
|
||||
|
||||
impl r : Drop {
|
||||
fn finalize() {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -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]) {
|
||||
|
@ -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,7 +23,10 @@ fn getbig_call_c_and_fail(i: int) {
|
||||
|
||||
struct and_then_get_big_again {
|
||||
x:int,
|
||||
drop {
|
||||
}
|
||||
|
||||
impl and_then_get_big_again : Drop {
|
||||
fn finalize() {
|
||||
fn getbig(i: int) {
|
||||
if i != 0 {
|
||||
getbig(i - 1);
|
||||
|
@ -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 getbig(i: int) {
|
||||
if i != 0 {
|
||||
getbig(i - 1);
|
||||
|
@ -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 {
|
||||
|
@ -2,10 +2,13 @@
|
||||
|
||||
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 {
|
||||
impl r : Drop {
|
||||
fn finalize() {
|
||||
os::set_exit_status(50);
|
||||
}
|
||||
}
|
||||
|
@ -6,10 +6,15 @@ fn failfn() {
|
||||
|
||||
struct r {
|
||||
v: *int,
|
||||
drop unsafe {
|
||||
}
|
||||
|
||||
impl r : Drop {
|
||||
fn finalize() {
|
||||
unsafe {
|
||||
let _v2: ~int = cast::reinterpret_cast(&self.v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn r(v: *int) -> r {
|
||||
r {
|
||||
|
@ -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,
|
||||
}
|
||||
|
||||
impl cat : Drop {
|
||||
#[cat_dropper]
|
||||
/**
|
||||
Actually, cats don't always land on their feet when you drop them.
|
||||
*/
|
||||
drop { error!("%s landed on hir feet", self.name); }
|
||||
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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 {
|
||||
}
|
||||
|
||||
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); }
|
||||
let v2: ~int = cast::reinterpret_cast(&self.v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn r(v: *int) -> r unsafe {
|
||||
|
@ -8,10 +8,15 @@ type u = {
|
||||
|
||||
struct r {
|
||||
v: u,
|
||||
drop unsafe {
|
||||
}
|
||||
|
||||
impl r : Drop {
|
||||
fn finalize() {
|
||||
unsafe {
|
||||
let v2: ~int = cast::reinterpret_cast(&self.v.c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn r(v: u) -> r {
|
||||
r {
|
||||
|
@ -12,11 +12,16 @@ struct r {
|
||||
v: u,
|
||||
w: int,
|
||||
x: *int,
|
||||
drop unsafe {
|
||||
}
|
||||
|
||||
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 {
|
||||
r {
|
||||
|
@ -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> {
|
||||
|
@ -6,7 +6,12 @@ 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 {
|
||||
|
@ -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 {
|
||||
|
@ -3,9 +3,14 @@ extern mod std;
|
||||
|
||||
struct complainer {
|
||||
c: comm::Chan<bool>,
|
||||
drop { error!("About to send!");
|
||||
}
|
||||
|
||||
impl complainer : Drop {
|
||||
fn finalize() {
|
||||
error!("About to send!");
|
||||
comm::send(self.c, true);
|
||||
error!("Sent!"); }
|
||||
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 New Issue
Block a user