about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBen Striegel <ben.striegel@gmail.com>2013-02-27 19:13:53 -0500
committerBen Striegel <ben.striegel@gmail.com>2013-02-27 19:14:19 -0500
commit43d43adf6bd2024b1ddc0e596d4bed88e1df82b1 (patch)
tree62bc69f2ad5f4e78dfef71a5555e1be4b4ec3aed
parent33e7a1f087b3b8047891b91fa95c5626042e7f6e (diff)
downloadrust-43d43adf6bd2024b1ddc0e596d4bed88e1df82b1.tar.gz
rust-43d43adf6bd2024b1ddc0e596d4bed88e1df82b1.zip
Turn old `drop` blocks into `Drop` traits
-rw-r--r--src/libcore/io.rs10
-rw-r--r--src/libcore/option.rs5
-rw-r--r--src/libcore/pipes.rs5
-rw-r--r--src/libcore/private.rs15
-rw-r--r--src/libcore/rand.rs5
-rw-r--r--src/libcore/run.rs5
-rw-r--r--src/libcore/task/spawn.rs10
-rw-r--r--src/libcore/util.rs5
-rw-r--r--src/librustc/lib/llvm.rs20
-rw-r--r--src/librustc/middle/trans/base.rs5
-rw-r--r--src/librustc/middle/trans/common.rs5
-rw-r--r--src/librustc/rustc.rc5
-rw-r--r--src/librustc/util/common.rs5
-rw-r--r--src/librustdoc/demo.rs5
-rw-r--r--src/libstd/task_pool.rs5
-rw-r--r--src/libsyntax/parse/parser.rs6
-rw-r--r--src/test/auxiliary/moves_based_on_type_lib.rs5
-rw-r--r--src/test/compile-fail/use-after-move-self-based-on-type.rs5
-rw-r--r--src/test/run-fail/too-much-recursion-unwinding.rs5
-rw-r--r--src/test/run-fail/unwind-resource-fail.rs5
-rw-r--r--src/test/run-fail/unwind-resource-fail2.rs5
-rw-r--r--src/test/run-pass/issue-3563-3.rs5
22 files changed, 117 insertions, 29 deletions
diff --git a/src/libcore/io.rs b/src/libcore/io.rs
index 421eb94a291..45d89b29a2e 100644
--- a/src/libcore/io.rs
+++ b/src/libcore/io.rs
@@ -474,7 +474,10 @@ impl<R:Reader,C> Reader for Wrapper<R, C> {
 
 pub struct FILERes {
     f: *libc::FILE,
-    drop {
+}
+
+impl Drop for FILERes {
+    fn finalize(&self) {
         unsafe {
             libc::fclose(self.f);
         }
@@ -683,7 +686,10 @@ impl Writer for fd_t {
 
 pub struct FdRes {
     fd: fd_t,
-    drop {
+}
+
+impl Drop for FdRes {
+    fn finalize(&self) {
         unsafe {
             libc::close(self.fd);
         }
diff --git a/src/libcore/option.rs b/src/libcore/option.rs
index 1c2df949a2e..12ed0df0076 100644
--- a/src/libcore/option.rs
+++ b/src/libcore/option.rs
@@ -450,7 +450,10 @@ fn test_unwrap_str() {
 fn test_unwrap_resource() {
     struct R {
        i: @mut int,
-       drop { *(self.i) += 1; }
+    }
+
+    impl ::ops::Drop for R {
+       fn finalize(&self) { *(self.i) += 1; }
     }
 
     fn R(i: @mut int) -> R {
diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs
index 15a6e700ffd..a0a29c6b516 100644
--- a/src/libcore/pipes.rs
+++ b/src/libcore/pipes.rs
@@ -346,7 +346,10 @@ pub unsafe fn get_buffer<T>(p: *PacketHeader) -> ~Buffer<T> {
 struct BufferResource<T> {
     buffer: ~Buffer<T>,
 
-    drop {
+}
+
+impl<T> ::ops::Drop for BufferResource<T> {
+    fn finalize(&self) {
         unsafe {
             let b = move_it!(self.buffer);
             //let p = ptr::addr_of(*b);
diff --git a/src/libcore/private.rs b/src/libcore/private.rs
index 2580efe6d09..e4fab18966c 100644
--- a/src/libcore/private.rs
+++ b/src/libcore/private.rs
@@ -126,7 +126,10 @@ struct ArcData<T> {
 
 struct ArcDestruct<T> {
     mut data: *libc::c_void,
-    drop {
+}
+
+impl<T> Drop for ArcDestruct<T>{
+    fn finalize(&self) {
         unsafe {
             if self.data.is_null() {
                 return; // Happens when destructing an unwrapper's handle.
@@ -178,7 +181,10 @@ pub unsafe fn unwrap_shared_mutable_state<T:Owned>(rc: SharedMutableState<T>)
     struct DeathThroes<T> {
         mut ptr:      Option<~ArcData<T>>,
         mut response: Option<comm::ChanOne<bool>>,
-        drop {
+    }
+
+    impl<T> Drop for DeathThroes<T>{
+        fn finalize(&self) {
             unsafe {
                 let response = option::swap_unwrap(&mut self.response);
                 // In case we get killed early, we need to tell the person who
@@ -311,7 +317,10 @@ type rust_little_lock = *libc::c_void;
 
 struct LittleLock {
     l: rust_little_lock,
-    drop {
+}
+
+impl Drop for LittleLock {
+    fn finalize(&self) {
         unsafe {
             rustrt::rust_destroy_little_lock(self.l);
         }
diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs
index a88b8346516..15362f89e3f 100644
--- a/src/libcore/rand.rs
+++ b/src/libcore/rand.rs
@@ -365,7 +365,10 @@ impl Rng {
 
 struct RandRes {
     rng: *rust_rng,
-    drop {
+}
+
+impl Drop for RandRes {
+    fn finalize(&self) {
         unsafe {
             rustrt::rand_free(self.rng);
         }
diff --git a/src/libcore/run.rs b/src/libcore/run.rs
index 4e2337b8331..aa1e473e3bf 100644
--- a/src/libcore/run.rs
+++ b/src/libcore/run.rs
@@ -248,7 +248,10 @@ pub fn start_program(prog: &str, args: &[~str]) -> Program {
     }
     struct ProgRes {
         r: ProgRepr,
-        drop {
+    }
+
+    impl Drop for ProgRes {
+        fn finalize(&self) {
             unsafe {
                 // FIXME #4943: This is bad.
                 destroy_repr(cast::transmute(&self.r));
diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs
index 5110f70ff11..bf7209f9fc3 100644
--- a/src/libcore/task/spawn.rs
+++ b/src/libcore/task/spawn.rs
@@ -308,8 +308,11 @@ struct TCB {
     mut ancestors: AncestorList,
     is_main:       bool,
     notifier:      Option<AutoNotify>,
+}
+
+impl Drop for TCB {
     // Runs on task exit.
-    drop {
+    fn finalize(&self) {
         unsafe {
             // If we are failing, the whole taskgroup needs to die.
             if rt::rust_task_is_unwinding(self.me) {
@@ -353,7 +356,10 @@ fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList,
 struct AutoNotify {
     notify_chan: Chan<TaskResult>,
     mut failed:  bool,
-    drop {
+}
+
+impl Drop for AutoNotify {
+    fn finalize(&self) {
         let result = if self.failed { Failure } else { Success };
         self.notify_chan.send(result);
     }
diff --git a/src/libcore/util.rs b/src/libcore/util.rs
index 629c4a3291c..522cb2d2783 100644
--- a/src/libcore/util.rs
+++ b/src/libcore/util.rs
@@ -66,7 +66,10 @@ pub fn replace<T>(dest: &mut T, src: T) -> T {
 /// A non-copyable dummy type.
 pub struct NonCopyable {
     i: (),
-    drop { }
+}
+
+impl Drop for NonCopyable {
+    fn finalize(&self) { }
 }
 
 pub fn NonCopyable() -> NonCopyable { NonCopyable { i: () } }
diff --git a/src/librustc/lib/llvm.rs b/src/librustc/lib/llvm.rs
index d2bb7c75a27..78528fa053a 100644
--- a/src/librustc/lib/llvm.rs
+++ b/src/librustc/lib/llvm.rs
@@ -1458,7 +1458,10 @@ pub fn struct_tys(struct_ty: TypeRef) -> ~[TypeRef] {
 
 pub struct target_data_res {
     TD: TargetDataRef,
-    drop {
+}
+
+impl Drop for target_data_res {
+    fn finalize(&self) {
         unsafe {
             llvm::LLVMDisposeTargetData(self.TD);
         }
@@ -1492,7 +1495,10 @@ pub fn mk_target_data(string_rep: ~str) -> TargetData {
 
 pub struct pass_manager_res {
     PM: PassManagerRef,
-    drop {
+}
+
+impl Drop for pass_manager_res {
+    fn finalize(&self) {
         unsafe {
             llvm::LLVMDisposePassManager(self.PM);
         }
@@ -1525,7 +1531,10 @@ pub fn mk_pass_manager() -> PassManager {
 
 pub struct object_file_res {
     ObjectFile: ObjectFileRef,
-    drop {
+}
+
+impl Drop for object_file_res {
+    fn finalize(&self) {
         unsafe {
             llvm::LLVMDisposeObjectFile(self.ObjectFile);
         }
@@ -1559,7 +1568,10 @@ pub fn mk_object_file(llmb: MemoryBufferRef) -> Option<ObjectFile> {
 
 pub struct section_iter_res {
     SI: SectionIteratorRef,
-    drop {
+}
+
+impl Drop for section_iter_res {
+    fn finalize(&self) {
         unsafe {
             llvm::LLVMDisposeSectionIterator(self.SI);
         }
diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs
index 740a7e043d4..c7f59a83cf5 100644
--- a/src/librustc/middle/trans/base.rs
+++ b/src/librustc/middle/trans/base.rs
@@ -90,7 +90,10 @@ use syntax::{ast, ast_util, codemap, ast_map};
 
 pub struct icx_popper {
     ccx: @CrateContext,
-    drop {
+}
+
+impl Drop for icx_popper {
+    fn finalize(&self) {
       if self.ccx.sess.count_llvm_insns() {
           self.ccx.stats.llvm_insn_ctxt.pop();
       }
diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs
index f8a7f477976..c45278ee454 100644
--- a/src/librustc/middle/trans/common.rs
+++ b/src/librustc/middle/trans/common.rs
@@ -141,7 +141,10 @@ pub struct Stats {
 
 pub struct BuilderRef_res {
     B: BuilderRef,
-    drop {
+}
+
+impl Drop for BuilderRef_res {
+    fn finalize(&self) {
         unsafe {
             llvm::LLVMDisposeBuilder(self.B);
         }
diff --git a/src/librustc/rustc.rc b/src/librustc/rustc.rc
index 5df7ae493ba..56ad56c3ae6 100644
--- a/src/librustc/rustc.rc
+++ b/src/librustc/rustc.rc
@@ -336,7 +336,10 @@ pub fn monitor(+f: fn~(diagnostic::Emitter)) {
 
         struct finally {
             ch: SharedChan<monitor_msg>,
-            drop { self.ch.send(done); }
+        }
+
+        impl Drop for finally {
+            fn finalize(&self) { self.ch.send(done); }
         }
 
         let _finally = finally { ch: ch };
diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs
index 7b980b9de0d..a83447432a0 100644
--- a/src/librustc/util/common.rs
+++ b/src/librustc/util/common.rs
@@ -32,7 +32,10 @@ pub fn indent<R>(op: fn() -> R) -> R {
 
 pub struct _indenter {
     _i: (),
-    drop { debug!("<<"); }
+}
+
+impl Drop for _indenter {
+    fn finalize(&self) { debug!("<<"); }
 }
 
 pub fn _indenter(_i: ()) -> _indenter {
diff --git a/src/librustdoc/demo.rs b/src/librustdoc/demo.rs
index 3c45c4a6fa0..b823be95ef7 100644
--- a/src/librustdoc/demo.rs
+++ b/src/librustdoc/demo.rs
@@ -125,7 +125,10 @@ mod blade_runner {
  */
 struct Bored {
   bored: bool,
-  drop { log(error, self.bored); }
+}
+
+impl Drop for Bored {
+  fn finalize(&self) { log(error, self.bored); }
 }
 
 /**
diff --git a/src/libstd/task_pool.rs b/src/libstd/task_pool.rs
index 6b8ea8a6ef4..35b7ff5ad27 100644
--- a/src/libstd/task_pool.rs
+++ b/src/libstd/task_pool.rs
@@ -28,7 +28,10 @@ pub struct TaskPool<T> {
     channels: ~[Chan<Msg<T>>],
     mut next_index: uint,
 
-    drop {
+}
+
+impl<T> Drop for TaskPool<T> {
+    fn finalize(&self) {
         for self.channels.each |channel| {
             channel.send(Quit);
         }
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 59ad35b38e4..1799d807564 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -243,7 +243,11 @@ pub struct Parser {
     /// Used to determine the path to externally loaded source files
     mod_path_stack: @mut ~[~str],
 
-    drop {} /* do not copy the parser; its state is tied to outside state */
+}
+
+impl Drop for Parser {
+    /* do not copy the parser; its state is tied to outside state */
+    fn finalize(&self) {}
 }
 
 pub impl Parser {
diff --git a/src/test/auxiliary/moves_based_on_type_lib.rs b/src/test/auxiliary/moves_based_on_type_lib.rs
index 3dd78eb3f1c..826bd0db129 100644
--- a/src/test/auxiliary/moves_based_on_type_lib.rs
+++ b/src/test/auxiliary/moves_based_on_type_lib.rs
@@ -12,7 +12,10 @@
 
 pub struct S {
     x: int,
-    drop {
+}
+
+impl Drop for S {
+    fn finalize(&self) {
         io::println("goodbye");
     }
 }
diff --git a/src/test/compile-fail/use-after-move-self-based-on-type.rs b/src/test/compile-fail/use-after-move-self-based-on-type.rs
index 270fe3626e8..a06bc42d29a 100644
--- a/src/test/compile-fail/use-after-move-self-based-on-type.rs
+++ b/src/test/compile-fail/use-after-move-self-based-on-type.rs
@@ -1,6 +1,9 @@
 struct S {
     x: int,
-    drop {}
+}
+
+impl Drop for S {
+    fn finalize(&self) {}
 }
 
 impl S {
diff --git a/src/test/run-fail/too-much-recursion-unwinding.rs b/src/test/run-fail/too-much-recursion-unwinding.rs
index fbea8022cfc..3890e24cdfe 100644
--- a/src/test/run-fail/too-much-recursion-unwinding.rs
+++ b/src/test/run-fail/too-much-recursion-unwinding.rs
@@ -21,7 +21,10 @@ fn recurse() {
 
 struct r {
     recursed: *mut bool,
-    drop {
+}
+
+impl Drop for r {
+    fn finalize(&self) {
         unsafe {
             if !*(self.recursed) {
                 *(self.recursed) = true;
diff --git a/src/test/run-fail/unwind-resource-fail.rs b/src/test/run-fail/unwind-resource-fail.rs
index 0d57e9279bc..d60e575bac4 100644
--- a/src/test/run-fail/unwind-resource-fail.rs
+++ b/src/test/run-fail/unwind-resource-fail.rs
@@ -12,7 +12,10 @@
 
 struct r {
     i: int,
-    drop { fail!(~"squirrel") }
+}
+
+impl Drop for r {
+    fn finalize(&self) { fail!(~"squirrel") }
 }
 
 fn r(i: int) -> r { r { i: i } }
diff --git a/src/test/run-fail/unwind-resource-fail2.rs b/src/test/run-fail/unwind-resource-fail2.rs
index 0b33326abe7..e276f2065f7 100644
--- a/src/test/run-fail/unwind-resource-fail2.rs
+++ b/src/test/run-fail/unwind-resource-fail2.rs
@@ -13,7 +13,10 @@
 
 struct r {
     i: int,
-    drop { fail!(~"wombat") }
+}
+
+impl Drop for r {
+    fn finalize(&self) { fail!(~"wombat") }
 }
 
 fn r(i: int) -> r { r { i: i } }
diff --git a/src/test/run-pass/issue-3563-3.rs b/src/test/run-pass/issue-3563-3.rs
index c4f4aa46a8a..f66a3cc474c 100644
--- a/src/test/run-pass/issue-3563-3.rs
+++ b/src/test/run-pass/issue-3563-3.rs
@@ -54,7 +54,10 @@ struct AsciiArt
 
     // This struct can be quite large so we'll disable copying: developers need
     // to either pass these structs around via borrowed pointers or move them.
-    drop {}
+}
+
+impl Drop for AsciiArt {
+    fn finalize(&self) {}
 }
 
 // It's common to define a constructor sort of function to create struct instances.