Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make UnsafeCell::into_inner safe #47204

Merged
merged 1 commit into from
Jan 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ impl<T> Cell<T> {
/// ```
#[stable(feature = "move_cell", since = "1.17.0")]
pub fn into_inner(self) -> T {
unsafe { self.value.into_inner() }
self.value.into_inner()
}
}

Expand Down Expand Up @@ -569,7 +569,7 @@ impl<T> RefCell<T> {
// compiler statically verifies that it is not currently borrowed.
// Therefore the following assertion is just a `debug_assert!`.
debug_assert!(self.borrow.get() == UNUSED);
unsafe { self.value.into_inner() }
self.value.into_inner()
}

/// Replaces the wrapped value with a new one, returning the old value,
Expand Down Expand Up @@ -1220,23 +1220,18 @@ impl<T> UnsafeCell<T> {

/// Unwraps the value.
///
/// # Safety
///
/// This function is unsafe because this thread or another thread may currently be
/// inspecting the inner value.
///
/// # Examples
///
/// ```
/// use std::cell::UnsafeCell;
///
/// let uc = UnsafeCell::new(5);
///
/// let five = unsafe { uc.into_inner() };
/// let five = uc.into_inner();
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub unsafe fn into_inner(self) -> T {
pub fn into_inner(self) -> T {
self.value
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/sync/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ impl AtomicBool {
#[inline]
#[stable(feature = "atomic_access", since = "1.15.0")]
pub fn into_inner(self) -> bool {
unsafe { self.v.into_inner() != 0 }
self.v.into_inner() != 0
}

/// Loads a value from the bool.
Expand Down Expand Up @@ -695,7 +695,7 @@ impl<T> AtomicPtr<T> {
#[inline]
#[stable(feature = "atomic_access", since = "1.15.0")]
pub fn into_inner(self) -> *mut T {
unsafe { self.p.into_inner() }
self.p.into_inner()
}

/// Loads a value from the pointer.
Expand Down Expand Up @@ -1050,7 +1050,7 @@ macro_rules! atomic_int {
#[inline]
#[$stable_access]
pub fn into_inner(self) -> $int_type {
unsafe { self.v.into_inner() }
self.v.into_inner()
}

/// Loads a value from the atomic integer.
Expand Down