From 090b8341bcd1eb7de3d0cbaa71eb2d77924fc4bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Sun, 27 May 2018 07:47:44 +0200 Subject: [PATCH] Add and use OnDrop::disable --- src/librustc/ty/maps/job.rs | 2 +- src/librustc_data_structures/lib.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/librustc/ty/maps/job.rs b/src/librustc/ty/maps/job.rs index 3fe22dba6e15..6b7170f2c476 100644 --- a/src/librustc/ty/maps/job.rs +++ b/src/librustc/ty/maps/job.rs @@ -456,5 +456,5 @@ fn deadlock(tcx: TyCtxt<'_, '_, '_>, registry: &rayon_core::Registry) { waiter.notify(tcx, registry); } - mem::forget(on_panic); + on_panic.disable(); } diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs index 7046a2a2a493..5844edf000a8 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(pub F); +impl OnDrop { + /// 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 Drop for OnDrop { fn drop(&mut self) { (self.0)();