Skip to content

Commit

Permalink
Fallout from stabilizing core::option
Browse files Browse the repository at this point in the history
  • Loading branch information
aturon committed Aug 28, 2014
1 parent 3a52ef4 commit 276b8b1
Show file tree
Hide file tree
Showing 46 changed files with 121 additions and 116 deletions.
4 changes: 2 additions & 2 deletions src/compiletest/procsrv.rs
Expand Up @@ -47,7 +47,7 @@ pub fn run(lib_path: &str,
match cmd.spawn() {
Ok(mut process) => {
for input in input.iter() {
process.stdin.get_mut_ref().write(input.as_bytes()).unwrap();
process.stdin.as_mut().unwrap().write(input.as_bytes()).unwrap();
}
let ProcessOutput { status, output, error } =
process.wait_with_output().unwrap();
Expand Down Expand Up @@ -79,7 +79,7 @@ pub fn run_background(lib_path: &str,
match cmd.spawn() {
Ok(mut process) => {
for input in input.iter() {
process.stdin.get_mut_ref().write(input.as_bytes()).unwrap();
process.stdin.as_mut().unwrap().write(input.as_bytes()).unwrap();
}

Some(process)
Expand Down
6 changes: 3 additions & 3 deletions src/compiletest/runtest.rs
Expand Up @@ -1526,7 +1526,7 @@ fn compile_cc_with_clang_and_save_bitcode(config: &Config, _props: &TestProps,
let testcc = testfile.with_extension("cc");
let proc_args = ProcArgs {
// FIXME (#9639): This needs to handle non-utf8 paths
prog: config.clang_path.get_ref().as_str().unwrap().to_string(),
prog: config.clang_path.as_ref().unwrap().as_str().unwrap().to_string(),
args: vec!("-c".to_string(),
"-emit-llvm".to_string(),
"-o".to_string(),
Expand All @@ -1542,7 +1542,7 @@ fn extract_function_from_bitcode(config: &Config, _props: &TestProps,
let bitcodefile = output_base_name(config, testfile).with_extension("bc");
let bitcodefile = append_suffix_to_stem(&bitcodefile, suffix);
let extracted_bc = append_suffix_to_stem(&bitcodefile, "extract");
let prog = config.llvm_bin_path.get_ref().join("llvm-extract");
let prog = config.llvm_bin_path.as_ref().unwrap().join("llvm-extract");
let proc_args = ProcArgs {
// FIXME (#9639): This needs to handle non-utf8 paths
prog: prog.as_str().unwrap().to_string(),
Expand All @@ -1559,7 +1559,7 @@ fn disassemble_extract(config: &Config, _props: &TestProps,
let bitcodefile = append_suffix_to_stem(&bitcodefile, suffix);
let extracted_bc = append_suffix_to_stem(&bitcodefile, "extract");
let extracted_ll = extracted_bc.with_extension("ll");
let prog = config.llvm_bin_path.get_ref().join("llvm-dis");
let prog = config.llvm_bin_path.as_ref().unwrap().join("llvm-dis");
let proc_args = ProcArgs {
// FIXME (#9639): This needs to handle non-utf8 paths
prog: prog.as_str().unwrap().to_string(),
Expand Down
6 changes: 3 additions & 3 deletions src/libarena/lib.rs
Expand Up @@ -476,7 +476,7 @@ impl<T> TypedArena<T> {
/// Grows the arena.
#[inline(never)]
fn grow(&self) {
let chunk = self.first.borrow_mut().take_unwrap();
let chunk = self.first.borrow_mut().take().unwrap();
let new_capacity = chunk.capacity.checked_mul(&2).unwrap();
let chunk = TypedArenaChunk::<T>::new(Some(chunk), new_capacity);
self.ptr.set(chunk.start() as *const T);
Expand All @@ -489,13 +489,13 @@ impl<T> TypedArena<T> {
impl<T> Drop for TypedArena<T> {
fn drop(&mut self) {
// Determine how much was filled.
let start = self.first.borrow().get_ref().start() as uint;
let start = self.first.borrow().as_ref().unwrap().start() as uint;
let end = self.ptr.get() as uint;
let diff = (end - start) / mem::size_of::<T>();

// Pass that to the `destroy` method.
unsafe {
self.first.borrow_mut().get_mut_ref().destroy(diff)
self.first.borrow_mut().as_mut().unwrap().destroy(diff)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/dlist.rs
Expand Up @@ -630,7 +630,7 @@ impl<'a, A> MutItems<'a, A> {
None => return self.list.push_front_node(ins_node),
Some(prev) => prev,
};
let node_own = prev_node.next.take_unwrap();
let node_own = prev_node.next.take().unwrap();
ins_node.next = link_with_prev(node_own, Rawlink::some(&mut *ins_node));
prev_node.next = link_with_prev(ins_node, Rawlink::some(prev_node));
self.list.length += 1;
Expand Down
6 changes: 3 additions & 3 deletions src/libcollections/ringbuf.rs
Expand Up @@ -309,7 +309,7 @@ impl<'a, T> Iterator<&'a T> for Items<'a, T> {
}
let raw_index = raw_index(self.lo, self.elts.len(), self.index);
self.index += 1;
Some(self.elts[raw_index].get_ref())
Some(self.elts[raw_index].as_ref().unwrap())
}

#[inline]
Expand All @@ -327,7 +327,7 @@ impl<'a, T> DoubleEndedIterator<&'a T> for Items<'a, T> {
}
self.rindex -= 1;
let raw_index = raw_index(self.lo, self.elts.len(), self.rindex);
Some(self.elts[raw_index].get_ref())
Some(self.elts[raw_index].as_ref().unwrap())
}
}

Expand All @@ -343,7 +343,7 @@ impl<'a, T> RandomAccessIterator<&'a T> for Items<'a, T> {
None
} else {
let raw_index = raw_index(self.lo, self.elts.len(), self.index + j);
Some(self.elts[raw_index].get_ref())
Some(self.elts[raw_index].as_ref().unwrap())
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/libcollections/treemap.rs
Expand Up @@ -1447,7 +1447,7 @@ impl<K: Ord, V> TreeNode<K, V> {
// Remove left horizontal link by rotating right
fn skew<K: Ord, V>(node: &mut Box<TreeNode<K, V>>) {
if node.left.as_ref().map_or(false, |x| x.level == node.level) {
let mut save = node.left.take_unwrap();
let mut save = node.left.take().unwrap();
swap(&mut node.left, &mut save.right); // save.right now None
swap(node, &mut save);
node.right = Some(save);
Expand All @@ -1459,7 +1459,7 @@ fn skew<K: Ord, V>(node: &mut Box<TreeNode<K, V>>) {
fn split<K: Ord, V>(node: &mut Box<TreeNode<K, V>>) {
if node.right.as_ref().map_or(false,
|x| x.right.as_ref().map_or(false, |y| y.level == node.level)) {
let mut save = node.right.take_unwrap();
let mut save = node.right.take().unwrap();
swap(&mut node.right, &mut save.left); // save.left now None
save.level += 1;
swap(node, &mut save);
Expand Down Expand Up @@ -1563,7 +1563,7 @@ fn remove<K: Ord, V>(node: &mut Option<Box<TreeNode<K, V>>>,
Equal => {
if save.left.is_some() {
if save.right.is_some() {
let mut left = save.left.take_unwrap();
let mut left = save.left.take().unwrap();
if left.right.is_some() {
heir_swap(save, &mut left.right);
} else {
Expand All @@ -1573,13 +1573,13 @@ fn remove<K: Ord, V>(node: &mut Option<Box<TreeNode<K, V>>>,
save.left = Some(left);
(remove(&mut save.left, key), true)
} else {
let new = save.left.take_unwrap();
let new = save.left.take().unwrap();
let box TreeNode{value, ..} = replace(save, new);
*save = save.left.take_unwrap();
*save = save.left.take().unwrap();
(Some(value), true)
}
} else if save.right.is_some() {
let new = save.right.take_unwrap();
let new = save.right.take().unwrap();
let box TreeNode{value, ..} = replace(save, new);
(Some(value), true)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/cell.rs
Expand Up @@ -99,7 +99,7 @@
//! // Take a reference to the inside of cache cell
//! let mut cache = self.span_tree_cache.borrow_mut();
//! if cache.is_some() {
//! return cache.get_ref().clone();
//! return cache.as_ref().unwrap().clone();
//! }
//!
//! let span_tree = self.calc_span_tree();
Expand Down
7 changes: 6 additions & 1 deletion src/libcore/iter.rs
Expand Up @@ -2191,7 +2191,12 @@ pub fn iterate<'a, T: Clone>(f: |T|: 'a -> T, seed: T) -> Iterate<'a, T> {
if *first {
*first = false;
} else {
val.mutate(|x| (*f)(x));
match val.take() {
Some(x) => {
*val = Some((*f)(x))
}
None => {}
}
}
val.clone()
})
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/option.rs
Expand Up @@ -341,7 +341,7 @@ impl<T> Option<T> {
#[deprecated = "removed due to lack of use"]
pub fn mutate(&mut self, f: |T| -> T) -> bool {
if self.is_some() {
*self = Some(f(self.take_unwrap()));
*self = Some(f(self.take().unwrap()));
true
} else { false }
}
Expand All @@ -353,7 +353,7 @@ impl<T> Option<T> {
#[deprecated = "removed due to lack of use"]
pub fn mutate_or_set(&mut self, def: T, f: |T| -> T) -> bool {
if self.is_some() {
*self = Some(f(self.take_unwrap()));
*self = Some(f(self.take().unwrap()));
true
} else {
*self = Some(def);
Expand Down
6 changes: 3 additions & 3 deletions src/libcoretest/option.rs
Expand Up @@ -73,7 +73,7 @@ fn test_option_dance() {
let mut y = Some(5i);
let mut y2 = 0;
for _x in x.iter() {
y2 = y.take_unwrap();
y2 = y.take().unwrap();
}
assert_eq!(y2, 5);
assert!(y.is_none());
Expand All @@ -82,8 +82,8 @@ fn test_option_dance() {
#[test] #[should_fail]
fn test_option_too_much_dance() {
let mut y = Some(marker::NoCopy);
let _y2 = y.take_unwrap();
let _y3 = y.take_unwrap();
let _y2 = y.take().unwrap();
let _y3 = y.take().unwrap();
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/libglob/lib.rs
Expand Up @@ -106,7 +106,7 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> Paths {
let mut root = os::getcwd();
let pat_root = Path::new(pattern).root_path();
if pat_root.is_some() {
if check_windows_verbatim(pat_root.get_ref()) {
if check_windows_verbatim(pat_root.as_ref().unwrap()) {
// FIXME: How do we want to handle verbatim paths? I'm inclined to return nothing,
// since we can't very well find all UNC shares with a 1-letter server name.
return Paths {
Expand All @@ -116,7 +116,7 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> Paths {
todo: Vec::new(),
};
}
root.push(pat_root.get_ref());
root.push(pat_root.as_ref().unwrap());
}

let root_len = pat_root.map_or(0u, |p| p.as_vec().len());
Expand Down
2 changes: 1 addition & 1 deletion src/libgreen/lib.rs
Expand Up @@ -305,7 +305,7 @@ pub fn start(argc: int, argv: *const *const u8,
let mut main = Some(main);
let mut ret = None;
simple::task().run(|| {
ret = Some(run(event_loop_factory, main.take_unwrap()));
ret = Some(run(event_loop_factory, main.take().unwrap()));
}).destroy();
// unsafe is ok b/c we're sure that the runtime is gone
unsafe { rt::cleanup() }
Expand Down
20 changes: 10 additions & 10 deletions src/libgreen/sched.rs
Expand Up @@ -203,7 +203,7 @@ impl Scheduler {
let mut sched_task = self.run(sched_task);

// Close the idle callback.
let mut sched = sched_task.sched.take_unwrap();
let mut sched = sched_task.sched.take().unwrap();
sched.idle_callback.take();
// Make one go through the loop to run the close callback.
let mut stask = sched.run(sched_task);
Expand Down Expand Up @@ -702,7 +702,7 @@ impl Scheduler {
assert!(sched.sched_task.is_none());
sched.sched_task = Some(stask);
});
(cur.sched.take_unwrap(), cur)
(cur.sched.take().unwrap(), cur)
}

fn resume_task_immediately_cl(sched: Box<Scheduler>,
Expand Down Expand Up @@ -738,7 +738,7 @@ impl Scheduler {
f: |&mut Scheduler, BlockedTask|) {
// Trickier - we need to get the scheduler task out of self
// and use it as the destination.
let stask = self.sched_task.take_unwrap();
let stask = self.sched_task.take().unwrap();
// Otherwise this is the same as below.
self.switch_running_tasks_and_then(cur, stask, f)
}
Expand Down Expand Up @@ -788,7 +788,7 @@ impl Scheduler {
sched.enqueue_task(last_task);
}
});
(cur.sched.take_unwrap(), cur)
(cur.sched.take().unwrap(), cur)
}

// * Task Context Helpers
Expand All @@ -800,9 +800,9 @@ impl Scheduler {
-> ! {
// Similar to deschedule running task and then, but cannot go through
// the task-blocking path. The task is already dying.
let stask = self.sched_task.take_unwrap();
let stask = self.sched_task.take().unwrap();
let _cur = self.change_task_context(cur, stask, |sched, mut dead_task| {
let coroutine = dead_task.coroutine.take_unwrap();
let coroutine = dead_task.coroutine.take().unwrap();
coroutine.recycle(&mut sched.stack_pool);
sched.task_state.decrement();
});
Expand All @@ -818,7 +818,7 @@ impl Scheduler {
}

pub fn run_task_later(mut cur: Box<GreenTask>, next: Box<GreenTask>) {
let mut sched = cur.sched.take_unwrap();
let mut sched = cur.sched.take().unwrap();
sched.enqueue_task(next);
cur.put_with_sched(sched);
}
Expand All @@ -838,7 +838,7 @@ impl Scheduler {
self.yield_check_count = reset_yield_check(&mut self.rng);
// Tell the scheduler to start stealing on the next iteration
self.steal_for_yield = true;
let stask = self.sched_task.take_unwrap();
let stask = self.sched_task.take().unwrap();
let cur = self.change_task_context(cur, stask, |sched, task| {
sched.enqueue_task(task);
});
Expand Down Expand Up @@ -878,7 +878,7 @@ impl Scheduler {
pub fn sched_id(&self) -> uint { self as *const Scheduler as uint }

pub fn run_cleanup_job(&mut self) {
let cleanup_job = self.cleanup_job.take_unwrap();
let cleanup_job = self.cleanup_job.take().unwrap();
cleanup_job.run(self)
}

Expand Down Expand Up @@ -1235,7 +1235,7 @@ mod test {

fn run(next: Box<GreenTask>) {
let mut task = GreenTask::convert(Local::take());
let sched = task.sched.take_unwrap();
let sched = task.sched.take().unwrap();
sched.run_task(task, next)
}

Expand Down
16 changes: 8 additions & 8 deletions src/libgreen/task.rs
Expand Up @@ -110,7 +110,7 @@ extern fn bootstrap_green_task(task: uint, code: *mut (), env: *mut ()) -> ! {
// requested. This is the "try/catch" block for this green task and
// is the wrapper for *all* code run in the task.
let mut start = Some(start);
let task = task.swap().run(|| start.take_unwrap()()).destroy();
let task = task.swap().run(|| start.take().unwrap()()).destroy();

// Once the function has exited, it's time to run the termination
// routine. This means we need to context switch one more time but
Expand Down Expand Up @@ -212,7 +212,7 @@ impl GreenTask {

pub fn take_unwrap_home(&mut self) -> Home {
match self.task_type {
TypeGreen(ref mut home) => home.take_unwrap(),
TypeGreen(ref mut home) => home.take().unwrap(),
TypeSched => rtabort!("type error: used SchedTask as GreenTask"),
}
}
Expand Down Expand Up @@ -277,7 +277,7 @@ impl GreenTask {
}

pub fn swap(mut self: Box<GreenTask>) -> Box<Task> {
let mut task = self.task.take_unwrap();
let mut task = self.task.take().unwrap();
task.put_runtime(self);
return task;
}
Expand All @@ -288,7 +288,7 @@ impl GreenTask {
}

fn terminate(mut self: Box<GreenTask>) -> ! {
let sched = self.sched.take_unwrap();
let sched = self.sched.take().unwrap();
sched.terminate_current_task(self)
}

Expand Down Expand Up @@ -324,13 +324,13 @@ impl GreenTask {
impl Runtime for GreenTask {
fn yield_now(mut self: Box<GreenTask>, cur_task: Box<Task>) {
self.put_task(cur_task);
let sched = self.sched.take_unwrap();
let sched = self.sched.take().unwrap();
sched.yield_now(self);
}

fn maybe_yield(mut self: Box<GreenTask>, cur_task: Box<Task>) {
self.put_task(cur_task);
let sched = self.sched.take_unwrap();
let sched = self.sched.take().unwrap();
sched.maybe_yield(self);
}

Expand All @@ -339,7 +339,7 @@ impl Runtime for GreenTask {
cur_task: Box<Task>,
f: |BlockedTask| -> Result<(), BlockedTask>) {
self.put_task(cur_task);
let mut sched = self.sched.take_unwrap();
let mut sched = self.sched.take().unwrap();

// In order for this task to be reawoken in all possible contexts, we
// may need a handle back in to the current scheduler. When we're woken
Expand Down Expand Up @@ -418,7 +418,7 @@ impl Runtime for GreenTask {
match running_task.maybe_take_runtime::<GreenTask>() {
Some(mut running_green_task) => {
running_green_task.put_task(running_task);
let sched = running_green_task.sched.take_unwrap();
let sched = running_green_task.sched.take().unwrap();

if sched.pool_id == self.pool_id {
sched.run_task(running_green_task, self);
Expand Down

0 comments on commit 276b8b1

Please sign in to comment.