diff options
| author | bors <bors@rust-lang.org> | 2014-04-04 08:41:50 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-04-04 08:41:50 -0700 |
| commit | eae265271089011c309ce6b8386bdd98f29f2aaf (patch) | |
| tree | 9092c1bd9f73378c6ba3797011701220caf7f0b9 /src/libstd | |
| parent | 46e6194ee138b09d7376fa3dcdb539cf41dc68dd (diff) | |
| parent | 1b6997d0692e743066dfc40e7ab4b65f8ed2e7fd (diff) | |
| download | rust-eae265271089011c309ce6b8386bdd98f29f2aaf.tar.gz rust-eae265271089011c309ce6b8386bdd98f29f2aaf.zip | |
auto merge of #13301 : erickt/rust/remove-refcell-get, r=huonw
`RefCell::get` can be a bit surprising, because it actually clones the wrapped value. This removes `RefCell::get` and replaces all the users with `RefCell::borrow()` when it can, and `RefCell::borrow().clone()` when it can't. It removes `RefCell::set` for consistency. This closes #13182. It also fixes an infinite loop in a test when debugging is on.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/cell.rs | 30 | ||||
| -rw-r--r-- | src/libstd/option.rs | 5 |
2 files changed, 7 insertions, 28 deletions
diff --git a/src/libstd/cell.rs b/src/libstd/cell.rs index eb114e89510..40c6c3ebccf 100644 --- a/src/libstd/cell.rs +++ b/src/libstd/cell.rs @@ -164,33 +164,11 @@ impl<T> RefCell<T> { None => fail!("RefCell<T> already borrowed") } } - - /// Sets the value, replacing what was there. - /// - /// # Failure - /// - /// Fails if the value is currently borrowed. - #[inline] - pub fn set(&self, value: T) { - *self.borrow_mut() = value; - } -} - -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 +194,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 +214,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..ca1ea0169e6 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.borrow_mut() = 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] |
