Skip to content

Commit e473e70

Browse files
committed
Stabilize cell
This patch finalizes stabilization for the `cell` module, settling on the current names `Cell`, `RefCell`, `UnsafeCell`, `Ref` and `RefMut`. While we had considered improving these names, no one was able to produce a truly compelling alternative. There is one substantive change here: the `get` method of `UnsafeSell` is now marked `unsafe`. Merely getting a raw pointer to the contents is not, by itself, an unsafe operation. (Consider that you can always safely turn a reference into a raw pointer, and that raw pointer may then be aliased by subsequent references.)
1 parent 1c2df5c commit e473e70

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

src/libcore/cell.rs

+13-19
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ use option::Option;
164164
use option::Option::{None, Some};
165165

166166
/// A mutable memory location that admits only `Copy` data.
167-
#[unstable = "likely to be renamed; otherwise stable"]
167+
#[stable]
168168
pub struct Cell<T> {
169169
value: UnsafeCell<T>,
170170
noshare: marker::NoSync,
@@ -231,7 +231,7 @@ impl<T:PartialEq + Copy> PartialEq for Cell<T> {
231231
}
232232

233233
/// A mutable memory location with dynamically checked borrow rules
234-
#[unstable = "likely to be renamed; otherwise stable"]
234+
#[stable]
235235
pub struct RefCell<T> {
236236
value: UnsafeCell<T>,
237237
borrow: Cell<BorrowFlag>,
@@ -256,7 +256,7 @@ impl<T> RefCell<T> {
256256
}
257257

258258
/// Consumes the `RefCell`, returning the wrapped value.
259-
#[unstable = "recently renamed per RFC 430"]
259+
#[stable]
260260
pub fn into_inner(self) -> T {
261261
// Since this function takes `self` (the `RefCell`) by value, the
262262
// compiler statically verifies that it is not currently borrowed.
@@ -275,7 +275,7 @@ impl<T> RefCell<T> {
275275
/// immutable borrows can be taken out at the same time.
276276
///
277277
/// Returns `None` if the value is currently mutably borrowed.
278-
#[unstable = "may be renamed, depending on global conventions"]
278+
#[unstable = "may be renamed or removed"]
279279
pub fn try_borrow<'a>(&'a self) -> Option<Ref<'a, T>> {
280280
match BorrowRef::new(&self.borrow) {
281281
Some(b) => Some(Ref { _value: unsafe { &*self.value.get() }, _borrow: b }),
@@ -291,7 +291,7 @@ impl<T> RefCell<T> {
291291
/// # Panics
292292
///
293293
/// Panics if the value is currently mutably borrowed.
294-
#[unstable]
294+
#[stable]
295295
pub fn borrow<'a>(&'a self) -> Ref<'a, T> {
296296
match self.try_borrow() {
297297
Some(ptr) => ptr,
@@ -305,7 +305,7 @@ impl<T> RefCell<T> {
305305
/// cannot be borrowed while this borrow is active.
306306
///
307307
/// Returns `None` if the value is currently borrowed.
308-
#[unstable = "may be renamed, depending on global conventions"]
308+
#[unstable = "may be renamed or removed"]
309309
pub fn try_borrow_mut<'a>(&'a self) -> Option<RefMut<'a, T>> {
310310
match BorrowRefMut::new(&self.borrow) {
311311
Some(b) => Some(RefMut { _value: unsafe { &mut *self.value.get() }, _borrow: b }),
@@ -321,7 +321,7 @@ impl<T> RefCell<T> {
321321
/// # Panics
322322
///
323323
/// Panics if the value is currently borrowed.
324-
#[unstable]
324+
#[stable]
325325
pub fn borrow_mut<'a>(&'a self) -> RefMut<'a, T> {
326326
match self.try_borrow_mut() {
327327
Some(ptr) => ptr,
@@ -400,7 +400,7 @@ impl<'b> Clone for BorrowRef<'b> {
400400
}
401401

402402
/// Wraps a borrowed reference to a value in a `RefCell` box.
403-
#[unstable]
403+
#[stable]
404404
pub struct Ref<'b, T:'b> {
405405
// FIXME #12808: strange name to try to avoid interfering with
406406
// field accesses of the contained type via Deref
@@ -456,7 +456,7 @@ impl<'b> BorrowRefMut<'b> {
456456
}
457457

458458
/// Wraps a mutable borrowed reference to a value in a `RefCell` box.
459-
#[unstable]
459+
#[stable]
460460
pub struct RefMut<'b, T:'b> {
461461
// FIXME #12808: strange name to try to avoid interfering with
462462
// field accesses of the contained type via Deref
@@ -517,7 +517,7 @@ impl<'b, T> DerefMut<T> for RefMut<'b, T> {
517517
/// is not recommended to access its fields directly, `get` should be used
518518
/// instead.
519519
#[lang="unsafe"]
520-
#[unstable = "this type may be renamed in the future"]
520+
#[stable]
521521
pub struct UnsafeCell<T> {
522522
/// Wrapped value
523523
///
@@ -539,22 +539,16 @@ impl<T> UnsafeCell<T> {
539539
}
540540

541541
/// Gets a mutable pointer to the wrapped value.
542-
///
543-
/// This function is unsafe as the pointer returned is an unsafe pointer and
544-
/// no guarantees are made about the aliasing of the pointers being handed
545-
/// out in this or other tasks.
546542
#[inline]
547-
#[unstable = "conventions around acquiring an inner reference are still \
548-
under development"]
549-
pub unsafe fn get(&self) -> *mut T { &self.value as *const T as *mut T }
543+
#[stable]
544+
pub fn get(&self) -> *mut T { &self.value as *const T as *mut T }
550545

551546
/// Unwraps the value
552547
///
553548
/// This function is unsafe because there is no guarantee that this or other
554549
/// tasks are currently inspecting the inner value.
555550
#[inline]
556-
#[unstable = "conventions around the name `unwrap` are still under \
557-
development"]
551+
#[stable]
558552
pub unsafe fn into_inner(self) -> T { self.value }
559553

560554
/// Deprecated, use into_inner() instead

0 commit comments

Comments
 (0)