Use UnsafeCell::get_mut() in core::lazy::OnceCell::get_mut()

This removes one unnecessary `unsafe` block.
This commit is contained in:
Chayim Refael Friedman 2021-12-30 05:04:44 +02:00 committed by GitHub
parent d331cb710f
commit e86ecdf9fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -102,8 +102,7 @@ impl<T> OnceCell<T> {
/// Returns `None` if the cell is empty. /// Returns `None` if the cell is empty.
#[unstable(feature = "once_cell", issue = "74465")] #[unstable(feature = "once_cell", issue = "74465")]
pub fn get_mut(&mut self) -> Option<&mut T> { pub fn get_mut(&mut self) -> Option<&mut T> {
// SAFETY: Safe because we have unique access self.inner.get_mut().as_mut()
unsafe { &mut *self.inner.get() }.as_mut()
} }
/// Sets the contents of the cell to `value`. /// Sets the contents of the cell to `value`.