about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorEduard Burtescu <edy.burt@gmail.com>2014-02-28 00:02:27 +0200
committerEduard Burtescu <edy.burt@gmail.com>2014-03-13 14:21:45 +0200
commitcdc18b96d6aa38c22b4fa9715c974ef986ad250d (patch)
tree9a0fae0250cb35e67a2f966ed6e17eb0a7afaef1 /src/libstd
parent12b2607572d6233a1d4b4f7592573e49b505771e (diff)
downloadrust-cdc18b96d6aa38c22b4fa9715c974ef986ad250d.tar.gz
rust-cdc18b96d6aa38c22b4fa9715c974ef986ad250d.zip
Remove Rc's borrow method to avoid conflicts with RefCell's borrow in Rc<RefCell<T>>.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/hash/mod.rs3
-rw-r--r--src/libstd/option.rs4
-rw-r--r--src/libstd/rc.rs36
3 files changed, 19 insertions, 24 deletions
diff --git a/src/libstd/hash/mod.rs b/src/libstd/hash/mod.rs
index 6c0ae280ed0..dd40f600873 100644
--- a/src/libstd/hash/mod.rs
+++ b/src/libstd/hash/mod.rs
@@ -66,6 +66,7 @@
 use container::Container;
 use io::Writer;
 use iter::Iterator;
+use ops::Deref;
 use option::{Option, Some, None};
 use rc::Rc;
 use str::{Str, StrSlice};
@@ -246,7 +247,7 @@ impl<S: Writer, T: Hash<S>> Hash<S> for @T {
 impl<S: Writer, T: Hash<S>> Hash<S> for Rc<T> {
     #[inline]
     fn hash(&self, state: &mut S) {
-        self.borrow().hash(state);
+        self.deref().hash(state);
     }
 }
 
diff --git a/src/libstd/option.rs b/src/libstd/option.rs
index 86f8c143a9e..31605ca961e 100644
--- a/src/libstd/option.rs
+++ b/src/libstd/option.rs
@@ -503,7 +503,7 @@ mod tests {
         #[unsafe_destructor]
         impl ::ops::Drop for R {
            fn drop(&mut self) {
-                let ii = self.i.borrow();
+                let ii = self.i.deref();
                 ii.set(ii.get() + 1);
             }
         }
@@ -520,7 +520,7 @@ mod tests {
             let opt = Some(x);
             let _y = opt.unwrap();
         }
-        assert_eq!(i.borrow().get(), 1);
+        assert_eq!(i.deref().get(), 1);
     }
 
     #[test]
diff --git a/src/libstd/rc.rs b/src/libstd/rc.rs
index 8a7edc728c0..5c4b19b4e4b 100644
--- a/src/libstd/rc.rs
+++ b/src/libstd/rc.rs
@@ -63,12 +63,6 @@ impl<T> Rc<T> {
 }
 
 impl<T> Rc<T> {
-    /// Borrow the value contained in the reference-counted box
-    #[inline(always)]
-    pub fn borrow<'a>(&'a self) -> &'a T {
-        unsafe { &(*self.ptr).value }
-    }
-
     /// Downgrade the reference-counted pointer to a weak reference
     pub fn downgrade(&self) -> Weak<T> {
         unsafe {
@@ -93,7 +87,7 @@ impl<T> Drop for Rc<T> {
             if self.ptr != 0 as *mut RcBox<T> {
                 (*self.ptr).strong -= 1;
                 if (*self.ptr).strong == 0 {
-                    ptr::read(self.borrow()); // destroy the contained object
+                    ptr::read(self.deref()); // destroy the contained object
 
                     // remove the implicit "strong weak" pointer now
                     // that we've destroyed the contents.
@@ -120,24 +114,24 @@ impl<T> Clone for Rc<T> {
 
 impl<T: Eq> Eq for Rc<T> {
     #[inline(always)]
-    fn eq(&self, other: &Rc<T>) -> bool { *self.borrow() == *other.borrow() }
+    fn eq(&self, other: &Rc<T>) -> bool { *self.deref() == *other.deref() }
 
     #[inline(always)]
-    fn ne(&self, other: &Rc<T>) -> bool { *self.borrow() != *other.borrow() }
+    fn ne(&self, other: &Rc<T>) -> bool { *self.deref() != *other.deref() }
 }
 
 impl<T: Ord> Ord for Rc<T> {
     #[inline(always)]
-    fn lt(&self, other: &Rc<T>) -> bool { *self.borrow() < *other.borrow() }
+    fn lt(&self, other: &Rc<T>) -> bool { *self.deref() < *other.deref() }
 
     #[inline(always)]
-    fn le(&self, other: &Rc<T>) -> bool { *self.borrow() <= *other.borrow() }
+    fn le(&self, other: &Rc<T>) -> bool { *self.deref() <= *other.deref() }
 
     #[inline(always)]
-    fn gt(&self, other: &Rc<T>) -> bool { *self.borrow() > *other.borrow() }
+    fn gt(&self, other: &Rc<T>) -> bool { *self.deref() > *other.deref() }
 
     #[inline(always)]
-    fn ge(&self, other: &Rc<T>) -> bool { *self.borrow() >= *other.borrow() }
+    fn ge(&self, other: &Rc<T>) -> bool { *self.deref() >= *other.deref() }
 }
 
 /// Weak reference to a reference-counted box
@@ -197,30 +191,30 @@ mod tests {
     fn test_clone() {
         let x = Rc::new(RefCell::new(5));
         let y = x.clone();
-        x.borrow().with_mut(|inner| {
+        x.deref().with_mut(|inner| {
             *inner = 20;
         });
-        assert_eq!(y.borrow().with(|v| *v), 20);
+        assert_eq!(y.deref().with(|v| *v), 20);
     }
 
     #[test]
     fn test_simple() {
         let x = Rc::new(5);
-        assert_eq!(*x.borrow(), 5);
+        assert_eq!(*x.deref(), 5);
     }
 
     #[test]
     fn test_simple_clone() {
         let x = Rc::new(5);
         let y = x.clone();
-        assert_eq!(*x.borrow(), 5);
-        assert_eq!(*y.borrow(), 5);
+        assert_eq!(*x.deref(), 5);
+        assert_eq!(*y.deref(), 5);
     }
 
     #[test]
     fn test_destructor() {
         let x = Rc::new(~5);
-        assert_eq!(**x.borrow(), 5);
+        assert_eq!(**x.deref(), 5);
     }
 
     #[test]
@@ -243,7 +237,7 @@ mod tests {
         // see issue #11532
         use gc::Gc;
         let a = Rc::new(RefCell::new(Gc::new(1)));
-        assert!(a.borrow().try_borrow_mut().is_some());
+        assert!(a.deref().try_borrow_mut().is_some());
     }
 
     #[test]
@@ -254,7 +248,7 @@ mod tests {
 
         let a = Rc::new(Cycle { x: RefCell::new(None) });
         let b = a.clone().downgrade();
-        *a.borrow().x.borrow_mut().get() = Some(b);
+        *a.deref().x.borrow_mut().get() = Some(b);
 
         // hopefully we don't double-free (or leak)...
     }