From e86ecdf9fe2d60dad52c1e60657ed749c2196c5b Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Thu, 30 Dec 2021 05:04:44 +0200 Subject: [PATCH] Use `UnsafeCell::get_mut()` in `core::lazy::OnceCell::get_mut()` This removes one unnecessary `unsafe` block. --- library/core/src/lazy.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/library/core/src/lazy.rs b/library/core/src/lazy.rs index 2b8a5f3cbf3..788f0cce01b 100644 --- a/library/core/src/lazy.rs +++ b/library/core/src/lazy.rs @@ -102,8 +102,7 @@ impl OnceCell { /// Returns `None` if the cell is empty. #[unstable(feature = "once_cell", issue = "74465")] pub fn get_mut(&mut self) -> Option<&mut T> { - // SAFETY: Safe because we have unique access - unsafe { &mut *self.inner.get() }.as_mut() + self.inner.get_mut().as_mut() } /// Sets the contents of the cell to `value`.