From f1e3b700c3aa037b48377e6c78c83f1012bb93aa Mon Sep 17 00:00:00 2001 From: Jan Niehusmann Date: Thu, 19 Sep 2024 11:03:56 +0000 Subject: [PATCH] Implement Drop for Mutex to drop the contents of the inner MaybeUninit --- src/mutex.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/mutex.rs b/src/mutex.rs index 46e1e8b..a224112 100644 --- a/src/mutex.rs +++ b/src/mutex.rs @@ -199,6 +199,13 @@ impl Mutex> { } } +impl Drop for Mutex { + fn drop(&mut self) { + // Safety: inner is always initialized + core::mem::drop(unsafe { self.inner.assume_init() }); + } +} + // NOTE A `Mutex` can be used as a channel so the protected data must be `Send` // to prevent sending non-Sendable stuff (e.g. access tokens) across different // threads.