about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2015-05-28 22:58:04 +0200
committerSimon Sapin <simon.sapin@exyr.org>2015-05-28 23:01:36 +0200
commitc516eee503ae643ead9553fed70528230feb2b1f (patch)
treec00c3b387b0fe64f1406675a1579e67f8995c28f
parent621a10e7f32d790c39a0b4528369cf7959dd7d34 (diff)
downloadrust-c516eee503ae643ead9553fed70528230feb2b1f.tar.gz
rust-c516eee503ae643ead9553fed70528230feb2b1f.zip
Move std::cell::clone_ref to a clone associated function on std::cell::Ref
... and generalize the bounds on the value type.
-rw-r--r--src/libcore/cell.rs23
-rw-r--r--src/libcoretest/cell.rs4
2 files changed, 22 insertions, 5 deletions
diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs
index 4c9f16fdaee..dbb0db33366 100644
--- a/src/libcore/cell.rs
+++ b/src/libcore/cell.rs
@@ -545,13 +545,30 @@ impl<'b, T: ?Sized> Deref for Ref<'b, T> {
 ///
 /// A `Clone` implementation would interfere with the widespread
 /// use of `r.borrow().clone()` to clone the contents of a `RefCell`.
+#[deprecated(since = "1.2.0", reason = "moved to a `Ref::clone` associated function")]
 #[unstable(feature = "core",
            reason = "likely to be moved to a method, pending language changes")]
 #[inline]
 pub fn clone_ref<'b, T:Clone>(orig: &Ref<'b, T>) -> Ref<'b, T> {
-    Ref {
-        _value: orig._value,
-        _borrow: orig._borrow.clone(),
+    Ref::clone(orig)
+}
+
+impl<'b, T: ?Sized> Ref<'b, T> {
+    /// Copies a `Ref`.
+    ///
+    /// The `RefCell` is already immutably borrowed, so this cannot fail.
+    ///
+    /// This is an associated function that needs to be used as `Ref::clone(...)`.
+    /// A `Clone` implementation or a method would interfere with the widespread
+    /// use of `r.borrow().clone()` to clone the contents of a `RefCell`.
+    #[unstable(feature = "cell_extras",
+               reason = "likely to be moved to a method, pending language changes")]
+    #[inline]
+    pub fn clone(orig: &Ref<'b, T>) -> Ref<'b, T> {
+        Ref {
+            _value: orig._value,
+            _borrow: orig._borrow.clone(),
+        }
     }
 }
 
diff --git a/src/libcoretest/cell.rs b/src/libcoretest/cell.rs
index f02312b8641..eae8cd2c0f3 100644
--- a/src/libcoretest/cell.rs
+++ b/src/libcoretest/cell.rs
@@ -115,13 +115,13 @@ fn discard_doesnt_unborrow() {
 }
 
 #[test]
-fn clone_ref_updates_flag() {
+fn ref_clone_updates_flag() {
     let x = RefCell::new(0);
     {
         let b1 = x.borrow();
         assert_eq!(x.borrow_state(), BorrowState::Reading);
         {
-            let _b2 = clone_ref(&b1);
+            let _b2 = Ref::clone(&b1);
             assert_eq!(x.borrow_state(), BorrowState::Reading);
         }
         assert_eq!(x.borrow_state(), BorrowState::Reading);