From 51a2e2fd826c82252d101ad1e1904319699e417e Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 13 Feb 2017 19:50:54 +0100 Subject: [PATCH 1/2] Allow more Cell methods for non-Copy types Contributes to #39264 --- src/libcore/cell.rs | 120 ++++++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index ab44342ebf0..1570428cf18 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -212,66 +212,6 @@ impl Cell { pub fn get(&self) -> T { unsafe{ *self.value.get() } } - - /// Returns a reference to the underlying `UnsafeCell`. - /// - /// # Examples - /// - /// ``` - /// #![feature(as_unsafe_cell)] - /// - /// use std::cell::Cell; - /// - /// let c = Cell::new(5); - /// - /// let uc = c.as_unsafe_cell(); - /// ``` - #[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 - /// that we possess the only reference. - /// - /// # Examples - /// - /// ``` - /// use std::cell::Cell; - /// - /// let mut c = Cell::new(5); - /// *c.get_mut() += 1; - /// - /// assert_eq!(c.get(), 6); - /// ``` - #[inline] - #[stable(feature = "cell_get_mut", since = "1.11.0")] - pub fn get_mut(&mut self) -> &mut T { - unsafe { - &mut *self.value.get() - } - } } #[stable(feature = "rust1", since = "1.0.0")] @@ -369,6 +309,66 @@ impl Cell { } } + /// Returns a reference to the underlying `UnsafeCell`. + /// + /// # Examples + /// + /// ``` + /// #![feature(as_unsafe_cell)] + /// + /// use std::cell::Cell; + /// + /// let c = Cell::new(5); + /// + /// let uc = c.as_unsafe_cell(); + /// ``` + #[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 + /// that we possess the only reference. + /// + /// # Examples + /// + /// ``` + /// use std::cell::Cell; + /// + /// let mut c = Cell::new(5); + /// *c.get_mut() += 1; + /// + /// assert_eq!(c.get(), 6); + /// ``` + #[inline] + #[stable(feature = "cell_get_mut", since = "1.11.0")] + pub fn get_mut(&mut self) -> &mut T { + unsafe { + &mut *self.value.get() + } + } + /// Sets the contained value. /// /// # Examples From 044ed10fee3351da2315d5d8e26949929ad918ce Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 14 Feb 2017 09:46:03 +0100 Subject: [PATCH 2/2] Remove Copy bound from some Cell trait impls Contributes to #39264 --- src/libcore/cell.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 1570428cf18..2b4ce3a35fc 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -229,7 +229,7 @@ impl Clone for Cell { } #[stable(feature = "rust1", since = "1.0.0")] -impl Default for Cell { +impl Default for Cell { /// Creates a `Cell`, with the `Default` value for T. #[inline] fn default() -> Cell { @@ -285,7 +285,7 @@ impl Ord for Cell { } #[stable(feature = "cell_from", since = "1.12.0")] -impl From for Cell { +impl From for Cell { fn from(t: T) -> Cell { Cell::new(t) }