mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-22 10:05:06 +03:00
Add and use OnDrop::disable
This commit is contained in:
@@ -456,5 +456,5 @@ fn deadlock(tcx: TyCtxt<'_, '_, '_>, registry: &rayon_core::Registry) {
|
||||
waiter.notify(tcx, registry);
|
||||
}
|
||||
|
||||
mem::forget(on_panic);
|
||||
on_panic.disable();
|
||||
}
|
||||
|
||||
@@ -80,6 +80,14 @@
|
||||
|
||||
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)();
|
||||
|
||||
Reference in New Issue
Block a user