]> git.lizzy.rs Git - rust.git/commitdiff
Turn old `drop` blocks into `Drop` traits
authorBen Striegel <ben.striegel@gmail.com>
Thu, 28 Feb 2013 00:13:53 +0000 (19:13 -0500)
committerBen Striegel <ben.striegel@gmail.com>
Thu, 28 Feb 2013 00:14:19 +0000 (19:14 -0500)
22 files changed:
src/libcore/io.rs
src/libcore/option.rs
src/libcore/pipes.rs
src/libcore/private.rs
src/libcore/rand.rs
src/libcore/run.rs
src/libcore/task/spawn.rs
src/libcore/util.rs
src/librustc/lib/llvm.rs
src/librustc/middle/trans/base.rs
src/librustc/middle/trans/common.rs
src/librustc/rustc.rc
src/librustc/util/common.rs
src/librustdoc/demo.rs
src/libstd/task_pool.rs
src/libsyntax/parse/parser.rs
src/test/auxiliary/moves_based_on_type_lib.rs
src/test/compile-fail/use-after-move-self-based-on-type.rs
src/test/run-fail/too-much-recursion-unwinding.rs
src/test/run-fail/unwind-resource-fail.rs
src/test/run-fail/unwind-resource-fail2.rs
src/test/run-pass/issue-3563-3.rs

index 421eb94a29128e0ee631426987baa04e37224d9c..45d89b29a2e9a0797918d2eabae5b774b01e51fc 100644 (file)
@@ -474,7 +474,10 @@ fn tell(&self) -> uint { self.base.tell() }
 
 pub struct FILERes {
     f: *libc::FILE,
-    drop {
+}
+
+impl Drop for FILERes {
+    fn finalize(&self) {
         unsafe {
             libc::fclose(self.f);
         }
@@ -683,7 +686,10 @@ fn get_type(&self) -> WriterType {
 
 pub struct FdRes {
     fd: fd_t,
-    drop {
+}
+
+impl Drop for FdRes {
+    fn finalize(&self) {
         unsafe {
             libc::close(self.fd);
         }
index 1c2df949a2e9c7061eba22c597db41c211041a84..12ed0df007621cd01245b4ab18ea845148b10062 100644 (file)
@@ -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 {
index 15a6e700ffd841a2479c1d124cfb47e1496e01f8..a0a29c6b5160193159a75024296f1d1ceda555e9 100644 (file)
@@ -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);
index 2580efe6d09687dceff3e587cd4553b2dab2bc4e..e4fab18966cadd0b71387cb16634850dcc0c2026 100644 (file)
@@ -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 @@ fn clone(&self) -> SharedMutableState<T> {
 
 struct LittleLock {
     l: rust_little_lock,
-    drop {
+}
+
+impl Drop for LittleLock {
+    fn finalize(&self) {
         unsafe {
             rustrt::rust_destroy_little_lock(self.l);
         }
index a88b83465161da8b4ee58ddefee7c82666ca309e..15362f89e3fb63f176836597b42fe7fcc455861e 100644 (file)
@@ -365,7 +365,10 @@ fn shuffle_mut<T>(values: &mut [T]) {
 
 struct RandRes {
     rng: *rust_rng,
-    drop {
+}
+
+impl Drop for RandRes {
+    fn finalize(&self) {
         unsafe {
             rustrt::rand_free(self.rng);
         }
index 4e2337b83313348ef63b8237286502c529b7884a..aa1e473e3bf8cdfb3c4161cd6e6bf3f2c2493229 100644 (file)
@@ -248,7 +248,10 @@ fn destroy_repr(r: &mut ProgRepr) {
     }
     struct ProgRes {
         r: ProgRepr,
-        drop {
+    }
+
+    impl Drop for ProgRes {
+        fn finalize(&self) {
             unsafe {
                 // FIXME #4943: This is bad.
                 destroy_repr(cast::transmute(&self.r));
index 5110f70ff11be9762f8616625e520b71cdc6b064..bf7209f9fc3fc9ef4594704a69d744961b854a98 100644 (file)
@@ -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);
     }
index 629c4a3291ce0e5cd9f3b6d7f05e997de4c98a47..522cb2d2783cf213d64e6a37cd9e479aece28250 100644 (file)
@@ -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: () } }
index d2bb7c75a27f6225d2b688f972b5a12ddb75ced8..78528fa053ae05fbb6a6a04fa37cd726f7e42df8 100644 (file)
@@ -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);
         }
index 740a7e043d4dddb0155e628a19aad4f8e1ab96a9..c7f59a83cf5e76aac1dfcb642179f45b0933e03c 100644 (file)
 
 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();
       }
index f8a7f4779764cc9fcfd85528e5327e73eebe7ec1..c45278ee454b99048b723721f4ca26fff59f316e 100644 (file)
@@ -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);
         }
index 5df7ae493baacf4f2961444582b918ebc1ef19c4..56ad56c3ae690e382225b0eaf3db23cc3a3275a6 100644 (file)
@@ -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 };
index 7b980b9de0db61fbf3897e71708c2abdf8e14304..a83447432a006388f6fc210e3dd22268714d51fe 100644 (file)
@@ -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 {
index 3c45c4a6fa03673b867ed04691d25c9f5b18e1f4..b823be95ef7528102037d8b2a7fd8f15b778f797 100644 (file)
@@ -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); }
 }
 
 /**
index 6b8ea8a6ef42c13e8382855eec923f745127ff2f..35b7ff5ad275caec1bf795a119878c6299538703 100644 (file)
@@ -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);
         }
index 59ad35b38e4ff99a8c61773e679d8c9d5b3bc792..1799d807564bf9e78a7db10145089b6b34f1ad60 100644 (file)
@@ -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 {
index 3dd78eb3f1caa672e9bfecca6eaed513459fdbd0..826bd0db12964ab84b58eed9db7bc0feebe04097 100644 (file)
 
 pub struct S {
     x: int,
-    drop {
+}
+
+impl Drop for S {
+    fn finalize(&self) {
         io::println("goodbye");
     }
 }
index 270fe3626e8a7167d7b26223eab4a5c757b0b214..a06bc42d29aba242291f517ab614e113fb38e48d 100644 (file)
@@ -1,6 +1,9 @@
 struct S {
     x: int,
-    drop {}
+}
+
+impl Drop for S {
+    fn finalize(&self) {}
 }
 
 impl S {
index fbea8022cfc3c0000e29de1bd769639fcbe0befb..3890e24cdfe05cf0bed6415cd05f32186d8fce22 100644 (file)
@@ -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;
index 0d57e9279bc72bbc313e42efb80fab6436bfe5d1..d60e575bac4662e2205ddd789af3ca9b08c8569d 100644 (file)
 
 struct r {
     i: int,
-    drop { fail!(~"squirrel") }
+}
+
+impl Drop for r {
+    fn finalize(&self) { fail!(~"squirrel") }
 }
 
 fn r(i: int) -> r { r { i: i } }
index 0b33326abe7190bee5728d953acf3fc0a1e6773e..e276f2065f708ee69e91ede44d890b29c87e2650 100644 (file)
 
 struct r {
     i: int,
-    drop { fail!(~"wombat") }
+}
+
+impl Drop for r {
+    fn finalize(&self) { fail!(~"wombat") }
 }
 
 fn r(i: int) -> r { r { i: i } }
index c4f4aa46a8a42b7691f0e2731aac10d498281677..f66a3cc474c20ce47a8ddc266c18a36cd7b92968 100644 (file)
@@ -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.