diff options
| author | bors <bors@rust-lang.org> | 2014-03-22 04:56:49 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-03-22 04:56:49 -0700 |
| commit | 30165e059c0a111a53020108686b6fd11fcc1d03 (patch) | |
| tree | 01b0aed8f6ae7a510cf52699b0dea7b1143b2688 /src/libstd | |
| parent | 092afdba3c81d122b4b24aa49dd445023b5daef6 (diff) | |
| parent | 1d98fe12a8b2ad954f01935552d23643e96a53af (diff) | |
| download | rust-30165e059c0a111a53020108686b6fd11fcc1d03.tar.gz rust-30165e059c0a111a53020108686b6fd11fcc1d03.zip | |
auto merge of #13052 : sfackler/rust/clean-refcell, r=alexcrichton
These are superfluous now that we have fixed rvalue lifetimes and Deref. I'd also like to kill off `get` and `set`, but that'll be a large change so I want to make sure that we actually want to do that first.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/cell.rs | 87 | ||||
| -rw-r--r-- | src/libstd/gc.rs | 6 | ||||
| -rw-r--r-- | src/libstd/rc.rs | 6 |
3 files changed, 16 insertions, 83 deletions
diff --git a/src/libstd/cell.rs b/src/libstd/cell.rs index 5733504c0d1..b54396efec5 100644 --- a/src/libstd/cell.rs +++ b/src/libstd/cell.rs @@ -22,19 +22,17 @@ use ty::Unsafe; /// A mutable memory location that admits only `Pod` data. pub struct Cell<T> { priv value: Unsafe<T>, - priv marker1: marker::InvariantType<T>, - priv marker2: marker::NoFreeze, - priv marker3: marker::NoShare, + priv marker1: marker::NoFreeze, + priv marker2: marker::NoShare, } impl<T:Pod> Cell<T> { /// Creates a new `Cell` containing the given value. pub fn new(value: T) -> Cell<T> { Cell { - value: Unsafe{value: value, marker1: marker::InvariantType::<T>}, - marker1: marker::InvariantType::<T>, - marker2: marker::NoFreeze, - marker3: marker::NoShare, + value: Unsafe::new(value), + marker1: marker::NoFreeze, + marker2: marker::NoShare, } } @@ -75,10 +73,9 @@ impl<T: fmt::Show> fmt::Show for Cell<T> { pub struct RefCell<T> { priv value: Unsafe<T>, priv borrow: BorrowFlag, - priv marker1: marker::InvariantType<T>, - priv marker2: marker::NoFreeze, - priv marker3: marker::NoPod, - priv marker4: marker::NoShare, + priv marker1: marker::NoFreeze, + priv marker2: marker::NoPod, + priv marker3: marker::NoShare, } // Values [1, MAX-1] represent the number of `Ref` active @@ -91,11 +88,10 @@ impl<T> RefCell<T> { /// Create a new `RefCell` containing `value` pub fn new(value: T) -> RefCell<T> { RefCell { - marker1: marker::InvariantType::<T>, - marker2: marker::NoFreeze, - marker3: marker::NoPod, - marker4: marker::NoShare, - value: Unsafe{value: value, marker1: marker::InvariantType::<T>}, + marker1: marker::NoFreeze, + marker2: marker::NoPod, + marker3: marker::NoShare, + value: Unsafe::new(value), borrow: UNUSED, } } @@ -173,28 +169,6 @@ impl<T> RefCell<T> { } } - /// Immutably borrows the wrapped value and applies `blk` to it. - /// - /// # Failure - /// - /// Fails if the value is currently mutably borrowed. - #[inline] - pub fn with<U>(&self, blk: |&T| -> U) -> U { - let ptr = self.borrow(); - blk(ptr.get()) - } - - /// Mutably borrows the wrapped value and applies `blk` to it. - /// - /// # Failure - /// - /// Fails if the value is currently borrowed. - #[inline] - pub fn with_mut<U>(&self, blk: |&mut T| -> U) -> U { - let mut ptr = self.borrow_mut(); - blk(ptr.get()) - } - /// Sets the value, replacing what was there. /// /// # Failure @@ -373,43 +347,6 @@ mod test { } #[test] - fn with_ok() { - let x = RefCell::new(0); - assert_eq!(1, x.with(|x| *x+1)); - } - - #[test] - #[should_fail] - fn mut_borrow_with() { - let x = RefCell::new(0); - let _b1 = x.borrow_mut(); - x.with(|x| *x+1); - } - - #[test] - fn borrow_with() { - let x = RefCell::new(0); - let _b1 = x.borrow(); - assert_eq!(1, x.with(|x| *x+1)); - } - - #[test] - fn with_mut_ok() { - let x = RefCell::new(0); - x.with_mut(|x| *x += 1); - let b = x.borrow(); - assert_eq!(1, *b.get()); - } - - #[test] - #[should_fail] - fn borrow_with_mut() { - let x = RefCell::new(0); - let _b = x.borrow(); - x.with_mut(|x| *x += 1); - } - - #[test] #[should_fail] fn discard_doesnt_unborrow() { let x = RefCell::new(0); diff --git a/src/libstd/gc.rs b/src/libstd/gc.rs index 907a2d21b69..7fb23d77f3c 100644 --- a/src/libstd/gc.rs +++ b/src/libstd/gc.rs @@ -87,10 +87,8 @@ mod tests { fn test_clone() { let x = Gc::new(RefCell::new(5)); let y = x.clone(); - x.borrow().with_mut(|inner| { - *inner = 20; - }); - assert_eq!(y.borrow().with(|x| *x), 20); + *x.borrow().borrow_mut() = 20; + assert_eq!(*y.borrow().borrow(), 20); } #[test] diff --git a/src/libstd/rc.rs b/src/libstd/rc.rs index dcf4d31c308..03be4fea5ee 100644 --- a/src/libstd/rc.rs +++ b/src/libstd/rc.rs @@ -229,10 +229,8 @@ mod tests { fn test_clone() { let x = Rc::new(RefCell::new(5)); let y = x.clone(); - x.deref().with_mut(|inner| { - *inner = 20; - }); - assert_eq!(y.deref().with(|v| *v), 20); + *x.borrow_mut() = 20; + assert_eq!(*y.borrow(), 20); } #[test] |
