[std::vec] Rename .pop_opt() to .pop(), drop the old .pop() behavior

This commit is contained in:
Simon Sapin 2013-12-23 16:20:52 +01:00
parent aa66b91767
commit bada25e425
43 changed files with 128 additions and 133 deletions

View File

@ -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)
}

View File

@ -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,

View File

@ -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();

View File

@ -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);

View File

@ -122,7 +122,7 @@ impl Iterator<Path> 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() {

View File

@ -1028,7 +1028,7 @@ impl<T : Iterator<char>> Parser<T> {
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<T>(&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<T>(&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<T>(&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() {

View File

@ -59,7 +59,7 @@ impl<T:Ord> PriorityQueue<T> {
/// 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());
}
}

View File

@ -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

View File

@ -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

View File

@ -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<K, V> Iterator<(K, V)> for MoveEntries<K,V> {
left: left,
right: right,
level: level
} = self.stack.pop();
} = self.stack.pop().unwrap();
match left {
Some(~left) => {

View File

@ -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,
}
}
}
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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<R>(&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))
{

View File

@ -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
}
};

View File

@ -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();
}
_ => {

View File

@ -489,7 +489,7 @@ pub fn uok() -> ures {
fn rollback_to<V:Clone + Vid,T:Clone>(vb: &mut ValsAndBindings<V, T>,
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);
}
}

View File

@ -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

View File

@ -242,7 +242,7 @@ impl ResolveState {
ty::mk_var(tcx, vid)
}
};
self.v_seen.pop();
self.v_seen.pop().unwrap();
return t1;
}
}

View File

@ -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,
}
}
}

View File

@ -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("/")),

View File

@ -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();

View File

@ -351,7 +351,7 @@ pub fn float_to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Float+Round+
char::from_digit(val, radix).unwrap() as u8
};
let extra_digit = ascii2value(buf.pop());
let extra_digit = ascii2value(buf.pop().unwrap());
if extra_digit >= radix / 2 { // -> need to round
let mut i: int = buf.len() as int - 1;
loop {

View File

@ -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 {

View File

@ -1025,7 +1025,7 @@ fn normalize_helper<'a>(s: &'a str, prefix: Option<PathPrefix>) -> (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) {

View File

@ -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
}

View File

@ -1381,10 +1381,8 @@ pub trait OwnedVector<T> {
/// 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<T>;
fn pop(&mut self) -> Option<T>;
/// 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<T> OwnedVector<T> for ~[T] {
}
}
fn pop_opt(&mut self) -> Option<T> {
fn pop(&mut self) -> Option<T> {
match self.len() {
0 => None,
ln => {
@ -1579,11 +1577,6 @@ impl<T> OwnedVector<T> 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);
}

View File

@ -340,7 +340,7 @@ impl<F: FoldOps> Folder for Ctx<F> {
_ => {}
}
self.path.pop();
self.path.pop().unwrap();
SmallVector::one(i)
}

View File

@ -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);
}

View File

@ -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 {

View File

@ -253,7 +253,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
lifetimes: OptVec<ast::Lifetime>,
types: ~[P<ast::Ty>])
-> 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 {

View File

@ -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);

View File

@ -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

View File

@ -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(

View File

@ -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();
}
}

View File

@ -48,10 +48,10 @@ impl<T> OptVec<T> {
}
}
pub fn pop(&mut self) -> T {
pub fn pop(&mut self) -> Option<T> {
match *self {
Vec(ref mut v) => v.pop(),
Empty => fail!("pop from empty opt_vec")
Empty => None
}
}

View File

@ -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.

View File

@ -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();

View File

@ -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
}

View File

@ -40,7 +40,7 @@ fn recv(p: &pipe) -> uint {
while state.is_empty() {
cond.wait();
}
state.pop()
state.pop().unwrap()
})
}
}

View File

@ -37,7 +37,7 @@ fn recv(p: &pipe) -> uint {
while state.is_empty() {
cond.wait();
}
state.pop()
state.pop().unwrap()
})
}