diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index 54d99151233..ee4d74ce169 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -159,10 +159,10 @@ fn parse_exec_env(line: &str) -> Option<(~str, ~str)> { let mut strs: ~[~str] = nv.splitn('=', 1).map(|s| s.to_owned()).collect(); match strs.len() { - 1u => (strs.pop(), ~""), + 1u => (strs.pop().unwrap(), ~""), 2u => { - let end = strs.pop(); - (strs.pop(), end) + let end = strs.pop().unwrap(); + (strs.pop().unwrap(), end) } n => fail!("Expected 1 or 2 strings, not {}", n) } diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index e06f4e32631..6f8a3ad83a3 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -917,7 +917,7 @@ fn _arm_exec_compiled_test(config: &config, props: &TestProps, // get bare program string let mut tvec: ~[~str] = args.prog.split('/').map(|ts| ts.to_owned()).collect(); - let prog_short = tvec.pop(); + let prog_short = tvec.pop().unwrap(); // copy to target let copy_result = procsrv::run("", config.adb_path, diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index 28a6c69ba1b..009cc53289e 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -1049,7 +1049,7 @@ mod tests { match r % 6 { 0 => { m.pop_back(); - if v.len() > 0 { v.pop(); } + v.pop(); } 1 => { m.pop_front(); diff --git a/src/libextra/ebml.rs b/src/libextra/ebml.rs index f7481599bac..8cce47b03f8 100644 --- a/src/libextra/ebml.rs +++ b/src/libextra/ebml.rs @@ -651,7 +651,7 @@ pub mod writer { } pub fn end_tag(&mut self) { - let last_size_pos = self.size_positions.pop(); + let last_size_pos = self.size_positions.pop().unwrap(); let cur_pos = self.writer.tell(); self.writer.seek(last_size_pos as i64, io::SeekSet); let size = (cur_pos as uint - last_size_pos - 4); diff --git a/src/libextra/glob.rs b/src/libextra/glob.rs index d4d0a7b89f0..3e2aa511b81 100644 --- a/src/libextra/glob.rs +++ b/src/libextra/glob.rs @@ -122,7 +122,7 @@ impl Iterator for Paths { return None; } - let (path,idx) = self.todo.pop(); + let (path,idx) = self.todo.pop().unwrap(); let ref pattern = self.dir_patterns[idx]; if pattern.matches_with(match path.filename_str() { diff --git a/src/libextra/json.rs b/src/libextra/json.rs index 378e1e85339..9fcafee8c51 100644 --- a/src/libextra/json.rs +++ b/src/libextra/json.rs @@ -1028,7 +1028,7 @@ impl> Parser { while !self.eof() { self.parse_whitespace(); - if self.ch != '\"' { + if self.ch != '"' { return self.error(~"key must be a string"); } @@ -1117,7 +1117,7 @@ impl Decoder { impl serialize::Decoder for Decoder { fn read_nil(&mut self) -> () { debug!("read_nil"); - match self.stack.pop() { + match self.stack.pop().unwrap() { Null => (), value => self.expected("null", &value) } @@ -1137,7 +1137,7 @@ impl serialize::Decoder for Decoder { fn read_bool(&mut self) -> bool { debug!("read_bool"); - match self.stack.pop() { + match self.stack.pop().unwrap() { Boolean(b) => b, value => self.expected("boolean", &value) } @@ -1145,7 +1145,7 @@ impl serialize::Decoder for Decoder { fn read_f64(&mut self) -> f64 { debug!("read_f64"); - match self.stack.pop() { + match self.stack.pop().unwrap() { Number(f) => f, value => self.expected("number", &value) } @@ -1168,7 +1168,7 @@ impl serialize::Decoder for Decoder { fn read_str(&mut self) -> ~str { debug!("read_str"); - match self.stack.pop() { + match self.stack.pop().unwrap() { String(s) => s, value => self.expected("string", &value) } @@ -1184,7 +1184,7 @@ impl serialize::Decoder for Decoder { f: |&mut Decoder, uint| -> T) -> T { debug!("read_enum_variant(names={:?})", names); - let name = match self.stack.pop() { + let name = match self.stack.pop().unwrap() { String(s) => s, Object(mut o) => { let n = match o.pop(&~"variant") { @@ -1249,7 +1249,7 @@ impl serialize::Decoder for Decoder { -> T { debug!("read_struct(name={}, len={})", name, len); let value = f(self); - self.stack.pop(); + self.stack.pop().unwrap(); value } @@ -1259,7 +1259,7 @@ impl serialize::Decoder for Decoder { f: |&mut Decoder| -> T) -> T { debug!("read_struct_field(name={}, idx={})", name, idx); - match self.stack.pop() { + match self.stack.pop().unwrap() { Object(mut obj) => { let value = match obj.pop(&name.to_owned()) { None => self.missing_field(name, obj), @@ -1302,7 +1302,7 @@ impl serialize::Decoder for Decoder { } fn read_option(&mut self, f: |&mut Decoder, bool| -> T) -> T { - match self.stack.pop() { + match self.stack.pop().unwrap() { Null => f(self, false), value => { self.stack.push(value); f(self, true) } } @@ -1310,7 +1310,7 @@ impl serialize::Decoder for Decoder { fn read_seq(&mut self, f: |&mut Decoder, uint| -> T) -> T { debug!("read_seq()"); - let len = match self.stack.pop() { + let len = match self.stack.pop().unwrap() { List(list) => { let len = list.len(); for v in list.move_rev_iter() { @@ -1330,7 +1330,7 @@ impl serialize::Decoder for Decoder { fn read_map(&mut self, f: |&mut Decoder, uint| -> T) -> T { debug!("read_map()"); - let len = match self.stack.pop() { + let len = match self.stack.pop().unwrap() { Object(obj) => { let len = obj.len(); for (key, value) in obj.move_iter() { diff --git a/src/libextra/priority_queue.rs b/src/libextra/priority_queue.rs index 9b6d12580ec..33b3931e989 100644 --- a/src/libextra/priority_queue.rs +++ b/src/libextra/priority_queue.rs @@ -59,7 +59,7 @@ impl PriorityQueue { /// Pop the greatest item from the queue - fails if empty pub fn pop(&mut self) -> T { - let mut item = self.data.pop(); + let mut item = self.data.pop().unwrap(); if !self.is_empty() { swap(&mut item, &mut self.data[0]); self.siftdown(0); @@ -235,7 +235,7 @@ mod tests { let mut heap = PriorityQueue::from_vec(data); while !heap.is_empty() { assert_eq!(heap.top(), sorted.last().unwrap()); - assert_eq!(heap.pop(), sorted.pop()); + assert_eq!(heap.pop(), sorted.pop().unwrap()); } } diff --git a/src/libextra/terminfo/parm.rs b/src/libextra/terminfo/parm.rs index eac450d9562..bd9eadc078d 100644 --- a/src/libextra/terminfo/parm.rs +++ b/src/libextra/terminfo/parm.rs @@ -121,7 +121,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) match cur { '%' => { output.push(c); state = Nothing }, 'c' => if stack.len() > 0 { - match stack.pop() { + match stack.pop().unwrap() { // if c is 0, use 0200 (128) for ncurses compatibility Number(c) => output.push(if c == 0 { 128 } else { c } as u8), _ => return Err(~"a non-char was used with %c") @@ -133,82 +133,82 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) '\'' => state = CharConstant, '{' => state = IntConstant(0), 'l' => if stack.len() > 0 { - match stack.pop() { + match stack.pop().unwrap() { String(s) => stack.push(Number(s.len() as int)), _ => return Err(~"a non-str was used with %l") } } else { return Err(~"stack is empty") }, '+' => if stack.len() > 1 { - match (stack.pop(), stack.pop()) { + match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x + y)), _ => return Err(~"non-numbers on stack with +") } } else { return Err(~"stack is empty") }, '-' => if stack.len() > 1 { - match (stack.pop(), stack.pop()) { + match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x - y)), _ => return Err(~"non-numbers on stack with -") } } else { return Err(~"stack is empty") }, '*' => if stack.len() > 1 { - match (stack.pop(), stack.pop()) { + match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x * y)), _ => return Err(~"non-numbers on stack with *") } } else { return Err(~"stack is empty") }, '/' => if stack.len() > 1 { - match (stack.pop(), stack.pop()) { + match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x / y)), _ => return Err(~"non-numbers on stack with /") } } else { return Err(~"stack is empty") }, 'm' => if stack.len() > 1 { - match (stack.pop(), stack.pop()) { + match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x % y)), _ => return Err(~"non-numbers on stack with %") } } else { return Err(~"stack is empty") }, '&' => if stack.len() > 1 { - match (stack.pop(), stack.pop()) { + match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x & y)), _ => return Err(~"non-numbers on stack with &") } } else { return Err(~"stack is empty") }, '|' => if stack.len() > 1 { - match (stack.pop(), stack.pop()) { + match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x | y)), _ => return Err(~"non-numbers on stack with |") } } else { return Err(~"stack is empty") }, '^' => if stack.len() > 1 { - match (stack.pop(), stack.pop()) { + match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x ^ y)), _ => return Err(~"non-numbers on stack with ^") } } else { return Err(~"stack is empty") }, '=' => if stack.len() > 1 { - match (stack.pop(), stack.pop()) { + match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(if x == y { 1 } else { 0 })), _ => return Err(~"non-numbers on stack with =") } } else { return Err(~"stack is empty") }, '>' => if stack.len() > 1 { - match (stack.pop(), stack.pop()) { + match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(if x > y { 1 } else { 0 })), _ => return Err(~"non-numbers on stack with >") } } else { return Err(~"stack is empty") }, '<' => if stack.len() > 1 { - match (stack.pop(), stack.pop()) { + match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(if x < y { 1 } else { 0 })), _ => return Err(~"non-numbers on stack with <") } } else { return Err(~"stack is empty") }, 'A' => if stack.len() > 1 { - match (stack.pop(), stack.pop()) { + match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(0), Number(_)) => stack.push(Number(0)), (Number(_), Number(0)) => stack.push(Number(0)), (Number(_), Number(_)) => stack.push(Number(1)), @@ -216,21 +216,21 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) } } else { return Err(~"stack is empty") }, 'O' => if stack.len() > 1 { - match (stack.pop(), stack.pop()) { + match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(0), Number(0)) => stack.push(Number(0)), (Number(_), Number(_)) => stack.push(Number(1)), _ => return Err(~"non-numbers on stack with logical or") } } else { return Err(~"stack is empty") }, '!' => if stack.len() > 0 { - match stack.pop() { + match stack.pop().unwrap() { Number(0) => stack.push(Number(1)), Number(_) => stack.push(Number(0)), _ => return Err(~"non-number on stack with logical not") } } else { return Err(~"stack is empty") }, '~' => if stack.len() > 0 { - match stack.pop() { + match stack.pop().unwrap() { Number(x) => stack.push(Number(!x)), _ => return Err(~"non-number on stack with %~") } @@ -246,7 +246,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) // printf-style support for %doxXs 'd'|'o'|'x'|'X'|'s' => if stack.len() > 0 { let flags = Flags::new(); - let res = format(stack.pop(), FormatOp::from_char(cur), flags); + let res = format(stack.pop().unwrap(), FormatOp::from_char(cur), flags); if res.is_err() { return res } output.push_all(res.unwrap()) } else { return Err(~"stack is empty") }, @@ -270,7 +270,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) // conditionals '?' => (), 't' => if stack.len() > 0 { - match stack.pop() { + match stack.pop().unwrap() { Number(0) => state = SeekIfElse(0), Number(_) => (), _ => return Err(~"non-number on stack with conditional") @@ -293,12 +293,12 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) if cur >= 'A' && cur <= 'Z' { if stack.len() > 0 { let idx = (cur as u8) - ('A' as u8); - vars.sta[idx] = stack.pop(); + vars.sta[idx] = stack.pop().unwrap(); } else { return Err(~"stack is empty") } } else if cur >= 'a' && cur <= 'z' { if stack.len() > 0 { let idx = (cur as u8) - ('a' as u8); - vars.dyn[idx] = stack.pop(); + vars.dyn[idx] = stack.pop().unwrap(); } else { return Err(~"stack is empty") } } else { return Err(~"bad variable name in %P"); @@ -341,7 +341,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) old_state = Nothing; match (*fstate, cur) { (_,'d')|(_,'o')|(_,'x')|(_,'X')|(_,'s') => if stack.len() > 0 { - let res = format(stack.pop(), FormatOp::from_char(cur), *flags); + let res = format(stack.pop().unwrap(), FormatOp::from_char(cur), *flags); if res.is_err() { return res } output.push_all(res.unwrap()); old_state = state; // will cause state to go to Nothing diff --git a/src/libextra/test.rs b/src/libextra/test.rs index ed3dcb5d737..5f0270beb80 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -753,7 +753,7 @@ fn run_tests(opts: &TestOpts, while pending > 0 || !remaining.is_empty() { while pending < concurrency && !remaining.is_empty() { - let test = remaining.pop(); + let test = remaining.pop().unwrap(); if concurrency == 1 { // We are doing one test at a time so we can print the name // of the test before we run it. Useful for debugging tests diff --git a/src/libextra/treemap.rs b/src/libextra/treemap.rs index 7b8258ec5ae..683fe2e070b 100644 --- a/src/libextra/treemap.rs +++ b/src/libextra/treemap.rs @@ -359,7 +359,7 @@ macro_rules! define_iterator { } self.stack.push(node); } else { - let node = self.stack.pop(); + let node = self.stack.pop().unwrap(); let next_node = if forward { addr!(& $($addr_mut)* node.right) } else { @@ -496,7 +496,7 @@ impl Iterator<(K, V)> for MoveEntries { left: left, right: right, level: level - } = self.stack.pop(); + } = self.stack.pop().unwrap(); match left { Some(~left) => { diff --git a/src/libgreen/sched.rs b/src/libgreen/sched.rs index 3554d435e55..989b8dc31f8 100644 --- a/src/libgreen/sched.rs +++ b/src/libgreen/sched.rs @@ -1285,8 +1285,11 @@ mod test { ports.push(port); }); - while !ports.is_empty() { - ports.pop().recv(); + loop { + match ports.pop() { + Some(port) => port.recv(), + None => break, + } } } } diff --git a/src/librustc/middle/borrowck/gather_loans/mod.rs b/src/librustc/middle/borrowck/gather_loans/mod.rs index 14fd3799caf..e45ea77b49e 100644 --- a/src/librustc/middle/borrowck/gather_loans/mod.rs +++ b/src/librustc/middle/borrowck/gather_loans/mod.rs @@ -339,7 +339,7 @@ impl<'a> GatherLoanCtxt<'a> { } pub fn pop_repeating_id(&mut self, id: ast::NodeId) { - let popped = self.repeating_ids.pop(); + let popped = self.repeating_ids.pop().unwrap(); assert_eq!(id, popped); } diff --git a/src/librustc/middle/dataflow.rs b/src/librustc/middle/dataflow.rs index e79d1649099..835f53a50ac 100644 --- a/src/librustc/middle/dataflow.rs +++ b/src/librustc/middle/dataflow.rs @@ -504,7 +504,7 @@ impl<'a, O:DataFlowOperator> PropagationContext<'a, O> { // add the bits from any early return via `break`, // `continue`, or `return` into `func_bits` - let loop_scope = loop_scopes.pop(); + let loop_scope = loop_scopes.pop().unwrap(); join_bits(&self.dfcx.oper, loop_scope.break_bits, func_bits); // add `func_bits` to the entry bits for `expr`, @@ -563,7 +563,7 @@ impl<'a, O:DataFlowOperator> PropagationContext<'a, O> { }); self.walk_block(blk, body_bits, loop_scopes); self.add_to_entry_set(expr.id, body_bits); - let new_loop_scope = loop_scopes.pop(); + let new_loop_scope = loop_scopes.pop().unwrap(); copy_bits(new_loop_scope.break_bits, in_out); } @@ -588,7 +588,7 @@ impl<'a, O:DataFlowOperator> PropagationContext<'a, O> { self.walk_block(blk, body_bits, loop_scopes); self.add_to_entry_set(expr.id, body_bits); - let new_loop_scope = loop_scopes.pop(); + let new_loop_scope = loop_scopes.pop().unwrap(); assert_eq!(new_loop_scope.loop_id, expr.id); copy_bits(new_loop_scope.break_bits, in_out); } diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 746cc74d7f6..c333bc58fee 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -129,7 +129,7 @@ impl MarkSymbolVisitor { fn mark_live_symbols(&mut self) { let mut scanned = HashSet::new(); while self.worklist.len() > 0 { - let id = self.worklist.pop(); + let id = self.worklist.pop().unwrap(); if scanned.contains(&id) { continue } diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 6f8ad77e90b..66d706e3621 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -284,7 +284,7 @@ impl ReachableContext { if worklist.get().len() == 0 { break } - let search_item = worklist.get().pop(); + let search_item = worklist.get().pop().unwrap(); if scanned.contains(&search_item) { continue } diff --git a/src/librustc/middle/trans/cleanup.rs b/src/librustc/middle/trans/cleanup.rs index d4b9af17845..1f0e99de264 100644 --- a/src/librustc/middle/trans/cleanup.rs +++ b/src/librustc/middle/trans/cleanup.rs @@ -396,8 +396,11 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> { let llbb = self.get_or_create_landing_pad(); // Push the scopes we removed back on: - while !popped_scopes.is_empty() { - self.push_scope(popped_scopes.pop()); + loop { + match popped_scopes.pop() { + Some(scope) => self.push_scope(scope), + None => break + } } assert_eq!(self.scopes_len(), orig_scopes_len); @@ -470,7 +473,7 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> { self.scopes_len() - 1); let mut scopes = self.scopes.borrow_mut(); - scopes.get().pop() + scopes.get().pop().unwrap() } fn top_scope(&self, f: |&CleanupScope<'a>| -> R) -> R { @@ -608,7 +611,7 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> { // At this point, `popped_scopes` is empty, and so the final block // that we return to the user is `Cleanup(AST 24)`. while !popped_scopes.is_empty() { - let mut scope = popped_scopes.pop(); + let mut scope = popped_scopes.pop().unwrap(); if scope.cleanups.iter().any(|c| cleanup_is_suitable_for(*c, label)) { diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 31ac97965b9..01fb18d73c2 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -2336,7 +2336,7 @@ pub fn is_instantiable(cx: ctxt, r_ty: t) -> bool { seen.push(did); let fields = struct_fields(cx, did, substs); let r = fields.iter().any(|f| type_requires(cx, seen, r_ty, f.mt.ty)); - seen.pop(); + seen.pop().unwrap(); r } @@ -2357,7 +2357,7 @@ pub fn is_instantiable(cx: ctxt, r_ty: t) -> bool { type_requires(cx, seen, r_ty, sty) }) }); - seen.pop(); + seen.pop().unwrap(); r } }; diff --git a/src/librustc/middle/typeck/check/regionmanip.rs b/src/librustc/middle/typeck/check/regionmanip.rs index c8fde97e4d6..daf5bdd9ea3 100644 --- a/src/librustc/middle/typeck/check/regionmanip.rs +++ b/src/librustc/middle/typeck/check/regionmanip.rs @@ -107,7 +107,7 @@ pub fn relate_nested_regions(tcx: ty::ctxt, self.relate(r); self.stack.push(r); ty_fold::super_fold_ty(self, mt.ty); - self.stack.pop(); + self.stack.pop().unwrap(); } _ => { diff --git a/src/librustc/middle/typeck/infer/mod.rs b/src/librustc/middle/typeck/infer/mod.rs index cb714399c16..68fb4b1e579 100644 --- a/src/librustc/middle/typeck/infer/mod.rs +++ b/src/librustc/middle/typeck/infer/mod.rs @@ -489,7 +489,7 @@ pub fn uok() -> ures { fn rollback_to(vb: &mut ValsAndBindings, len: uint) { while vb.bindings.len() != len { - let (vid, old_v) = vb.bindings.pop(); + let (vid, old_v) = vb.bindings.pop().unwrap(); vb.vals.insert(vid.to_uint(), old_v); } } diff --git a/src/librustc/middle/typeck/infer/region_inference/mod.rs b/src/librustc/middle/typeck/infer/region_inference/mod.rs index b5e67361378..536bbd0b20d 100644 --- a/src/librustc/middle/typeck/infer/region_inference/mod.rs +++ b/src/librustc/middle/typeck/infer/region_inference/mod.rs @@ -150,7 +150,7 @@ impl RegionVarBindings { debug!("RegionVarBindings: commit()"); let mut undo_log = self.undo_log.borrow_mut(); while undo_log.get().len() > 0 { - undo_log.get().pop(); + undo_log.get().pop().unwrap(); } } @@ -158,14 +158,14 @@ impl RegionVarBindings { debug!("RegionVarBindings: rollback_to({})", snapshot); let mut undo_log = self.undo_log.borrow_mut(); while undo_log.get().len() > snapshot { - let undo_item = undo_log.get().pop(); + let undo_item = undo_log.get().pop().unwrap(); debug!("undo_item={:?}", undo_item); match undo_item { Snapshot => {} AddVar(vid) => { let mut var_origins = self.var_origins.borrow_mut(); assert_eq!(var_origins.get().len(), vid.to_uint() + 1); - var_origins.get().pop(); + var_origins.get().pop().unwrap(); } AddConstraint(ref constraint) => { let mut constraints = self.constraints.borrow_mut(); @@ -1234,7 +1234,7 @@ impl RegionVarBindings { process_edges(self, &mut state, graph, orig_node_idx, dir); while !state.stack.is_empty() { - let node_idx = state.stack.pop(); + let node_idx = state.stack.pop().unwrap(); let classification = var_data[node_idx.to_uint()].classification; // check whether we've visited this node on some previous walk diff --git a/src/librustc/middle/typeck/infer/resolve.rs b/src/librustc/middle/typeck/infer/resolve.rs index 498f4707f92..85585ecaf54 100644 --- a/src/librustc/middle/typeck/infer/resolve.rs +++ b/src/librustc/middle/typeck/infer/resolve.rs @@ -242,7 +242,7 @@ impl ResolveState { ty::mk_var(tcx, vid) } }; - self.v_seen.pop(); + self.v_seen.pop().unwrap(); return t1; } } diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index fee97232fa0..9a9b588fa47 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -635,8 +635,8 @@ impl DocFolder for Cache { i => i, }; - if pushed { self.stack.pop(); } - if parent_pushed { self.parent_stack.pop(); } + if pushed { self.stack.pop().unwrap(); } + if parent_pushed { self.parent_stack.pop().unwrap(); } self.privmod = orig_privmod; return ret; } @@ -673,7 +673,7 @@ impl Context { self.dst = prev; let len = self.root_path.len(); self.root_path.truncate(len - 3); - self.current.pop(); + self.current.pop().unwrap(); return ret; } @@ -693,11 +693,13 @@ impl Context { local_data::set(cache_key, Arc::new(cache)); let mut work = ~[(self, item)]; - while work.len() > 0 { - let (mut cx, item) = work.pop(); - cx.item(item, |cx, item| { - work.push((cx.clone(), item)); - }) + loop { + match work.pop() { + Some((mut cx, item)) => cx.item(item, |cx, item| { + work.push((cx.clone(), item)); + }), + None => break, + } } } diff --git a/src/librustpkg/crate_id.rs b/src/librustpkg/crate_id.rs index 9a3c47823e0..239abbe546f 100644 --- a/src/librustpkg/crate_id.rs +++ b/src/librustpkg/crate_id.rs @@ -121,7 +121,7 @@ impl Iterator<(Path, Path)> for Prefixes { None } else { - let last = self.components.pop(); + let last = self.components.pop().unwrap(); self.remaining.unshift(last); // converting to str and then back is a little unfortunate Some((Path::new(self.components.connect("/")), diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index 4c8a640a849..a0c451647d3 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -161,8 +161,11 @@ impl Drop for Process { fn drop(&mut self) { // Close all I/O before exiting to ensure that the child doesn't wait // forever to print some text or something similar. - for _ in range(0, self.io.len()) { - self.io.pop(); + loop { + match self.io.pop() { + Some(_) => (), + None => break, + } } self.wait(); diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index 0c41c538c6c..5c35c500e6c 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -351,7 +351,7 @@ pub fn float_to_str_bytes_common= radix / 2 { // -> need to round let mut i: int = buf.len() as int - 1; loop { diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index b228dc7f1ff..dc547d702ba 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -426,7 +426,7 @@ fn normalize_helper<'a>(v: &'a [u8], is_abs: bool) -> Option<~[&'a [u8]]> { else if comp == bytes!("..") { if is_abs && comps.is_empty() { changed = true } else if comps.len() == n_up { comps.push(dot_dot_static); n_up += 1 } - else { comps.pop(); changed = true } + else { comps.pop().unwrap(); changed = true } } else { comps.push(comp) } } if changed { diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 0e5b7894e74..89640add7d0 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -1025,7 +1025,7 @@ fn normalize_helper<'a>(s: &'a str, prefix: Option) -> (bool,Option< }; if (is_abs || has_abs_prefix) && comps.is_empty() { changed = true } else if comps.len() == n_up { comps.push(".."); n_up += 1 } - else { comps.pop(); changed = true } + else { comps.pop().unwrap(); changed = true } } else { comps.push(comp) } } if !changed && !prefix_is_verbatim(prefix) { diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs index 7255448bd23..8f7d01f263d 100644 --- a/src/libstd/repr.rs +++ b/src/libstd/repr.rs @@ -123,7 +123,7 @@ impl<'a> MovePtr for ReprVisitor<'a> { self.ptr_stk.push(self.ptr); } fn pop_ptr(&mut self) { - self.ptr = self.ptr_stk.pop(); + self.ptr = self.ptr_stk.pop().unwrap(); } } @@ -471,7 +471,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> { n_fields: uint, name: &str) -> bool { let mut write = false; - match self.var_stk.pop() { + match self.var_stk.pop().unwrap() { SearchingFor(sought) => { if disr_val == sought { self.var_stk.push(Matched); @@ -534,7 +534,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> { _sz: uint, _align: uint) -> bool { - match self.var_stk.pop() { + match self.var_stk.pop().unwrap() { SearchingFor(..) => fail!("enum value matched no variant"), _ => true } diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index b3d0e9cb10a..1dfd2ea5600 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -1381,10 +1381,8 @@ pub trait OwnedVector { /// assert!(a == ~[~1, ~2, ~3, ~4]); /// ``` fn push_all_move(&mut self, rhs: ~[T]); - /// Remove the last element from a vector and return it, failing if it is empty - fn pop(&mut self) -> T; /// Remove the last element from a vector and return it, or `None` if it is empty - fn pop_opt(&mut self) -> Option; + fn pop(&mut self) -> Option; /// Removes the first element from a vector and return it fn shift(&mut self) -> T; /// Removes the first element from a vector and return it, or `None` if it is empty @@ -1565,7 +1563,7 @@ impl OwnedVector for ~[T] { } } - fn pop_opt(&mut self) -> Option { + fn pop(&mut self) -> Option { match self.len() { 0 => None, ln => { @@ -1579,11 +1577,6 @@ impl OwnedVector for ~[T] { } - #[inline] - fn pop(&mut self) -> T { - self.pop_opt().expect("pop: empty vector") - } - #[inline] fn shift(&mut self) -> T { self.shift_opt().expect("shift: empty vector") @@ -3168,28 +3161,16 @@ mod tests { assert_eq!(vec.slice_to(0), &[]); } - #[test] - fn test_pop() { - // Test on-heap pop. - let mut v = ~[1, 2, 3, 4, 5]; - let e = v.pop(); - assert_eq!(v.len(), 4u); - assert_eq!(v[0], 1); - assert_eq!(v[1], 2); - assert_eq!(v[2], 3); - assert_eq!(v[3], 4); - assert_eq!(e, 5); - } #[test] - fn test_pop_opt() { + fn test_pop() { let mut v = ~[5]; - let e = v.pop_opt(); + let e = v.pop(); assert_eq!(v.len(), 0); assert_eq!(e, Some(5)); - let f = v.pop_opt(); + let f = v.pop(); assert_eq!(f, None); - let g = v.pop_opt(); + let g = v.pop(); assert_eq!(g, None); } diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index 72ab81d8657..0585f1abecc 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -340,7 +340,7 @@ impl Folder for Ctx { _ => {} } - self.path.pop(); + self.path.pop().unwrap(); SmallVector::one(i) } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 6472551b049..47ae146d19b 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -904,7 +904,7 @@ pub fn mtwt_outer_mark(ctxt: SyntaxContext) -> Mrk { /// case pop and discard (so two of the same marks cancel) pub fn xorPush(marks: &mut ~[Mrk], mark: Mrk) { if (marks.len() > 0) && (getLast(marks) == mark) { - marks.pop(); + marks.pop().unwrap(); } else { marks.push(mark); } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index a90e118d02b..86982201303 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -356,7 +356,7 @@ impl<'a> ExtCtxt<'a> { pub fn print_backtrace(&self) { } pub fn backtrace(&self) -> Option<@ExpnInfo> { self.backtrace } pub fn mod_push(&mut self, i: ast::Ident) { self.mod_path.push(i); } - pub fn mod_pop(&mut self) { self.mod_path.pop(); } + pub fn mod_pop(&mut self) { self.mod_path.pop().unwrap(); } pub fn mod_path(&self) -> ~[ast::Ident] { self.mod_path.clone() } pub fn bt_push(&mut self, ei: codemap::ExpnInfo) { match ei { diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index d702ee3ead4..3c0d7aaf4f3 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -253,7 +253,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { lifetimes: OptVec, types: ~[P]) -> ast::Path { - let last_identifier = idents.pop(); + let last_identifier = idents.pop().unwrap(); let mut segments: ~[ast::PathSegment] = idents.move_iter() .map(|ident| { ast::PathSegment { diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index cddfa7d2aa0..fe519a31efa 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -841,7 +841,7 @@ impl<'a> MethodDef<'a> { matching, matches_so_far, match_count + 1); - matches_so_far.pop(); + matches_so_far.pop().unwrap(); arms.push(cx.arm(trait_.span, ~[ pattern ], arm_expr)); if enum_def.variants.len() > 1 { @@ -875,7 +875,7 @@ impl<'a> MethodDef<'a> { new_matching, matches_so_far, match_count + 1); - matches_so_far.pop(); + matches_so_far.pop().unwrap(); let arm = cx.arm(trait_.span, ~[ pattern ], arm_expr); arms.push(arm); diff --git a/src/libsyntax/ext/registrar.rs b/src/libsyntax/ext/registrar.rs index 265dd91d7f4..1c349c4343a 100644 --- a/src/libsyntax/ext/registrar.rs +++ b/src/libsyntax/ext/registrar.rs @@ -42,7 +42,7 @@ pub fn find_macro_registrar(diagnostic: @diagnostic::SpanHandler, match ctx.registrars.len() { 0 => None, 1 => { - let (node_id, _) = ctx.registrars.pop(); + let (node_id, _) = ctx.registrars.pop().unwrap(); Some(ast::DefId { crate: ast::LOCAL_CRATE, node: node_id diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index dc721f15c3b..492852c6a79 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -238,8 +238,11 @@ pub fn parse(sess: @ParseSess, let TokenAndSpan {tok: tok, sp: sp} = rdr.peek(); /* we append new items to this while we go */ - while !cur_eis.is_empty() { /* for each Earley Item */ - let ei = cur_eis.pop(); + loop { + let ei = match cur_eis.pop() { + None => break, /* for each Earley Item */ + Some(ei) => ei, + }; let idx = ei.idx; let len = ei.elts.len(); @@ -347,7 +350,7 @@ pub fn parse(sess: @ParseSess, if eof_eis.len() == 1u { let mut v = ~[]; for dv in eof_eis[0u].matches.mut_iter() { - v.push(dv.pop()); + v.push(dv.pop().unwrap()); } return Success(nameize(sess, ms, v)); } else if eof_eis.len() > 1u { @@ -376,13 +379,13 @@ pub fn parse(sess: @ParseSess, } else if next_eis.len() > 0u { /* Now process the next token */ while next_eis.len() > 0u { - cur_eis.push(next_eis.pop()); + cur_eis.push(next_eis.pop().unwrap()); } rdr.next_token(); } else /* bb_eis.len() == 1 */ { let mut rust_parser = Parser(sess, cfg.clone(), rdr.dup()); - let mut ei = bb_eis.pop(); + let mut ei = bb_eis.pop().unwrap(); match ei.elts[ei.idx].node { MatchNonterminal(_, ref name, idx) => { ei.matches[idx].push(@MatchedNonterminal( diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 4c78244bf08..20d544f52c9 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -204,8 +204,8 @@ pub fn tt_next_token(r: &TtReader) -> TokenAndSpan { { let mut repeat_idx = r.repeat_idx.borrow_mut(); let mut repeat_len = r.repeat_len.borrow_mut(); - repeat_idx.get().pop(); - repeat_len.get().pop(); + repeat_idx.get().pop().unwrap(); + repeat_len.get().pop().unwrap(); } } diff --git a/src/libsyntax/opt_vec.rs b/src/libsyntax/opt_vec.rs index d6f363eb6a0..ce3042cb9cd 100644 --- a/src/libsyntax/opt_vec.rs +++ b/src/libsyntax/opt_vec.rs @@ -48,10 +48,10 @@ impl OptVec { } } - pub fn pop(&mut self) -> T { + pub fn pop(&mut self) -> Option { match *self { Vec(ref mut v) => v.pop(), - Empty => fail!("pop from empty opt_vec") + Empty => None } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 30408fa1c2b..4e1703fe6b0 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2158,7 +2158,7 @@ impl Parser { // Parse the close delimiter. result.push(parse_any_tt_tok(self)); - self.open_braces.pop(); + self.open_braces.pop().unwrap(); TTDelim(@result) } @@ -3593,7 +3593,7 @@ impl Parser { } ); - let variadic = match args.pop_opt() { + let variadic = match args.pop() { Some(None) => true, Some(x) => { // Need to put back that last arg @@ -4218,7 +4218,7 @@ impl Parser { } fn pop_mod_path(&mut self) { - self.mod_path_stack.pop(); + self.mod_path_stack.pop().unwrap(); } // read a module from a source file. diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index c421c2f4d7a..902d9e1c284 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -511,7 +511,7 @@ impl Printer { debug!("print End -> pop End"); let print_stack = &mut self.print_stack; assert!((print_stack.len() != 0u)); - print_stack.pop(); + print_stack.pop().unwrap(); } Break(b) => { let top = self.get_top(); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 3ea48969069..cdfeebd3e1b 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -78,7 +78,7 @@ pub fn ibox(s: &mut State, u: uint) { pub fn end(s: &mut State) { { let mut boxes = s.boxes.borrow_mut(); - boxes.get().pop(); + boxes.get().pop().unwrap(); } pp::end(&mut s.s); } @@ -1090,11 +1090,11 @@ pub fn print_call_pre(s: &mut State, match sugar { ast::DoSugar => { head(s, "do"); - Some(base_args.pop()) + Some(base_args.pop().unwrap()) } ast::ForSugar => { head(s, "for"); - Some(base_args.pop()) + Some(base_args.pop().unwrap()) } ast::NoSugar => None } diff --git a/src/test/bench/msgsend-ring-mutex-arcs.rs b/src/test/bench/msgsend-ring-mutex-arcs.rs index b148df24833..a5838f20173 100644 --- a/src/test/bench/msgsend-ring-mutex-arcs.rs +++ b/src/test/bench/msgsend-ring-mutex-arcs.rs @@ -40,7 +40,7 @@ fn recv(p: &pipe) -> uint { while state.is_empty() { cond.wait(); } - state.pop() + state.pop().unwrap() }) } } diff --git a/src/test/bench/msgsend-ring-rw-arcs.rs b/src/test/bench/msgsend-ring-rw-arcs.rs index ea241d267c7..fa7026b6569 100644 --- a/src/test/bench/msgsend-ring-rw-arcs.rs +++ b/src/test/bench/msgsend-ring-rw-arcs.rs @@ -37,7 +37,7 @@ fn recv(p: &pipe) -> uint { while state.is_empty() { cond.wait(); } - state.pop() + state.pop().unwrap() }) }