X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibcore%2Fcell.rs;h=2af48ef2fabe3b42d04cfa53bb4bd565259f538b;hb=43204fff5d0a656f8a94bfff3129e04bc9d30ad4;hp=17ec325e257b028f43ca709041f1769829309500;hpb=f65d96fe3fa3cfae2cfc88be40f7416a22c88bf2;p=rust.git diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 17ec325e257..2af48ef2fab 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -233,10 +233,28 @@ pub fn set(&self, value: T) { /// ``` #[inline] #[unstable(feature = "as_unsafe_cell", issue = "27708")] + #[rustc_deprecated(since = "1.12.0", reason = "renamed to as_ptr")] pub fn as_unsafe_cell(&self) -> &UnsafeCell { &self.value } + /// Returns a raw pointer to the underlying data in this cell. + /// + /// # Examples + /// + /// ``` + /// use std::cell::Cell; + /// + /// let c = Cell::new(5); + /// + /// let ptr = c.as_ptr(); + /// ``` + #[inline] + #[stable(feature = "cell_as_ptr", since = "1.12.0")] + pub fn as_ptr(&self) -> *mut T { + self.value.get() + } + /// Returns a mutable reference to the underlying data. /// /// This call borrows `Cell` mutably (at compile-time) which guarantees @@ -337,6 +355,9 @@ fn from(t: T) -> Cell { } } +#[unstable(feature = "coerce_unsized", issue = "27732")] +impl, U> CoerceUnsized> for Cell {} + /// A mutable memory location with dynamically checked borrow rules /// /// See the [module-level documentation](index.html) for more. @@ -653,10 +674,28 @@ pub fn try_borrow_mut(&self) -> Result, BorrowMutError> { /// ``` #[inline] #[unstable(feature = "as_unsafe_cell", issue = "27708")] + #[rustc_deprecated(since = "1.12.0", reason = "renamed to as_ptr")] pub unsafe fn as_unsafe_cell(&self) -> &UnsafeCell { &self.value } + /// Returns a raw pointer to the underlying data in this cell. + /// + /// # Examples + /// + /// ``` + /// use std::cell::RefCell; + /// + /// let c = RefCell::new(5); + /// + /// let ptr = c.as_ptr(); + /// ``` + #[inline] + #[stable(feature = "cell_as_ptr", since = "1.12.0")] + pub fn as_ptr(&self) -> *mut T { + self.value.get() + } + /// Returns a mutable reference to the underlying data. /// /// This call borrows `RefCell` mutably (at compile-time) so there is no @@ -757,6 +796,9 @@ fn from(t: T) -> RefCell { } } +#[unstable(feature = "coerce_unsized", issue = "27732")] +impl, U> CoerceUnsized> for RefCell {} + struct BorrowRef<'b> { borrow: &'b Cell, } @@ -1086,3 +1128,13 @@ fn from(t: T) -> UnsafeCell { UnsafeCell::new(t) } } + +#[unstable(feature = "coerce_unsized", issue = "27732")] +impl, U> CoerceUnsized> for UnsafeCell {} + +#[allow(unused)] +fn assert_coerce_unsized(a: UnsafeCell<&i32>, b: Cell<&i32>, c: RefCell<&i32>) { + let _: UnsafeCell<&Send> = a; + let _: Cell<&Send> = b; + let _: RefCell<&Send> = c; +}