about summary refs log tree commit diff
path: root/src/librustc_data_structures/lib.rs
diff options
context:
space:
mode:
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2018-05-27 07:47:44 +0200
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2018-06-06 15:25:17 +0200
commit090b8341bcd1eb7de3d0cbaa71eb2d77924fc4bc (patch)
tree3f33030dfb498f7fef3eaaaa0d0ff33c6b493953 /src/librustc_data_structures/lib.rs
parent77259af56ab337d476cafeeb657c9b8953f8b75b (diff)
downloadrust-090b8341bcd1eb7de3d0cbaa71eb2d77924fc4bc.tar.gz
rust-090b8341bcd1eb7de3d0cbaa71eb2d77924fc4bc.zip
Add and use OnDrop::disable
Diffstat (limited to 'src/librustc_data_structures/lib.rs')
-rw-r--r--src/librustc_data_structures/lib.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs
index 7046a2a2a49..5844edf000a 100644
--- a/src/librustc_data_structures/lib.rs
+++ b/src/librustc_data_structures/lib.rs
@@ -80,6 +80,14 @@ pub mod sorted_map;
 
 pub struct OnDrop<F: Fn()>(pub F);
 
+impl<F: Fn()> OnDrop<F> {
+      /// Forgets the function which prevents it from running.
+      /// Ensure that the function owns no memory, otherwise it will be leaked.
+      pub fn disable(self) {
+            std::mem::forget(self);
+      }
+}
+
 impl<F: Fn()> Drop for OnDrop<F> {
       fn drop(&mut self) {
             (self.0)();