Skip to content

Commit 712ac83

Browse files
committed
Rename Option swap_unwrap to take_unwrap. Fixes Issue#7764
1 parent a317584 commit 712ac83

15 files changed

+43
-43
lines changed

src/libextra/dlist.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ impl<T> Deque<T> for DList<T> {
173173
let tail_own = match tail.prev.resolve() {
174174
None => {
175175
self.list_tail = Rawlink::none();
176-
self.list_head.swap_unwrap()
176+
self.list_head.take_unwrap()
177177
},
178178
Some(tail_prev) => {
179179
self.list_tail = tail.prev;
180-
tail_prev.next.swap_unwrap()
180+
tail_prev.next.take_unwrap()
181181
}
182182
};
183183
Some(tail_own.value)
@@ -465,7 +465,7 @@ impl<'self, A> ListInsertion<A> for MutDListIterator<'self, A> {
465465
Some(prev) => prev,
466466
};
467467
let mut ins_node = ~Node{value: elt, next: None, prev: Rawlink::none()};
468-
let node_own = prev_node.next.swap_unwrap();
468+
let node_own = prev_node.next.take_unwrap();
469469
ins_node.next = link_with_prev(node_own, Rawlink::some(ins_node));
470470
prev_node.next = link_with_prev(ins_node, Rawlink::some(prev_node));
471471
self.list.length += 1;

src/libextra/net/ip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub fn get_addr(node: &str, iotask: &iotask)
116116
let (output_po, output_ch) = stream();
117117
let mut output_ch = Some(SharedChan::new(output_ch));
118118
do str::as_buf(node) |node_ptr, len| {
119-
let output_ch = output_ch.swap_unwrap();
119+
let output_ch = output_ch.take_unwrap();
120120
debug!("slice len %?", len);
121121
let handle = create_uv_getaddrinfo_t();
122122
let handle_ptr: *uv_getaddrinfo_t = &handle;

src/libextra/sync.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ impl<'self> Condvar<'self> {
260260
signal_waitqueue(&state.waiters);
261261
}
262262
// Enqueue ourself to be woken up by a signaller.
263-
let SignalEnd = SignalEnd.swap_unwrap();
263+
let SignalEnd = SignalEnd.take_unwrap();
264264
state.blocked[condvar_id].tail.send(SignalEnd);
265265
} else {
266266
out_of_bounds = Some(state.blocked.len());
@@ -281,7 +281,7 @@ impl<'self> Condvar<'self> {
281281
// Unconditionally "block". (Might not actually block if a
282282
// signaller already sent -- I mean 'unconditionally' in contrast
283283
// with acquire().)
284-
let _ = comm::recv_one(WaitEnd.swap_unwrap());
284+
let _ = comm::recv_one(WaitEnd.take_unwrap());
285285
}
286286

287287
// This is needed for a failing condition variable to reacquire the
@@ -353,7 +353,7 @@ impl<'self> Condvar<'self> {
353353
}
354354
}
355355
do check_cvar_bounds(out_of_bounds, condvar_id, "cond.signal_on()") {
356-
let queue = queue.swap_unwrap();
356+
let queue = queue.take_unwrap();
357357
broadcast_waitqueue(&queue)
358358
}
359359
}
@@ -1436,7 +1436,7 @@ mod tests {
14361436
do x.write_downgrade |xwrite| {
14371437
let mut xopt = Some(xwrite);
14381438
do y.write_downgrade |_ywrite| {
1439-
y.downgrade(xopt.swap_unwrap());
1439+
y.downgrade(xopt.take_unwrap());
14401440
error!("oops, y.downgrade(x) should have failed!");
14411441
}
14421442
}

src/libextra/treemap.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ fn mutate_values<'r, K: TotalOrd, V>(node: &'r mut Option<~TreeNode<K, V>>,
552552
// Remove left horizontal link by rotating right
553553
fn skew<K: TotalOrd, V>(node: &mut ~TreeNode<K, V>) {
554554
if node.left.map_default(false, |x| x.level == node.level) {
555-
let mut save = node.left.swap_unwrap();
555+
let mut save = node.left.take_unwrap();
556556
swap(&mut node.left, &mut save.right); // save.right now None
557557
swap(node, &mut save);
558558
node.right = Some(save);
@@ -564,7 +564,7 @@ fn skew<K: TotalOrd, V>(node: &mut ~TreeNode<K, V>) {
564564
fn split<K: TotalOrd, V>(node: &mut ~TreeNode<K, V>) {
565565
if node.right.map_default(false,
566566
|x| x.right.map_default(false, |y| y.level == node.level)) {
567-
let mut save = node.right.swap_unwrap();
567+
let mut save = node.right.take_unwrap();
568568
swap(&mut node.right, &mut save.left); // save.left now None
569569
save.level += 1;
570570
swap(node, &mut save);
@@ -643,7 +643,7 @@ fn remove<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>,
643643
Equal => {
644644
if save.left.is_some() {
645645
if save.right.is_some() {
646-
let mut left = save.left.swap_unwrap();
646+
let mut left = save.left.take_unwrap();
647647
if left.right.is_some() {
648648
heir_swap(save, &mut left.right);
649649
} else {
@@ -653,13 +653,13 @@ fn remove<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>,
653653
save.left = Some(left);
654654
(remove(&mut save.left, key), true)
655655
} else {
656-
let new = save.left.swap_unwrap();
656+
let new = save.left.take_unwrap();
657657
let ~TreeNode{value, _} = replace(save, new);
658-
*save = save.left.swap_unwrap();
658+
*save = save.left.take_unwrap();
659659
(Some(value), true)
660660
}
661661
} else if save.right.is_some() {
662-
let new = save.right.swap_unwrap();
662+
let new = save.right.take_unwrap();
663663
let ~TreeNode{value, _} = replace(save, new);
664664
(Some(value), true)
665665
} else {

src/libstd/option.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,14 @@ impl<T> Option<T> {
203203
/// Apply a function to the contained value or do nothing
204204
pub fn mutate(&mut self, f: &fn(T) -> T) {
205205
if self.is_some() {
206-
*self = Some(f(self.swap_unwrap()));
206+
*self = Some(f(self.take_unwrap()));
207207
}
208208
}
209209

210210
/// Apply a function to the contained value or set it to a default
211211
pub fn mutate_default(&mut self, def: T, f: &fn(T) -> T) {
212212
if self.is_some() {
213-
*self = Some(f(self.swap_unwrap()));
213+
*self = Some(f(self.take_unwrap()));
214214
} else {
215215
*self = Some(def);
216216
}
@@ -293,8 +293,8 @@ impl<T> Option<T> {
293293
* Fails if the value equals `None`.
294294
*/
295295
#[inline]
296-
pub fn swap_unwrap(&mut self) -> T {
297-
if self.is_none() { fail!("option::swap_unwrap none") }
296+
pub fn take_unwrap(&mut self) -> T {
297+
if self.is_none() { fail!("option::take_unwrap none") }
298298
util::replace(self, None).unwrap()
299299
}
300300

@@ -460,16 +460,16 @@ fn test_option_dance() {
460460
let mut y = Some(5);
461461
let mut y2 = 0;
462462
for x.iter().advance |_x| {
463-
y2 = y.swap_unwrap();
463+
y2 = y.take_unwrap();
464464
}
465465
assert_eq!(y2, 5);
466466
assert!(y.is_none());
467467
}
468468
#[test] #[should_fail] #[ignore(cfg(windows))]
469469
fn test_option_too_much_dance() {
470470
let mut y = Some(util::NonCopyable);
471-
let _y2 = y.swap_unwrap();
472-
let _y3 = y.swap_unwrap();
471+
let _y2 = y.take_unwrap();
472+
let _y3 = y.take_unwrap();
473473
}
474474

475475
#[test]

src/libstd/rt/sched.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ impl Scheduler {
328328
/// Given an input Coroutine sends it back to its home scheduler.
329329
fn send_task_home(task: ~Task) {
330330
let mut task = task;
331-
let mut home = task.home.swap_unwrap();
331+
let mut home = task.home.take_unwrap();
332332
match home {
333333
Sched(ref mut home_handle) => {
334334
home_handle.send(PinnedTask(task));
@@ -418,7 +418,7 @@ impl Scheduler {
418418

419419
do self.deschedule_running_task_and_then |sched, dead_task| {
420420
let mut dead_task = dead_task;
421-
let coroutine = dead_task.coroutine.swap_unwrap();
421+
let coroutine = dead_task.coroutine.take_unwrap();
422422
coroutine.recycle(&mut sched.stack_pool);
423423
}
424424

@@ -506,7 +506,7 @@ impl Scheduler {
506506
this.metrics.context_switches_task_to_sched += 1;
507507

508508
unsafe {
509-
let blocked_task = this.current_task.swap_unwrap();
509+
let blocked_task = this.current_task.take_unwrap();
510510
let f_fake_region = transmute::<&fn(&mut Scheduler, ~Task),
511511
&fn(&mut Scheduler, ~Task)>(f);
512512
let f_opaque = ClosureConverter::from_fn(f_fake_region);
@@ -538,7 +538,7 @@ impl Scheduler {
538538
rtdebug!("switching tasks");
539539
this.metrics.context_switches_task_to_task += 1;
540540

541-
let old_running_task = this.current_task.swap_unwrap();
541+
let old_running_task = this.current_task.take_unwrap();
542542
let f_fake_region = unsafe {
543543
transmute::<&fn(&mut Scheduler, ~Task),
544544
&fn(&mut Scheduler, ~Task)>(f)
@@ -576,7 +576,7 @@ impl Scheduler {
576576

577577
assert!(self.cleanup_job.is_some());
578578

579-
let cleanup_job = self.cleanup_job.swap_unwrap();
579+
let cleanup_job = self.cleanup_job.take_unwrap();
580580
match cleanup_job {
581581
DoNothing => { }
582582
GiveTask(task, f) => (f.to_fn())(self, task)

src/libstd/rt/task.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl Task {
127127

128128
// Wait for children. Possibly report the exit status.
129129
let local_success = !self.unwinder.unwinding;
130-
let join_latch = self.join_latch.swap_unwrap();
130+
let join_latch = self.join_latch.take_unwrap();
131131
match self.on_exit {
132132
Some(ref on_exit) => {
133133
let success = join_latch.wait(local_success);

src/libstd/rt/tube.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<T> Tube<T> {
5353
if (*state).blocked_task.is_some() {
5454
// There's a waiting task. Wake it up
5555
rtdebug!("waking blocked tube");
56-
let task = (*state).blocked_task.swap_unwrap();
56+
let task = (*state).blocked_task.take_unwrap();
5757
let sched = Local::take::<Scheduler>();
5858
sched.resume_task_immediately(task);
5959
}

src/libstd/rt/uv/async.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl AsyncWatcher {
6262
let mut watcher: AsyncWatcher = NativeHandle::from_native_handle(handle);
6363
{
6464
let data = watcher.get_watcher_data();
65-
data.close_cb.swap_unwrap()();
65+
data.close_cb.take_unwrap()();
6666
}
6767
watcher.drop_watcher_data();
6868
unsafe { uvll::free_handle(handle as *c_void); }

src/libstd/rt/uv/idle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl IdleWatcher {
7373
let mut idle_watcher: IdleWatcher = NativeHandle::from_native_handle(handle);
7474
{
7575
let data = idle_watcher.get_watcher_data();
76-
data.close_cb.swap_unwrap()();
76+
data.close_cb.take_unwrap()();
7777
}
7878
idle_watcher.drop_watcher_data();
7979
uvll::idle_delete(handle);

src/libstd/rt/uv/net.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl StreamWatcher {
209209
let write_request: WriteRequest = NativeHandle::from_native_handle(req);
210210
let mut stream_watcher = write_request.stream();
211211
write_request.delete();
212-
let cb = stream_watcher.get_watcher_data().write_cb.swap_unwrap();
212+
let cb = stream_watcher.get_watcher_data().write_cb.take_unwrap();
213213
let status = status_to_maybe_uv_error(stream_watcher.native_handle(), status);
214214
cb(stream_watcher, status);
215215
}
@@ -233,7 +233,7 @@ impl StreamWatcher {
233233

234234
extern fn close_cb(handle: *uvll::uv_stream_t) {
235235
let mut stream_watcher: StreamWatcher = NativeHandle::from_native_handle(handle);
236-
stream_watcher.get_watcher_data().close_cb.swap_unwrap()();
236+
stream_watcher.get_watcher_data().close_cb.take_unwrap()();
237237
stream_watcher.drop_watcher_data();
238238
unsafe { free_handle(handle as *c_void) }
239239
}
@@ -301,7 +301,7 @@ impl TcpWatcher {
301301
let connect_request: ConnectRequest = NativeHandle::from_native_handle(req);
302302
let mut stream_watcher = connect_request.stream();
303303
connect_request.delete();
304-
let cb = stream_watcher.get_watcher_data().connect_cb.swap_unwrap();
304+
let cb = stream_watcher.get_watcher_data().connect_cb.take_unwrap();
305305
let status = status_to_maybe_uv_error(stream_watcher.native_handle(), status);
306306
cb(stream_watcher, status);
307307
}
@@ -438,7 +438,7 @@ impl UdpWatcher {
438438
let send_request: UdpSendRequest = NativeHandle::from_native_handle(req);
439439
let mut udp_watcher = send_request.handle();
440440
send_request.delete();
441-
let cb = udp_watcher.get_watcher_data().udp_send_cb.swap_unwrap();
441+
let cb = udp_watcher.get_watcher_data().udp_send_cb.take_unwrap();
442442
let status = status_to_maybe_uv_error(udp_watcher.native_handle(), status);
443443
cb(udp_watcher, status);
444444
}
@@ -456,7 +456,7 @@ impl UdpWatcher {
456456

457457
extern fn close_cb(handle: *uvll::uv_udp_t) {
458458
let mut udp_watcher: UdpWatcher = NativeHandle::from_native_handle(handle);
459-
udp_watcher.get_watcher_data().close_cb.swap_unwrap()();
459+
udp_watcher.get_watcher_data().close_cb.take_unwrap()();
460460
udp_watcher.drop_watcher_data();
461461
unsafe { free_handle(handle as *c_void) }
462462
}

src/libstd/rt/uv/timer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl TimerWatcher {
7070
let mut watcher: TimerWatcher = NativeHandle::from_native_handle(handle);
7171
{
7272
let data = watcher.get_watcher_data();
73-
data.close_cb.swap_unwrap()();
73+
data.close_cb.take_unwrap()();
7474
}
7575
watcher.drop_watcher_data();
7676
unsafe {

src/libstd/task/spawn.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ fn each_ancestor(list: &mut AncestorList,
302302
fn with_parent_tg<U>(parent_group: &mut Option<TaskGroupArc>,
303303
blk: &fn(TaskGroupInner) -> U) -> U {
304304
// If this trips, more likely the problem is 'blk' failed inside.
305-
let tmp_arc = parent_group.swap_unwrap();
305+
let tmp_arc = parent_group.take_unwrap();
306306
let result = do access_group(&tmp_arc) |tg_opt| { blk(tg_opt) };
307307
*parent_group = Some(tmp_arc);
308308
result
@@ -609,7 +609,7 @@ fn spawn_raw_newsched(mut opts: TaskOpts, f: ~fn()) {
609609
};
610610

611611
if opts.notify_chan.is_some() {
612-
let notify_chan = opts.notify_chan.swap_unwrap();
612+
let notify_chan = opts.notify_chan.take_unwrap();
613613
let notify_chan = Cell::new(notify_chan);
614614
let on_exit: ~fn(bool) = |success| {
615615
notify_chan.take().send(
@@ -647,7 +647,7 @@ fn spawn_raw_oldsched(mut opts: TaskOpts, f: ~fn()) {
647647
let notify_chan = if opts.notify_chan.is_none() {
648648
None
649649
} else {
650-
Some(opts.notify_chan.swap_unwrap())
650+
Some(opts.notify_chan.take_unwrap())
651651
};
652652

653653
let child_wrapper = make_child_wrapper(new_task, child_tg,

src/test/bench/msgsend-ring-mutex-arcs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ fn thread_ring(i: uint, count: uint, num_chan: pipe, num_port: pipe) {
6060
// Send/Receive lots of messages.
6161
for uint::range(0u, count) |j| {
6262
//error!("task %?, iter %?", i, j);
63-
let mut num_chan2 = num_chan.swap_unwrap();
64-
let mut num_port2 = num_port.swap_unwrap();
63+
let mut num_chan2 = num_chan.take_unwrap();
64+
let mut num_port2 = num_port.take_unwrap();
6565
send(&num_chan2, i * j);
6666
num_chan = Some(num_chan2);
6767
let _n = recv(&num_port2);

src/test/bench/msgsend-ring-rw-arcs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ fn thread_ring(i: uint, count: uint, num_chan: pipe, num_port: pipe) {
5656
// Send/Receive lots of messages.
5757
for uint::range(0u, count) |j| {
5858
//error!("task %?, iter %?", i, j);
59-
let mut num_chan2 = num_chan.swap_unwrap();
60-
let mut num_port2 = num_port.swap_unwrap();
59+
let mut num_chan2 = num_chan.take_unwrap();
60+
let mut num_port2 = num_port.take_unwrap();
6161
send(&num_chan2, i * j);
6262
num_chan = Some(num_chan2);
6363
let _n = recv(&num_port2);

0 commit comments

Comments
 (0)