diff options
| author | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2014-03-28 10:29:55 -0700 |
|---|---|---|
| committer | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2014-04-03 20:28:55 -0700 |
| commit | 7bcfe2ee1067d1304c9a2813c111f10a89984e45 (patch) | |
| tree | a42fc0ceadbf33bdfc722236697b65b9688b817e /src/libstd | |
| parent | bb31cb8d2e4e415cbb71d368918d72902e655e01 (diff) | |
| download | rust-7bcfe2ee1067d1304c9a2813c111f10a89984e45.tar.gz rust-7bcfe2ee1067d1304c9a2813c111f10a89984e45.zip | |
std: Remove `RefCell::get()`
It's surprising that `RefCell::get()` is implicitly doing a clone on a value. This patch removes it and replaces all users with either `.borrow()` when we can autoderef, or `.borrow().clone()` when we cannot.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/cell.rs | 20 | ||||
| -rw-r--r-- | src/libstd/option.rs | 5 |
2 files changed, 7 insertions, 18 deletions
diff --git a/src/libstd/cell.rs b/src/libstd/cell.rs index eb114e89510..ec6994728f7 100644 --- a/src/libstd/cell.rs +++ b/src/libstd/cell.rs @@ -176,21 +176,9 @@ impl<T> RefCell<T> { } } -impl<T:Clone> RefCell<T> { - /// Returns a copy of the contained value. - /// - /// # Failure - /// - /// Fails if the value is currently mutably borrowed. - #[inline] - pub fn get(&self) -> T { - (*self.borrow()).clone() - } -} - impl<T: Clone> Clone for RefCell<T> { fn clone(&self) -> RefCell<T> { - RefCell::new(self.get()) + RefCell::new(self.borrow().clone()) } } @@ -216,7 +204,7 @@ impl<'b, T> Drop for Ref<'b, T> { impl<'b, T> Deref<T> for Ref<'b, T> { #[inline] fn deref<'a>(&'a self) -> &'a T { - unsafe{ &*self.parent.value.get() } + unsafe { &*self.parent.value.get() } } } @@ -236,14 +224,14 @@ impl<'b, T> Drop for RefMut<'b, T> { impl<'b, T> Deref<T> for RefMut<'b, T> { #[inline] fn deref<'a>(&'a self) -> &'a T { - unsafe{ &*self.parent.value.get() } + unsafe { &*self.parent.value.get() } } } impl<'b, T> DerefMut<T> for RefMut<'b, T> { #[inline] fn deref_mut<'a>(&'a mut self) -> &'a mut T { - unsafe{ &mut *self.parent.value.get() } + unsafe { &mut *self.parent.value.get() } } } diff --git a/src/libstd/option.rs b/src/libstd/option.rs index be1c87ba788..ce2c1378fc1 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -651,7 +651,8 @@ mod tests { impl ::ops::Drop for R { fn drop(&mut self) { let ii = &*self.i; - ii.set(ii.get() + 1); + let i = ii.borrow().clone(); + ii.set(i + 1); } } @@ -667,7 +668,7 @@ mod tests { let opt = Some(x); let _y = opt.unwrap(); } - assert_eq!(i.get(), 1); + assert_eq!(*i.borrow(), 1); } #[test] |
