diff options
| author | Daniel Micay <danielmicay@gmail.com> | 2013-09-20 02:08:47 -0400 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2013-10-09 09:17:29 -0400 |
| commit | 6a90e80b6240d8213f2b99fa470ef6ee04552d1b (patch) | |
| tree | e7ae38c849741fc9345652311dfa374f36b4be9a /src/libstd | |
| parent | f647ccc79c38c1f80dbdb697900b2ba97e293263 (diff) | |
| download | rust-6a90e80b6240d8213f2b99fa470ef6ee04552d1b.tar.gz rust-6a90e80b6240d8213f2b99fa470ef6ee04552d1b.zip | |
option: rewrite the API to use composition
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/condition.rs | 2 | ||||
| -rw-r--r-- | src/libstd/hashmap.rs | 4 | ||||
| -rw-r--r-- | src/libstd/iter.rs | 16 | ||||
| -rw-r--r-- | src/libstd/local_data.rs | 12 | ||||
| -rw-r--r-- | src/libstd/option.rs | 83 | ||||
| -rw-r--r-- | src/libstd/os.rs | 2 | ||||
| -rw-r--r-- | src/libstd/rand/mod.rs | 2 | ||||
| -rw-r--r-- | src/libstd/rt/args.rs | 4 | ||||
| -rw-r--r-- | src/libstd/rt/comm.rs | 6 | ||||
| -rw-r--r-- | src/libstd/rt/io/net/ip.rs | 10 | ||||
| -rw-r--r-- | src/libstd/rt/io/process.rs | 2 | ||||
| -rw-r--r-- | src/libstd/rt/io/timer.rs | 2 | ||||
| -rw-r--r-- | src/libstd/rt/kill.rs | 14 | ||||
| -rw-r--r-- | src/libstd/rt/sched.rs | 2 | ||||
| -rw-r--r-- | src/libstd/rt/task.rs | 4 | ||||
| -rw-r--r-- | src/libstd/rt/uv/process.rs | 2 | ||||
| -rw-r--r-- | src/libstd/rt/uv/uvio.rs | 6 | ||||
| -rw-r--r-- | src/libstd/str.rs | 6 | ||||
| -rw-r--r-- | src/libstd/sys.rs | 2 | ||||
| -rw-r--r-- | src/libstd/task/spawn.rs | 16 | ||||
| -rw-r--r-- | src/libstd/trie.rs | 2 |
21 files changed, 82 insertions, 117 deletions
diff --git a/src/libstd/condition.rs b/src/libstd/condition.rs index 77f8cb937fa..7828fa09d97 100644 --- a/src/libstd/condition.rs +++ b/src/libstd/condition.rs @@ -106,7 +106,7 @@ impl<T, U> Condition<T, U> { /// ``` pub fn trap<'a>(&'a self, h: &'a fn(T) -> U) -> Trap<'a, T, U> { let h: Closure = unsafe { ::cast::transmute(h) }; - let prev = local_data::get(self.key, |k| k.map(|&x| *x)); + let prev = local_data::get(self.key, |k| k.map(|x| *x)); let h = @Handler { handle: h, prev: prev }; Trap { cond: self, handler: h } } diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index 7b18bed0098..7816480efab 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -239,7 +239,7 @@ impl<K:Hash + Eq,V> HashMap<K, V> { let len_buckets = self.buckets.len(); let bucket = self.buckets[idx].take(); - let value = do bucket.map_move |bucket| { + let value = do bucket.map |bucket| { bucket.value }; @@ -480,7 +480,7 @@ impl<K: Hash + Eq, V> HashMap<K, V> { impl<K: Hash + Eq, V: Clone> HashMap<K, V> { /// Like `find`, but returns a copy of the value. pub fn find_copy(&self, k: &K) -> Option<V> { - self.find(k).map_move(|v| (*v).clone()) + self.find(k).map(|v| (*v).clone()) } /// Like `get`, but returns a copy of the value. diff --git a/src/libstd/iter.rs b/src/libstd/iter.rs index 5b7753a337c..08298889101 100644 --- a/src/libstd/iter.rs +++ b/src/libstd/iter.rs @@ -617,7 +617,7 @@ pub trait Iterator<A> { Some((y, y_val)) } } - }).map_move(|(x, _)| x) + }).map(|(x, _)| x) } /// Return the element that gives the minimum value from the @@ -641,7 +641,7 @@ pub trait Iterator<A> { Some((y, y_val)) } } - }).map_move(|(x, _)| x) + }).map(|(x, _)| x) } } @@ -1550,8 +1550,8 @@ impl<'self, A, T: Iterator<A>, B, U: Iterator<B>> Iterator<B> for FlatMap<'self, return Some(x) } } - match self.iter.next().map_move(|x| (self.f)(x)) { - None => return self.backiter.and_then_mut_ref(|it| it.next()), + match self.iter.next().map(|x| (self.f)(x)) { + None => return self.backiter.as_mut().and_then(|it| it.next()), next => self.frontiter = next, } } @@ -1559,8 +1559,8 @@ impl<'self, A, T: Iterator<A>, B, U: Iterator<B>> Iterator<B> for FlatMap<'self, #[inline] fn size_hint(&self) -> (uint, Option<uint>) { - let (flo, fhi) = self.frontiter.map_default((0, Some(0)), |it| it.size_hint()); - let (blo, bhi) = self.backiter.map_default((0, Some(0)), |it| it.size_hint()); + let (flo, fhi) = self.frontiter.as_ref().map_default((0, Some(0)), |it| it.size_hint()); + let (blo, bhi) = self.backiter.as_ref().map_default((0, Some(0)), |it| it.size_hint()); let lo = flo.saturating_add(blo); match (self.iter.size_hint(), fhi, bhi) { ((0, Some(0)), Some(a), Some(b)) => (lo, a.checked_add(&b)), @@ -1582,8 +1582,8 @@ impl<'self, y => return y } } - match self.iter.next_back().map_move(|x| (self.f)(x)) { - None => return self.frontiter.and_then_mut_ref(|it| it.next_back()), + match self.iter.next_back().map(|x| (self.f)(x)) { + None => return self.frontiter.as_mut().and_then(|it| it.next_back()), next => self.backiter = next, } } diff --git a/src/libstd/local_data.rs b/src/libstd/local_data.rs index c4d0523fdf4..64f02539d0f 100644 --- a/src/libstd/local_data.rs +++ b/src/libstd/local_data.rs @@ -355,16 +355,16 @@ mod tests { set(my_key, @~"parent data"); do task::spawn { // TLS shouldn't carry over. - assert!(get(my_key, |k| k.map_move(|k| *k)).is_none()); + assert!(get(my_key, |k| k.map(|k| *k)).is_none()); set(my_key, @~"child data"); - assert!(*(get(my_key, |k| k.map_move(|k| *k)).unwrap()) == + assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) == ~"child data"); // should be cleaned up for us } // Must work multiple times - assert!(*(get(my_key, |k| k.map_move(|k| *k)).unwrap()) == ~"parent data"); - assert!(*(get(my_key, |k| k.map_move(|k| *k)).unwrap()) == ~"parent data"); - assert!(*(get(my_key, |k| k.map_move(|k| *k)).unwrap()) == ~"parent data"); + assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) == ~"parent data"); + assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) == ~"parent data"); + assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) == ~"parent data"); } #[test] @@ -372,7 +372,7 @@ mod tests { static my_key: Key<@~str> = &Key; set(my_key, @~"first data"); set(my_key, @~"next data"); // Shouldn't leak. - assert!(*(get(my_key, |k| k.map_move(|k| *k)).unwrap()) == ~"next data"); + assert!(*(get(my_key, |k| k.map(|k| *k)).unwrap()) == ~"next data"); } #[test] diff --git a/src/libstd/option.rs b/src/libstd/option.rs index 5c7ae63d391..cdff32a46dc 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -96,6 +96,30 @@ impl<T: ToStr> ToStr for Option<T> { } impl<T> Option<T> { + /// Convert from `Option<T>` to `Option<&T>` + #[inline] + pub fn as_ref<'r>(&'r self) -> Option<&'r T> { + match *self { Some(ref x) => Some(x), None => None } + } + + /// Convert from `Option<T>` to `Option<&mut T>` + #[inline] + pub fn as_mut<'r>(&'r mut self) -> Option<&'r mut T> { + match *self { Some(ref mut x) => Some(x), None => None } + } + + /// Maps an `Option<T>` to `Option<U>` by applying a function to a contained value. + #[inline] + pub fn map<U>(self, f: &fn(T) -> U) -> Option<U> { + match self { Some(x) => Some(f(x)), None => None } + } + + /// Applies a function to the contained value or returns a default. + #[inline] + pub fn map_default<U>(self, def: U, f: &fn(T) -> U) -> U { + match self { None => def, Some(t) => f(t) } + } + /// Return an iterator over the possibly contained value #[inline] pub fn iter<'r>(&'r self) -> OptionIterator<&'r T> { @@ -149,26 +173,6 @@ impl<T> Option<T> { } } - /// Returns `None` if the option is `None`, otherwise calls `f` with a - /// reference to the wrapped value and returns the result. - #[inline] - pub fn and_then_ref<'a, U>(&'a self, f: &fn(&'a T) -> Option<U>) -> Option<U> { - match *self { - Some(ref x) => f(x), - None => None - } - } - - /// Returns `None` if the option is `None`, otherwise calls `f` with a - /// mutable reference to the wrapped value and returns the result. - #[inline] - pub fn and_then_mut_ref<'a, U>(&'a mut self, f: &fn(&'a mut T) -> Option<U>) -> Option<U> { - match *self { - Some(ref mut x) => f(x), - None => None - } - } - /// Returns the option if it contains a value, otherwise returns `optb`. #[inline] pub fn or(self, optb: Option<T>) -> Option<T> { @@ -197,45 +201,6 @@ impl<T> Option<T> { } } - /// Maps a `Some` value from one type to another by reference - #[inline] - pub fn map<'a, U>(&'a self, f: &fn(&'a T) -> U) -> Option<U> { - match *self { Some(ref x) => Some(f(x)), None => None } - } - - /// Maps a `Some` value from one type to another by a mutable reference - #[inline] - pub fn map_mut<'a, U>(&'a mut self, f: &fn(&'a mut T) -> U) -> Option<U> { - match *self { Some(ref mut x) => Some(f(x)), None => None } - } - - /// Applies a function to the contained value or returns a default - #[inline] - pub fn map_default<'a, U>(&'a self, def: U, f: &fn(&'a T) -> U) -> U { - match *self { None => def, Some(ref t) => f(t) } - } - - /// Maps a `Some` value from one type to another by a mutable reference, - /// or returns a default value. - #[inline] - pub fn map_mut_default<'a, U>(&'a mut self, def: U, f: &fn(&'a mut T) -> U) -> U { - match *self { Some(ref mut x) => f(x), None => def } - } - - /// As `map`, but consumes the option and gives `f` ownership to avoid - /// copying. - #[inline] - pub fn map_move<U>(self, f: &fn(T) -> U) -> Option<U> { - match self { Some(x) => Some(f(x)), None => None } - } - - /// As `map_default`, but consumes the option and gives `f` - /// ownership to avoid copying. - #[inline] - pub fn map_move_default<U>(self, def: U, f: &fn(T) -> U) -> U { - match self { None => def, Some(t) => f(t) } - } - /// Take the value out of the option, leaving a `None` in its place. #[inline] pub fn take(&mut self) -> Option<T> { diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 7b9bb249a3c..4de7f32248d 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -514,7 +514,7 @@ pub fn self_exe_path() -> Option<Path> { } } - load_self().map_move(|path| Path(path).dir_path()) + load_self().map(|path| Path(path).dir_path()) } diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index 9b757092266..545c7698e73 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -689,7 +689,7 @@ local_data_key!(TASK_RNG_KEY: @mut TaskRng) /// the same sequence always. If absolute consistency is required, /// explicitly select an RNG, e.g. `IsaacRng` or `Isaac64Rng`. pub fn task_rng() -> @mut TaskRng { - let r = local_data::get(TASK_RNG_KEY, |k| k.map(|&k| *k)); + let r = local_data::get(TASK_RNG_KEY, |k| k.map(|k| *k)); match r { None => { let rng = @mut reseeding::ReseedingRng::new(StdRng::new(), diff --git a/src/libstd/rt/args.rs b/src/libstd/rt/args.rs index 100ea3e0546..315de4b9af3 100644 --- a/src/libstd/rt/args.rs +++ b/src/libstd/rt/args.rs @@ -74,7 +74,7 @@ mod imp { with_lock(|| unsafe { let ptr = get_global_ptr(); let val = util::replace(&mut *ptr, None); - val.map(|s: &~~[~str]| (**s).clone()) + val.as_ref().map(|s: &~~[~str]| (**s).clone()) }) } @@ -89,7 +89,7 @@ mod imp { pub fn clone() -> Option<~[~str]> { with_lock(|| unsafe { let ptr = get_global_ptr(); - (*ptr).map(|s: &~~[~str]| (**s).clone()) + (*ptr).as_ref().map(|s: &~~[~str]| (**s).clone()) }) } diff --git a/src/libstd/rt/comm.rs b/src/libstd/rt/comm.rs index 7d61b556bb5..3e3431b32c9 100644 --- a/src/libstd/rt/comm.rs +++ b/src/libstd/rt/comm.rs @@ -165,7 +165,7 @@ impl<T> ChanOne<T> { // Port is blocked. Wake it up. let recvr = BlockedTask::cast_from_uint(task_as_state); if do_resched { - do recvr.wake().map_move |woken_task| { + do recvr.wake().map |woken_task| { Scheduler::run_task(woken_task); }; } else { @@ -391,7 +391,7 @@ impl<T> Drop for ChanOne<T> { // The port is blocked waiting for a message we will never send. Wake it. rtassert!((*this.packet()).payload.is_none()); let recvr = BlockedTask::cast_from_uint(task_as_state); - do recvr.wake().map_move |woken_task| { + do recvr.wake().map |woken_task| { Scheduler::run_task(woken_task); }; } @@ -501,7 +501,7 @@ impl<T> GenericPort<T> for Port<T> { } fn try_recv(&self) -> Option<T> { - do self.next.take_opt().map_move_default(None) |pone| { + do self.next.take_opt().map_default(None) |pone| { match pone.try_recv() { Some(StreamPayload { val, next }) => { self.next.put_back(next); diff --git a/src/libstd/rt/io/net/ip.rs b/src/libstd/rt/io/net/ip.rs index 6a6619cc548..f72d2e1f19b 100644 --- a/src/libstd/rt/io/net/ip.rs +++ b/src/libstd/rt/io/net/ip.rs @@ -203,7 +203,7 @@ impl<'self> Parser<'self> { return None; } - let octet = self.read_number(10, 3, 0x100).map(|&n| n as u8); + let octet = self.read_number(10, 3, 0x100).map(|n| n as u8); match octet { Some(d) => bs[i] = d, None => return None, @@ -252,7 +252,7 @@ impl<'self> Parser<'self> { let group = do p.read_atomically |p| { if i == 0 || p.read_given_char(':').is_some() { - p.read_number(16, 4, 0x10000).map(|&n| n as u16) + p.read_number(16, 4, 0x10000).map(|n| n as u16) } else { None } @@ -310,16 +310,16 @@ impl<'self> Parser<'self> { let ip_addr = |p: &mut Parser| p.read_ipv6_addr(); let clos_br = |p: &mut Parser| p.read_given_char(']'); p.read_seq_3::<char, IpAddr, char>(open_br, ip_addr, clos_br) - .map(|&t| match t { (_, ip, _) => ip }) + .map(|t| match t { (_, ip, _) => ip }) }; p.read_or([ipv4_p, ipv6_p]) }; let colon = |p: &mut Parser| p.read_given_char(':'); - let port = |p: &mut Parser| p.read_number(10, 5, 0x10000).map(|&n| n as u16); + let port = |p: &mut Parser| p.read_number(10, 5, 0x10000).map(|n| n as u16); // host, colon, port self.read_seq_3::<IpAddr, char, u16>(ip_addr, colon, port) - .map(|&t| match t { (ip, _, port) => SocketAddr { ip: ip, port: port } }) + .map(|t| match t { (ip, _, port) => SocketAddr { ip: ip, port: port } }) } } diff --git a/src/libstd/rt/io/process.rs b/src/libstd/rt/io/process.rs index b2dbd8ee1f4..c190547889d 100644 --- a/src/libstd/rt/io/process.rs +++ b/src/libstd/rt/io/process.rs @@ -93,7 +93,7 @@ impl Process { Ok((p, io)) => Some(Process{ handle: p, io: io.move_iter().map(|p| - p.map_move(|p| io::PipeStream::bind(p)) + p.map(|p| io::PipeStream::bind(p)) ).collect() }), Err(ioerr) => { diff --git a/src/libstd/rt/io/timer.rs b/src/libstd/rt/io/timer.rs index c2cf9be3980..b41d7541a60 100644 --- a/src/libstd/rt/io/timer.rs +++ b/src/libstd/rt/io/timer.rs @@ -58,7 +58,7 @@ mod test { fn test_io_timer_sleep_simple() { do run_in_mt_newsched_task { let timer = Timer::new(); - do timer.map_move |mut t| { t.sleep(1) }; + do timer.map |mut t| { t.sleep(1) }; } } diff --git a/src/libstd/rt/kill.rs b/src/libstd/rt/kill.rs index 09f99b9302e..6043ae318fe 100644 --- a/src/libstd/rt/kill.rs +++ b/src/libstd/rt/kill.rs @@ -486,10 +486,10 @@ impl KillHandle { || { // Prefer to check tombstones that were there first, // being "more fair" at the expense of tail-recursion. - others.take().map_move_default(true, |f| f()) && { + others.take().map_default(true, |f| f()) && { let mut inner = this.take().unwrap(); (!inner.any_child_failed) && - inner.child_tombstones.take().map_move_default(true, |f| f()) + inner.child_tombstones.take().map_default(true, |f| f()) } } } @@ -508,7 +508,7 @@ impl KillHandle { let others = Cell::new(other_tombstones); // :( || { // Prefer fairness to tail-recursion, as in above case. - others.take().map_move_default(true, |f| f()) && + others.take().map_default(true, |f| f()) && f.take()() } } @@ -577,7 +577,7 @@ impl Death { { use util; util::ignore(group); } // Step 1. Decide if we need to collect child failures synchronously. - do self.on_exit.take().map_move |on_exit| { + do self.on_exit.take().map |on_exit| { if success { // We succeeded, but our children might not. Need to wait for them. let mut inner = self.kill_handle.take_unwrap().unwrap(); @@ -585,7 +585,7 @@ impl Death { success = false; } else { // Lockless access to tombstones protected by unwrap barrier. - success = inner.child_tombstones.take().map_move_default(true, |f| f()); + success = inner.child_tombstones.take().map_default(true, |f| f()); } } on_exit(success); @@ -594,12 +594,12 @@ impl Death { // Step 2. Possibly alert possibly-watching parent to failure status. // Note that as soon as parent_handle goes out of scope, the parent // can successfully unwrap its handle and collect our reported status. - do self.watching_parent.take().map_move |mut parent_handle| { + do self.watching_parent.take().map |mut parent_handle| { if success { // Our handle might be None if we had an exit callback, and // already unwrapped it. But 'success' being true means no // child failed, so there's nothing to do (see below case). - do self.kill_handle.take().map_move |own_handle| { + do self.kill_handle.take().map |own_handle| { own_handle.reparent_children_to(&mut parent_handle); }; } else { diff --git a/src/libstd/rt/sched.rs b/src/libstd/rt/sched.rs index ee43ced44ab..0a4622bc65e 100644 --- a/src/libstd/rt/sched.rs +++ b/src/libstd/rt/sched.rs @@ -538,7 +538,7 @@ impl Scheduler { /// As enqueue_task, but with the possibility for the blocked task to /// already have been killed. pub fn enqueue_blocked_task(&mut self, blocked_task: BlockedTask) { - do blocked_task.wake().map_move |task| { + do blocked_task.wake().map |task| { self.enqueue_task(task); }; } diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index 48b894f51e0..71ab3b571c4 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -485,10 +485,10 @@ mod test { do run_in_newsched_task() { local_data_key!(key: @~str) local_data::set(key, @~"data"); - assert!(*local_data::get(key, |k| k.map_move(|k| *k)).unwrap() == ~"data"); + assert!(*local_data::get(key, |k| k.map(|k| *k)).unwrap() == ~"data"); local_data_key!(key2: @~str) local_data::set(key2, @~"data"); - assert!(*local_data::get(key2, |k| k.map_move(|k| *k)).unwrap() == ~"data"); + assert!(*local_data::get(key2, |k| k.map(|k| *k)).unwrap() == ~"data"); } } diff --git a/src/libstd/rt/uv/process.rs b/src/libstd/rt/uv/process.rs index ddaf0c28725..176754de8f7 100644 --- a/src/libstd/rt/uv/process.rs +++ b/src/libstd/rt/uv/process.rs @@ -46,7 +46,7 @@ impl Process { exit_cb: uv::ExitCallback) -> Result<~[Option<UvPipeStream>], uv::UvError> { - let cwd = config.cwd.map_move(|s| s.to_c_str()); + let cwd = config.cwd.map(|s| s.to_c_str()); extern fn on_exit(p: *uvll::uv_process_t, exit_status: libc::c_int, diff --git a/src/libstd/rt/uv/uvio.rs b/src/libstd/rt/uv/uvio.rs index f9b71db7043..1de6042003c 100644 --- a/src/libstd/rt/uv/uvio.rs +++ b/src/libstd/rt/uv/uvio.rs @@ -74,7 +74,7 @@ trait HomingIO { * * RESOLUTION IDEA: Since the task is dead, we should just abort the IO action. */ - do task.wake().map_move |mut task| { + do task.wake().map |mut task| { *ptr = Some(task.take_unwrap_home()); self.home().send(PinnedTask(task)); }; @@ -97,7 +97,7 @@ trait HomingIO { * * RESOLUTION IDEA: Since the task is dead, we should just abort the IO action. */ - do task.wake().map_move |mut task| { + do task.wake().map |mut task| { task.give_home(old.take()); scheduler.make_handle().send(TaskFromFriend(task)); }; @@ -1672,7 +1672,7 @@ fn test_simple_homed_udp_io_bind_then_move_task_then_home_and_close() { let scheduler: ~Scheduler = Local::take(); do scheduler.deschedule_running_task_and_then |_, task| { // unblock task - do task.wake().map_move |task| { + do task.wake().map |task| { // send self to sched2 tasksFriendHandle.take().send(TaskFromFriend(task)); }; diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 9649bd9c0aa..88497bdaa82 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -415,7 +415,7 @@ impl<'self> Iterator<(uint, char)> for CharOffsetIterator<'self> { b as uint - a as uint } }; - self.iter.next().map_move(|ch| (offset, ch)) + self.iter.next().map(|ch| (offset, ch)) } #[inline] @@ -427,7 +427,7 @@ impl<'self> Iterator<(uint, char)> for CharOffsetIterator<'self> { impl<'self> DoubleEndedIterator<(uint, char)> for CharOffsetIterator<'self> { #[inline] fn next_back(&mut self) -> Option<(uint, char)> { - self.iter.next_back().map_move(|ch| { + self.iter.next_back().map(|ch| { let offset = do self.string.as_imm_buf |a, _| { do self.iter.string.as_imm_buf |b, len| { b as uint - a as uint + len @@ -2260,7 +2260,7 @@ impl<'self> StrSlice<'self> for &'self str { } else { self.matches_index_iter(needle) .next() - .map_move(|(start, _end)| start) + .map(|(start, _end)| start) } } diff --git a/src/libstd/sys.rs b/src/libstd/sys.rs index 25425e07577..ce1be592d79 100644 --- a/src/libstd/sys.rs +++ b/src/libstd/sys.rs @@ -142,7 +142,7 @@ pub fn begin_unwind_(msg: *c_char, file: *c_char, line: size_t) -> ! { // Be careful not to allocate in this block, if we're failing we may // have been failing due to a lack of memory in the first place... do Local::borrow |task: &mut Task| { - let n = task.name.map(|n| n.as_slice()).unwrap_or("<unnamed>"); + let n = task.name.as_ref().map(|n| n.as_slice()).unwrap_or("<unnamed>"); format_args!(|args| { task.logger.log(args) }, "task '{}' failed at '{}', {}:{}", n, msg.as_slice(), file.as_slice(), line); diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index a801bf3328d..d26f8eb1024 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -182,7 +182,7 @@ fn check_generation(_younger: uint, _older: uint) { } #[inline] #[cfg(test)] fn incr_generation(ancestors: &AncestorList) -> uint { - ancestors.map_default(0, |arc| access_ancestors(arc, |a| a.generation+1)) + ancestors.as_ref().map_default(0, |arc| access_ancestors(arc, |a| a.generation+1)) } #[inline] #[cfg(not(test))] fn incr_generation(_ancestors: &AncestorList) -> uint { 0 } @@ -243,7 +243,7 @@ fn each_ancestor(list: &mut AncestorList, // The map defaults to None, because if ancestors is None, we're at // the end of the list, which doesn't make sense to coalesce. - do ancestors.map_default((None,false)) |ancestor_arc| { + do ancestors.as_ref().map_default((None,false)) |ancestor_arc| { // NB: Takes a lock! (this ancestor node) do access_ancestors(ancestor_arc) |nobe| { // Argh, but we couldn't give it to coalesce() otherwise. @@ -386,7 +386,7 @@ fn enlist_in_taskgroup(state: TaskGroupInner, me: KillHandle, is_member: bool) -> bool { let me = Cell::new(me); // :( // If 'None', the group was failing. Can't enlist. - do state.map_mut_default(false) |group| { + do state.as_mut().map_default(false) |group| { (if is_member { &mut group.members } else { @@ -400,7 +400,7 @@ fn enlist_in_taskgroup(state: TaskGroupInner, me: KillHandle, fn leave_taskgroup(state: TaskGroupInner, me: &KillHandle, is_member: bool) { let me = Cell::new(me); // :( // If 'None', already failing and we've already gotten a kill signal. - do state.map_mut |group| { + do state.as_mut().map |group| { (if is_member { &mut group.members } else { @@ -414,7 +414,7 @@ fn kill_taskgroup(state: Option<TaskGroupData>, me: &KillHandle) { // Might already be None, if somebody is failing simultaneously. // That's ok; only one task needs to do the dirty work. (Might also // see 'None' if somebody already failed and we got a kill signal.) - do state.map_move |TaskGroupData { members: members, descendants: descendants }| { + do state.map |TaskGroupData { members: members, descendants: descendants }| { for sibling in members.move_iter() { // Skip self - killing ourself won't do much good. if &sibling != me { @@ -439,7 +439,7 @@ fn taskgroup_key() -> local_data::Key<@@mut Taskgroup> { struct RuntimeGlue; impl RuntimeGlue { fn kill_task(mut handle: KillHandle) { - do handle.kill().map_move |killed_task| { + do handle.kill().map |killed_task| { let killed_task = Cell::new(killed_task); do Local::borrow |sched: &mut Scheduler| { sched.enqueue_task(killed_task.take()); @@ -491,7 +491,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool) // with_my_taskgroup will lazily initialize the parent's taskgroup if // it doesn't yet exist. We don't want to call it in the unlinked case. do RuntimeGlue::with_my_taskgroup |spawner_group| { - let ancestors = AncestorList(spawner_group.ancestors.map(|x| x.clone())); + let ancestors = AncestorList(spawner_group.ancestors.as_ref().map(|x| x.clone())); if linked { // Child is in the same group as spawner. // Child's ancestors are spawner's ancestors. @@ -562,7 +562,7 @@ pub fn spawn_raw(mut opts: TaskOpts, f: ~fn()) { // Child task runs this code. // If child data is 'None', the enlist is vacuously successful. - let enlist_success = do child_data.take().map_move_default(true) |child_data| { + let enlist_success = do child_data.take().map_default(true) |child_data| { let child_data = Cell::new(child_data); // :( do Local::borrow |me: &mut Task| { let (child_tg, ancestors) = child_data.take(); diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs index c1b0cd500d6..b42d3c904d7 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -488,7 +488,7 @@ pub struct TrieSetIterator<'self> { impl<'self> Iterator<uint> for TrieSetIterator<'self> { fn next(&mut self) -> Option<uint> { - do self.iter.next().map |&(key, _)| { key } + do self.iter.next().map |(key, _)| { key } } fn size_hint(&self) -> (uint, Option<uint>) { |
