Skip to content

Commit 090b834

Browse files
committed
Add and use OnDrop::disable
1 parent 77259af commit 090b834

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/librustc/ty/maps/job.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,5 +456,5 @@ fn deadlock(tcx: TyCtxt<'_, '_, '_>, registry: &rayon_core::Registry) {
456456
waiter.notify(tcx, registry);
457457
}
458458

459-
mem::forget(on_panic);
459+
on_panic.disable();
460460
}

src/librustc_data_structures/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ pub mod sorted_map;
8080

8181
pub struct OnDrop<F: Fn()>(pub F);
8282

83+
impl<F: Fn()> OnDrop<F> {
84+
/// Forgets the function which prevents it from running.
85+
/// Ensure that the function owns no memory, otherwise it will be leaked.
86+
pub fn disable(self) {
87+
std::mem::forget(self);
88+
}
89+
}
90+
8391
impl<F: Fn()> Drop for OnDrop<F> {
8492
fn drop(&mut self) {
8593
(self.0)();

0 commit comments

Comments
 (0)