From 8d7e6ef7725f8a11de940892a74398fc1911dfc7 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 26 Feb 2013 11:32:00 -0800 Subject: libsyntax: Forbid `~mut` and `~const`. rs=demuting --- src/libstd/arc.rs | 7 ++++--- src/libstd/future.rs | 11 +++++------ src/libstd/sync.rs | 11 ++++++----- src/libstd/workcache.rs | 5 +++-- 4 files changed, 18 insertions(+), 16 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/arc.rs b/src/libstd/arc.rs index 61b5ffd845f..f258e649122 100644 --- a/src/libstd/arc.rs +++ b/src/libstd/arc.rs @@ -17,6 +17,7 @@ use sync; use sync::{Mutex, mutex_with_condvars, RWlock, rwlock_with_condvars}; use core::cast; +use core::cell::Cell; use core::pipes; use core::prelude::*; use core::private::{SharedMutableState, shared_mutable_state}; @@ -532,17 +533,17 @@ mod tests { let arc = ~MutexARC(false); let arc2 = ~arc.clone(); let (p,c) = comm::oneshot(); - let (c,p) = (~mut Some(c), ~mut Some(p)); + let (c,p) = (Cell(c), Cell(p)); do task::spawn || { // wait until parent gets in - comm::recv_one(option::swap_unwrap(p)); + comm::recv_one(p.take()); do arc2.access_cond |state, cond| { *state = true; cond.signal(); } } do arc.access_cond |state, cond| { - comm::send_one(option::swap_unwrap(c), ()); + comm::send_one(c.take(), ()); assert !*state; while !*state { cond.wait(); diff --git a/src/libstd/future.rs b/src/libstd/future.rs index b6b001727a4..7f48466ed0a 100644 --- a/src/libstd/future.rs +++ b/src/libstd/future.rs @@ -23,6 +23,7 @@ use core::cast::copy_lifetime; use core::cast; +use core::cell::Cell; use core::either::Either; use core::option; use core::comm::{oneshot, ChanOne, PortOne, send_one, recv_one}; @@ -103,11 +104,9 @@ pub fn from_port(port: PortOne) -> * waiting for the result to be received on the port. */ - let port = ~mut Some(port); + let port = Cell(port); do from_fn || { - let mut port_ = None; - port_ <-> *port; - let port = option::unwrap(port_); + let port = port.take(); match recv(port) { oneshot::send(data) => data } @@ -136,9 +135,9 @@ pub fn spawn(blk: fn~() -> A) -> Future { let (chan, port) = oneshot::init(); - let chan = ~mut Some(chan); + let chan = Cell(chan); do task::spawn || { - let chan = option::swap_unwrap(&mut *chan); + let chan = chan.take(); send_one(chan, blk()); } diff --git a/src/libstd/sync.rs b/src/libstd/sync.rs index 016847a5bfd..1ff51e8bff0 100644 --- a/src/libstd/sync.rs +++ b/src/libstd/sync.rs @@ -15,6 +15,7 @@ * in std. */ +use core::cell::Cell; use core::option; use core::pipes; use core::prelude::*; @@ -799,9 +800,9 @@ mod tests { let s = ~semaphore(1); let s2 = ~s.clone(); let (p,c) = comm::stream(); - let child_data = ~mut Some((s2, c)); + let child_data = Cell((s2, c)); do s.access { - let (s2,c) = option::swap_unwrap(child_data); + let (s2, c) = child_data.take(); do task::spawn || { c.send(()); do s2.access { } @@ -976,13 +977,13 @@ mod tests { let mut sibling_convos = ~[]; for 2.times { let (p,c) = comm::stream(); - let c = ~mut Some(c); + let c = Cell(c); sibling_convos.push(p); let mi = ~m2.clone(); // spawn sibling task - do task::spawn || { // linked + do task::spawn { // linked do mi.lock_cond |cond| { - let c = option::swap_unwrap(c); + let c = c.take(); c.send(()); // tell sibling to go ahead let _z = SendOnFailure(c); cond.wait(); // block forever diff --git a/src/libstd/workcache.rs b/src/libstd/workcache.rs index 8ce68a41f81..d7ca766f183 100644 --- a/src/libstd/workcache.rs +++ b/src/libstd/workcache.rs @@ -15,6 +15,7 @@ use sha1; use serialize::{Encoder, Encodable, Decoder, Decodable}; use sort; +use core::cell::Cell; use core::cmp; use core::either::{Either, Left, Right}; use core::io; @@ -339,11 +340,11 @@ impl TPrep for @Mut { let mut blk = None; blk <-> bo; let blk = blk.unwrap(); - let chan = ~mut Some(chan); + let chan = Cell(chan); do task::spawn || { let exe = Exec{discovered_inputs: LinearMap::new(), discovered_outputs: LinearMap::new()}; - let chan = option::swap_unwrap(&mut *chan); + let chan = chan.take(); let v = blk(&exe); send_one(chan, (exe, v)); } -- cgit 1.4.1-3-g733a5