diff options
Diffstat (limited to 'src/librustc_data_structures')
| -rw-r--r-- | src/librustc_data_structures/lib.rs | 8 |
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)(); |
