]> git.lizzy.rs Git - rust.git/commitdiff
[std::vec] Rename .last_opt() to .last(), drop the old .last() behavior
authorSimon Sapin <simon.sapin@exyr.org>
Mon, 23 Dec 2013 14:08:23 +0000 (15:08 +0100)
committerSimon Sapin <simon.sapin@exyr.org>
Tue, 21 Jan 2014 23:48:46 +0000 (15:48 -0800)
27 files changed:
src/libextra/num/bigint.rs
src/libextra/priority_queue.rs
src/librustc/front/feature_gate.rs
src/librustc/middle/borrowck/gather_loans/mod.rs
src/librustc/middle/cfg/construct.rs
src/librustc/middle/lint.rs
src/librustc/middle/liveness.rs
src/librustc/middle/privacy.rs
src/librustc/middle/resolve.rs
src/librustc/middle/trans/_match.rs
src/librustc/middle/trans/base.rs
src/librustc/middle/trans/cleanup.rs
src/librustc/middle/trans/debuginfo.rs
src/librustc/middle/typeck/astconv.rs
src/librustc/middle/typeck/check/mod.rs
src/librustdoc/html/format.rs
src/librustdoc/html/render.rs
src/libstd/vec.rs
src/libsyntax/ast_map.rs
src/libsyntax/ast_util.rs
src/libsyntax/codemap.rs
src/libsyntax/ext/deriving/generic.rs
src/libsyntax/ext/tt/transcribe.rs
src/libsyntax/opt_vec.rs
src/libsyntax/parse/parser.rs
src/libsyntax/print/pprust.rs
src/test/bench/task-perf-alloc-unwind.rs

index 178356ac2613283906bb80cede7fc15bb3cdaa2b..8729cf1b68553ece9aee7b3bc46b0eb8443a1d22 100644 (file)
@@ -385,7 +385,7 @@ fn div_mod_floor(&self, other: &BigUint) -> (BigUint, BigUint) {
         }
 
         let mut shift = 0;
-        let mut n = *other.data.last();
+        let mut n = *other.data.last().unwrap();
         while n < (1 << BigDigit::bits - 2) {
             n <<= 1;
             shift += 1;
@@ -434,7 +434,7 @@ fn div_estimate(a: &BigUint, b: &BigUint, n: uint)
             }
 
             let an = a.data.slice(a.data.len() - n, a.data.len());
-            let bn = *b.data.last();
+            let bn = *b.data.last().unwrap();
             let mut d = ~[];
             let mut carry = 0;
             for elt in an.rev_iter() {
@@ -798,7 +798,7 @@ fn shr_bits(&self, n_bits: uint) -> BigUint {
     /// Determines the fewest bits necessary to express the `BigUint`.
     pub fn bits(&self) -> uint {
         if self.is_zero() { return 0; }
-        let zeros = self.data.last().leading_zeros();
+        let zeros = self.data.last().unwrap().leading_zeros();
         return self.data.len()*BigDigit::bits - (zeros as uint);
     }
 }
index cf3c265e3fbe0d69fe0507f2e1d571e9d70a70d5..9b6d12580ecc44020953698d17a0874b04f38f95 100644 (file)
@@ -234,7 +234,7 @@ fn test_top_and_pop() {
         sorted.sort();
         let mut heap = PriorityQueue::from_vec(data);
         while !heap.is_empty() {
-            assert_eq!(heap.top(), sorted.last());
+            assert_eq!(heap.top(), sorted.last().unwrap());
             assert_eq!(heap.pop(), sorted.pop());
         }
     }
index 26ba38f5f8cca85d231cdcfbb59ebfd6f5f40818..a0a9800926ebc829e018cac3a37cdad70de32c1d 100644 (file)
@@ -179,17 +179,17 @@ fn visit_item(&mut self, i: &ast::Item, _:()) {
     fn visit_mac(&mut self, macro: &ast::Mac, _: ()) {
         let ast::MacInvocTT(ref path, _, _) = macro.node;
 
-        if path.segments.last().identifier == self.sess.ident_of("macro_rules") {
+        if path.segments.last().unwrap().identifier == self.sess.ident_of("macro_rules") {
             self.gate_feature("macro_rules", path.span, "macro definitions are \
                 not stable enough for use and are subject to change");
         }
 
-        else if path.segments.last().identifier == self.sess.ident_of("asm") {
+        else if path.segments.last().unwrap().identifier == self.sess.ident_of("asm") {
             self.gate_feature("asm", path.span, "inline assembly is not \
                 stable enough for use and is subject to change");
         }
 
-        else if path.segments.last().identifier == self.sess.ident_of("log_syntax") {
+        else if path.segments.last().unwrap().identifier == self.sess.ident_of("log_syntax") {
             self.gate_feature("log_syntax", path.span, "`log_syntax!` is not \
                 stable enough for use and is subject to change");
         }
index 00e648db732e7ff05abbe58bbca660c2ca37c52b..14fd3799caf1b52620680fa5db37bdcc15299960 100644 (file)
@@ -445,7 +445,7 @@ pub fn guarantee_valid(&mut self,
             return;
         }
 
-        let root_ub = { *self.repeating_ids.last() }; // FIXME(#5074)
+        let root_ub = { *self.repeating_ids.last().unwrap() }; // FIXME(#5074)
 
         // Check that the lifetime of the borrow does not exceed
         // the lifetime of the data being borrowed.
index 527d74f8a862fff3a02d4e576eeccb743157faf2..dc0b700da522a7d7b9a772e7b18622bb0e862427 100644 (file)
@@ -495,7 +495,7 @@ fn find_scope(&self,
                   label: Option<ast::Name>) -> LoopScope {
         match label {
             None => {
-                return *self.loop_scopes.last();
+                return *self.loop_scopes.last().unwrap();
             }
 
             Some(_) => {
index 68f71ddfc473b0fcb7db2e69841f20d420d63bca..e780864ffd507749df76b096ae48fa894ba0f9da 100644 (file)
@@ -1077,7 +1077,7 @@ fn check_pat_non_uppercase_statics(cx: &Context, p: &ast::Pat) {
     match (&p.node, def_map.get().find(&p.id)) {
         (&ast::PatIdent(_, ref path, _), Some(&ast::DefStatic(_, false))) => {
             // last identifier alone is right choice for this lint.
-            let ident = path.segments.last().identifier;
+            let ident = path.segments.last().unwrap().identifier;
             let s = cx.tcx.sess.str_of(ident);
             if s.chars().any(|c| c.is_lowercase()) {
                 cx.span_lint(NonUppercasePatternStatics, path.span,
index e55229b37eba81053c3956e17d84aefeb7052828..03d7c56aeb6f4bdc251811464e384ffe1f825faf 100644 (file)
@@ -790,7 +790,7 @@ pub fn find_loop_scope(&self,
 
     pub fn last_loop_scope(&self) -> NodeId {
         let loop_scope = self.loop_scope.borrow();
-        *loop_scope.get().last()
+        *loop_scope.get().last().unwrap()
     }
 
     pub fn ln_str(&self, ln: LiveNode) -> ~str {
@@ -1593,7 +1593,7 @@ pub fn check_ret(&self,
             } else {
                 let ends_with_stmt = match body.expr {
                     None if body.stmts.len() > 0 =>
-                        match body.stmts.last().node {
+                        match body.stmts.last().unwrap().node {
                             StmtSemi(e, _) => {
                                 let t_stmt = ty::expr_ty(self.tcx, e);
                                 ty::get(t_stmt).sty == ty::get(t_ret).sty
@@ -1603,7 +1603,7 @@ pub fn check_ret(&self,
                     _ => false
                 };
                 if ends_with_stmt {
-                    let last_stmt = body.stmts.last();
+                    let last_stmt = body.stmts.last().unwrap();
                     let span_semicolon = Span {
                         lo: last_stmt.span.hi,
                         hi: last_stmt.span.hi,
index a430790a2af30a6c7703b11a98e0b7725b91830c..3d5267cd9285cce528250e63c097eb6e288cb9c9 100644 (file)
@@ -595,7 +595,7 @@ fn check_path(&mut self, span: Span, path_id: ast::NodeId, path: &ast::Path) {
             match *self.last_private_map.get(&path_id) {
                 resolve::AllPublic => {},
                 resolve::DependsOn(def) => {
-                    let name = token::ident_to_str(&path.segments.last()
+                    let name = token::ident_to_str(&path.segments.last().unwrap()
                                                         .identifier);
                     self.ensure_public(span, def, Some(origdid),
                                        format!("{} `{}`", tyname, name));
index 7b094591b1a39d92f8b8c050e6dbb812641f0588..082c755b8321e37646db0aad730375388e500c7c 100644 (file)
@@ -1476,7 +1476,7 @@ fn build_reduced_graph_for_view_item(&mut self, view_item: &ViewItem,
                     match view_path.node {
                         ViewPathSimple(binding, ref full_path, id) => {
                             let source_ident =
-                                full_path.segments.last().identifier;
+                                full_path.segments.last().unwrap().identifier;
                             let subclass = @SingleImport(binding,
                                                          source_ident);
                             self.build_import_directive(module_,
@@ -4303,7 +4303,7 @@ fn resolve_type(&mut self, ty: &Ty) {
 
                 // First, check to see whether the name is a primitive type.
                 if path.segments.len() == 1 {
-                    let id = path.segments.last().identifier;
+                    let id = path.segments.last().unwrap().identifier;
 
                     match self.primitive_type_table
                             .primitive_types
@@ -4342,7 +4342,7 @@ fn resolve_type(&mut self, ty: &Ty) {
                                 debug!("(resolving type) resolved `{}` to \
                                         type {:?}",
                                        self.session.str_of(path.segments
-                                                               .last()
+                                                               .last().unwrap()
                                                                .identifier),
                                        def);
                                 result_def = Some(def);
@@ -4561,7 +4561,7 @@ struct in scope",
                                 path.span,
                                 format!("`{}` is not an enum variant or constant",
                                      self.session.str_of(
-                                         path.segments.last().identifier)))
+                                         path.segments.last().unwrap().identifier)))
                         }
                         None => {
                             self.resolve_error(path.span,
@@ -4592,7 +4592,7 @@ struct in scope",
                                 format!("`{}` is not an enum variant, struct or const",
                                      self.session
                                          .str_of(path.segments
-                                                     .last()
+                                                     .last().unwrap()
                                                      .identifier)));
                         }
                         None => {
@@ -4601,7 +4601,7 @@ struct in scope",
                                                     struct or const `{}`",
                                                     self.session
                                                         .str_of(path.segments
-                                                                    .last()
+                                                                    .last().unwrap()
                                                                     .identifier)));
                         }
                     }
@@ -4722,7 +4722,7 @@ fn resolve_path(&mut self,
 
         let unqualified_def =
                 self.resolve_identifier(path.segments
-                                            .last()
+                                            .last().unwrap()
                                             .identifier,
                                         namespace,
                                         check_ribs,
@@ -4883,7 +4883,7 @@ fn resolve_module_relative_path(&mut self,
             }
         }
 
-        let ident = path.segments.last().identifier;
+        let ident = path.segments.last().unwrap().identifier;
         let def = match self.resolve_definition_of_name_in_module(containing_module,
                                                         ident,
                                                         namespace) {
@@ -4952,7 +4952,7 @@ fn resolve_crate_relative_path(&mut self,
             }
         }
 
-        let name = path.segments.last().identifier;
+        let name = path.segments.last().unwrap().identifier;
         match self.resolve_definition_of_name_in_module(containing_module,
                                                         name,
                                                         namespace) {
index 96367c769fdbfa2f1061c93c84206e44fa8f3bce..5bd8eb6386fcff4d055f44f7cf84c096270fa5ae 100644 (file)
@@ -575,7 +575,7 @@ fn enter_default<'r,'b>(
     // non guarded matches, and thus by exhaustiveness, we know that
     // we don't need any default cases. If the check *isn't* nonexhaustive
     // (because chk is Some), then we need the defaults anyways.
-    let is_exhaustive = match matches.last_opt() {
+    let is_exhaustive = match matches.last() {
         Some(m) if m.data.arm.guard.is_some() && chk.is_infallible() => true,
         _ => false
     };
@@ -913,7 +913,7 @@ fn add_to_set(tcx: ty::ctxt, set: &mut ~[Opt], val: Opt) {
     // to not always merge conditions.
     fn add_veclen_to_set(set: &mut ~[Opt], i: uint,
                          len: uint, vlo: VecLenOpt) {
-        match set.last_opt() {
+        match set.last() {
             // If the last condition in the list matches the one we want
             // to add, then extend its range. Otherwise, make a new
             // vec_len with a range just covering the new entry.
index 6aa35096792ab7c9017a8d6be340692610a6d1ba..c654bbbd709d9637bfba6d3533930aaf090a5846 100644 (file)
@@ -2014,7 +2014,7 @@ fn exported_name(ccx: &CrateContext, path: ast_map::Path,
 
         // Don't mangle
         _ if attr::contains_name(attrs, "no_mangle")
-            => path_elem_to_str(*path.last(), token::get_ident_interner()),
+            => path_elem_to_str(*path.last().unwrap(), token::get_ident_interner()),
 
         // Usual name mangling
         _ => mangle_exported_name(ccx, path, ty)
index 6fed396a78c2a086ab088f286960d42d136ec4b5..d4b9af17845468256cfba055158e3ea8283b2a4d 100644 (file)
@@ -475,7 +475,7 @@ fn pop_scope(&self) -> CleanupScope<'a> {
 
     fn top_scope<R>(&self, f: |&CleanupScope<'a>| -> R) -> R {
         let scopes = self.scopes.borrow();
-        f(scopes.get().last())
+        f(scopes.get().last().unwrap())
     }
 
     fn trans_cleanups_to_exit_scope(&self,
@@ -568,7 +568,7 @@ fn trans_cleanups_to_exit_scope(&self,
             // and this scope is that loop, then stop popping and set
             // `prev_llbb` to the appropriate exit block from the loop.
             popped_scopes.push(self.pop_scope());
-            let scope = popped_scopes.last();
+            let scope = popped_scopes.last().unwrap();
             match label {
                 UnwindExit | ReturnExit => { }
                 LoopExit(id, exit) => {
index d256dd7e9a37955d36b2cc49a92f9afd8f1b38a2..4c5ed91e5f74750f1b94f37494778cae715548eb 100644 (file)
@@ -2036,7 +2036,7 @@ fn trait_metadata(cx: &CrateContext,
     // assigned the correct name, size, namespace, and source location. But it does not describe
     // the trait's methods.
     let path = ty::item_path(cx.tcx, def_id);
-    let ident = path.last().ident();
+    let ident = path.last().unwrap().ident();
     let name = ppaux::trait_store_to_str(cx.tcx, trait_store) +
                ppaux::mutability_to_str(mutability) +
                token::ident_to_str(&ident);
@@ -2361,7 +2361,7 @@ fn with_new_scope(cx: &CrateContext,
         // Create a new lexical scope and push it onto the stack
         let loc = cx.sess.codemap.lookup_char_pos(scope_span.lo);
         let file_metadata = file_metadata(cx, loc.file.name);
-        let parent_scope = scope_stack.last().scope_metadata;
+        let parent_scope = scope_stack.last().unwrap().scope_metadata;
 
         let scope_metadata = unsafe {
             llvm::LLVMDIBuilderCreateLexicalBlock(
@@ -2377,11 +2377,11 @@ fn with_new_scope(cx: &CrateContext,
         inner_walk(cx, scope_stack, scope_map);
 
         // pop artificial scopes
-        while scope_stack.last().ident.is_some() {
+        while scope_stack.last().unwrap().ident.is_some() {
             scope_stack.pop();
         }
 
-        if scope_stack.last().scope_metadata != scope_metadata {
+        if scope_stack.last().unwrap().scope_metadata != scope_metadata {
             cx.sess.span_bug(scope_span, "debuginfo: Inconsistency in scope management.");
         }
 
@@ -2392,11 +2392,12 @@ fn walk_block(cx: &CrateContext,
                   block: &ast::Block,
                   scope_stack: &mut ~[ScopeStackEntry],
                   scope_map: &mut HashMap<ast::NodeId, DIScope>) {
-        scope_map.insert(block.id, scope_stack.last().scope_metadata);
+        scope_map.insert(block.id, scope_stack.last().unwrap().scope_metadata);
 
         // The interesting things here are statements and the concluding expression.
         for statement in block.stmts.iter() {
-            scope_map.insert(ast_util::stmt_id(*statement), scope_stack.last().scope_metadata);
+            scope_map.insert(ast_util::stmt_id(*statement),
+                             scope_stack.last().unwrap().scope_metadata);
 
             match statement.node {
                 ast::StmtDecl(decl, _) => walk_decl(cx, decl, scope_stack, scope_map),
@@ -2417,7 +2418,7 @@ fn walk_decl(cx: &CrateContext,
                  scope_map: &mut HashMap<ast::NodeId, DIScope>) {
         match *decl {
             codemap::Spanned { node: ast::DeclLocal(local), .. } => {
-                scope_map.insert(local.id, scope_stack.last().scope_metadata);
+                scope_map.insert(local.id, scope_stack.last().unwrap().scope_metadata);
 
                 walk_pattern(cx, local.pat, scope_stack, scope_map);
 
@@ -2477,7 +2478,7 @@ fn walk_pattern(cx: &CrateContext,
                         // Create a new lexical scope and push it onto the stack
                         let loc = cx.sess.codemap.lookup_char_pos(pat.span.lo);
                         let file_metadata = file_metadata(cx, loc.file.name);
-                        let parent_scope = scope_stack.last().scope_metadata;
+                        let parent_scope = scope_stack.last().unwrap().scope_metadata;
 
                         let scope_metadata = unsafe {
                             llvm::LLVMDIBuilderCreateLexicalBlock(
@@ -2495,7 +2496,7 @@ fn walk_pattern(cx: &CrateContext,
 
                     } else {
                         // Push a new entry anyway so the name can be found
-                        let prev_metadata = scope_stack.last().scope_metadata;
+                        let prev_metadata = scope_stack.last().unwrap().scope_metadata;
                         scope_stack.push(ScopeStackEntry {
                             scope_metadata: prev_metadata,
                             ident: Some(ident)
@@ -2503,7 +2504,7 @@ fn walk_pattern(cx: &CrateContext,
                     }
                 }
 
-                scope_map.insert(pat.id, scope_stack.last().scope_metadata);
+                scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
 
                 for &sub_pat in sub_pat_opt.iter() {
                     walk_pattern(cx, sub_pat, scope_stack, scope_map);
@@ -2511,11 +2512,11 @@ fn walk_pattern(cx: &CrateContext,
             }
 
             ast::PatWild | ast::PatWildMulti => {
-                scope_map.insert(pat.id, scope_stack.last().scope_metadata);
+                scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
             }
 
             ast::PatEnum(_, ref sub_pats_opt) => {
-                scope_map.insert(pat.id, scope_stack.last().scope_metadata);
+                scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
 
                 for ref sub_pats in sub_pats_opt.iter() {
                     for &p in sub_pats.iter() {
@@ -2525,7 +2526,7 @@ fn walk_pattern(cx: &CrateContext,
             }
 
             ast::PatStruct(_, ref field_pats, _) => {
-                scope_map.insert(pat.id, scope_stack.last().scope_metadata);
+                scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
 
                 for &ast::FieldPat { pat: sub_pat, .. } in field_pats.iter() {
                     walk_pattern(cx, sub_pat, scope_stack, scope_map);
@@ -2533,7 +2534,7 @@ fn walk_pattern(cx: &CrateContext,
             }
 
             ast::PatTup(ref sub_pats) => {
-                scope_map.insert(pat.id, scope_stack.last().scope_metadata);
+                scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
 
                 for &sub_pat in sub_pats.iter() {
                     walk_pattern(cx, sub_pat, scope_stack, scope_map);
@@ -2541,23 +2542,23 @@ fn walk_pattern(cx: &CrateContext,
             }
 
             ast::PatUniq(sub_pat) | ast::PatRegion(sub_pat) => {
-                scope_map.insert(pat.id, scope_stack.last().scope_metadata);
+                scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
                 walk_pattern(cx, sub_pat, scope_stack, scope_map);
             }
 
             ast::PatLit(exp) => {
-                scope_map.insert(pat.id, scope_stack.last().scope_metadata);
+                scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
                 walk_expr(cx, exp, scope_stack, scope_map);
             }
 
             ast::PatRange(exp1, exp2) => {
-                scope_map.insert(pat.id, scope_stack.last().scope_metadata);
+                scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
                 walk_expr(cx, exp1, scope_stack, scope_map);
                 walk_expr(cx, exp2, scope_stack, scope_map);
             }
 
             ast::PatVec(ref front_sub_pats, ref middle_sub_pats, ref back_sub_pats) => {
-                scope_map.insert(pat.id, scope_stack.last().scope_metadata);
+                scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
 
                 for &sub_pat in front_sub_pats.iter() {
                     walk_pattern(cx, sub_pat, scope_stack, scope_map);
@@ -2579,7 +2580,7 @@ fn walk_expr(cx: &CrateContext,
                  scope_stack: &mut ~[ScopeStackEntry],
                  scope_map: &mut HashMap<ast::NodeId, DIScope>) {
 
-        scope_map.insert(exp.id, scope_stack.last().scope_metadata);
+        scope_map.insert(exp.id, scope_stack.last().unwrap().scope_metadata);
 
         match exp.node {
             ast::ExprLogLevel |
@@ -2606,14 +2607,14 @@ fn walk_expr(cx: &CrateContext,
             },
 
             ast::ExprUnary(node_id, _, sub_exp) => {
-                scope_map.insert(node_id, scope_stack.last().scope_metadata);
+                scope_map.insert(node_id, scope_stack.last().unwrap().scope_metadata);
                 walk_expr(cx, sub_exp, scope_stack, scope_map);
             }
 
             ast::ExprAssignOp(node_id, _, lhs, rhs) |
             ast::ExprIndex(node_id, lhs, rhs)        |
             ast::ExprBinary(node_id, _, lhs, rhs)    => {
-                scope_map.insert(node_id, scope_stack.last().scope_metadata);
+                scope_map.insert(node_id, scope_stack.last().unwrap().scope_metadata);
                 walk_expr(cx, lhs, scope_stack, scope_map);
                 walk_expr(cx, rhs, scope_stack, scope_map);
             }
@@ -2720,7 +2721,7 @@ fn walk_expr(cx: &CrateContext,
             }
 
             ast::ExprMethodCall(node_id, receiver_exp, _, _, ref args, _) => {
-                scope_map.insert(node_id, scope_stack.last().scope_metadata);
+                scope_map.insert(node_id, scope_stack.last().unwrap().scope_metadata);
                 walk_expr(cx, receiver_exp, scope_stack, scope_map);
 
                 for arg_exp in args.iter() {
index 3b787581e158d4ad1099bd603907dcec43d37585..2e25ac941a66dda43031b72dc07eb7c6864b7a67 100644 (file)
@@ -170,9 +170,9 @@ fn ast_path_substs<AC:AstConv,RS:RegionScope>(
     // region with the current anon region binding (in other words,
     // whatever & would get replaced with).
     let expected_num_region_params = decl_generics.region_param_defs.len();
-    let supplied_num_region_params = path.segments.last().lifetimes.len();
+    let supplied_num_region_params = path.segments.last().unwrap().lifetimes.len();
     let regions = if expected_num_region_params == supplied_num_region_params {
-        path.segments.last().lifetimes.map(
+        path.segments.last().unwrap().lifetimes.map(
             |l| ast_region_to_region(this.tcx(), l))
     } else {
         let anon_regions =
@@ -373,7 +373,7 @@ fn check_path_args(tcx: ty::ctxt,
         }
 
         if (flags & NO_REGIONS) != 0u {
-            if !path.segments.last().lifetimes.is_empty() {
+            if !path.segments.last().unwrap().lifetimes.is_empty() {
                 tcx.sess.span_err(
                     path.span,
                     "region parameters are not allowed on this type");
index 99cdbacbd5bed155d158657c91f61823e388191c..86d347fdac0d2d0f43d9917c38d29f42aae500e9 100644 (file)
@@ -3827,9 +3827,9 @@ pub fn instantiate_path(fcx: @FnCtxt,
     // determine the region parameters, using the value given by the user
     // (if any) and otherwise using a fresh region variable
     let num_expected_regions = tpt.generics.region_param_defs.len();
-    let num_supplied_regions = pth.segments.last().lifetimes.len();
+    let num_supplied_regions = pth.segments.last().unwrap().lifetimes.len();
     let regions = if num_expected_regions == num_supplied_regions {
-        pth.segments.last().lifetimes.map(
+        pth.segments.last().unwrap().lifetimes.map(
             |l| ast_region_to_region(fcx.tcx(), l))
     } else {
         if num_supplied_regions != 0 {
index e84b5bafaa83e52027e283f2decde54db2cba272..9b1caaa152ce3b341542ebcc1fe13379392eb445 100644 (file)
@@ -164,7 +164,7 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool,
         info: |&render::Cache| -> Option<(~[~str], &'static str)>) {
     // The generics will get written to both the title and link
     let mut generics = ~"";
-    let last = path.segments.last();
+    let last = path.segments.last().unwrap();
     if last.lifetimes.len() > 0 || last.types.len() > 0 {
         let mut counter = 0;
         generics.push_str("&lt;");
@@ -230,13 +230,13 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool,
                     }
                     match shortty {
                         "mod" => {
-                            url.push_str(*fqp.last());
+                            url.push_str(*fqp.last().unwrap());
                             url.push_str("/index.html");
                         }
                         _ => {
                             url.push_str(shortty);
                             url.push_str(".");
-                            url.push_str(*fqp.last());
+                            url.push_str(*fqp.last().unwrap());
                             url.push_str(".html");
                         }
                     }
@@ -457,7 +457,7 @@ impl fmt::Default for clean::ViewPath {
     fn fmt(v: &clean::ViewPath, f: &mut fmt::Formatter) {
         match *v {
             clean::SimpleImport(ref name, ref src) => {
-                if *name == src.path.segments.last().name {
+                if *name == src.path.segments.last().unwrap().name {
                     write!(f.buf, "use {};", *src);
                 } else {
                     write!(f.buf, "use {} = {};", *name, *src);
index 64328cdd7c3c6313b554165ac49684ceda09296b..fee97232fa000ee664dfae9f31fbde1bc89c8f3e 100644 (file)
@@ -275,7 +275,7 @@ pub fn run(mut crate: clean::Crate, dst: Path) {
         for (i, (&id, &(ref fqp, short))) in cache.paths.iter().enumerate() {
             if i > 0 { write!(w, ","); }
             write!(w, "'{}':\\{type:'{}',name:'{}'\\}",
-                   id, short, *fqp.last());
+                   id, short, *fqp.last().unwrap());
         }
         write!(w, "\\};");
         w.flush();
@@ -522,7 +522,7 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
                     clean::TyMethodItem(..) |
                     clean::StructFieldItem(..) |
                     clean::VariantItem(..) => {
-                        Some((Some(*self.parent_stack.last()),
+                        Some((Some(*self.parent_stack.last().unwrap()),
                               self.stack.slice_to(self.stack.len() - 1)))
 
                     }
@@ -530,7 +530,7 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
                         if self.parent_stack.len() == 0 {
                             None
                         } else {
-                            let last = self.parent_stack.last();
+                            let last = self.parent_stack.last().unwrap();
                             let amt = match self.paths.find(last) {
                                 Some(&(_, "trait")) => self.stack.len() - 1,
                                 Some(..) | None => self.stack.len(),
index 983d2def7b564c2806b0e9d20ad70067850836ed..b3d0e9cb10ab8daf9a2c2c19b6eef8b441b73ae6 100644 (file)
@@ -952,10 +952,8 @@ pub trait ImmutableVector<'a, T> {
     fn init(&self) -> &'a [T];
     /// Returns all but the last `n' elements of a vector
     fn initn(&self, n: uint) -> &'a [T];
-    /// Returns the last element of a vector, failing if the vector is empty.
-    fn last(&self) -> &'a T;
     /// Returns the last element of a vector, or `None` if it is empty.
-    fn last_opt(&self) -> Option<&'a T>;
+    fn last(&self) -> Option<&'a T>;
     /**
      * Apply a function to each element of a vector and return a concatenation
      * of each result vector
@@ -1142,13 +1140,7 @@ fn initn(&self, n: uint) -> &'a [T] {
     }
 
     #[inline]
-    fn last(&self) -> &'a T {
-        if self.len() == 0 { fail!("last: empty vector") }
-        &self[self.len() - 1]
-    }
-
-    #[inline]
-    fn last_opt(&self) -> Option<&'a T> {
+    fn last(&self) -> Option<&'a T> {
             if self.len() == 0 { None } else { Some(&self[self.len() - 1]) }
     }
 
@@ -3116,27 +3108,12 @@ fn test_initn_empty() {
 
     #[test]
     fn test_last() {
-        let mut a = ~[11];
-        assert_eq!(a.last(), &11);
-        a = ~[11, 12];
-        assert_eq!(a.last(), &12);
-    }
-
-    #[test]
-    #[should_fail]
-    fn test_last_empty() {
-        let a: ~[int] = ~[];
-        a.last();
-    }
-
-    #[test]
-    fn test_last_opt() {
         let mut a = ~[];
-        assert_eq!(a.last_opt(), None);
+        assert_eq!(a.last(), None);
         a = ~[11];
-        assert_eq!(a.last_opt().unwrap(), &11);
+        assert_eq!(a.last().unwrap(), &11);
         a = ~[11, 12];
-        assert_eq!(a.last_opt().unwrap(), &12);
+        assert_eq!(a.last().unwrap(), &12);
     }
 
     #[test]
index 27f4c34d3cdc3e360c7b419a45192d410c449d84..72ab81d8657584140c237907838bed2d75a86307 100644 (file)
@@ -106,7 +106,7 @@ fn pretty_ty(ty: &Ty, itr: @IdentInterner, out: &mut ~str) {
         // need custom handling.
         TyNil => { out.push_str("$NIL$"); return }
         TyPath(ref path, _, _) => {
-            out.push_str(itr.get(path.segments.last().identifier.name));
+            out.push_str(itr.get(path.segments.last().unwrap().identifier.name));
             return
         }
         TyTup(ref tys) => {
@@ -139,7 +139,7 @@ pub fn impl_pretty_name(trait_ref: &Option<TraitRef>, ty: &Ty) -> PathElem {
     match *trait_ref {
         None => pretty = ~"",
         Some(ref trait_ref) => {
-            pretty = itr.get(trait_ref.path.segments.last().identifier.name).to_owned();
+            pretty = itr.get(trait_ref.path.segments.last().unwrap().identifier.name).to_owned();
             pretty.push_char('$');
         }
     };
index 04a89a03852d0ea921deb354a355491b0164377a..6472551b049fc547b0e02f8972937cc72a76aa7c 100644 (file)
@@ -31,7 +31,7 @@ pub fn path_name_i(idents: &[Ident]) -> ~str {
 // totally scary function: ignores all but the last element, should have
 // a different name
 pub fn path_to_ident(path: &Path) -> Ident {
-    path.segments.last().identifier
+    path.segments.last().unwrap().identifier
 }
 
 pub fn local_def(id: NodeId) -> DefId {
@@ -913,7 +913,7 @@ pub fn xorPush(marks: &mut ~[Mrk], mark: Mrk) {
 // get the last element of a mutable array.
 // FIXME #4903: , must be a separate procedure for now.
 pub fn getLast(arr: &~[Mrk]) -> Mrk {
-    *arr.last()
+    *arr.last().unwrap()
 }
 
 // are two paths equal when compared unhygienically?
index 15146551370b20a92e7c1c9929bf45046ce85b0b..ebf02f7691e40dc6db437b96ed1cd5ed12663d54 100644 (file)
@@ -269,12 +269,9 @@ pub fn new() -> CodeMap {
 
     pub fn new_filemap(&self, filename: FileName, src: @str) -> @FileMap {
         let mut files = self.files.borrow_mut();
-        let start_pos = if files.get().len() == 0 {
-            0
-        } else {
-            let last_start = files.get().last().start_pos.to_uint();
-            let last_len = files.get().last().src.len();
-            last_start + last_len
+        let start_pos = match files.get().last() {
+            None => 0,
+            Some(last) => last.start_pos.to_uint() + last.src.len(),
         };
 
         let filemap = @FileMap {
index 202746acddce1a01b604ed2a03835f1a2e1b3502..cddfa7d2aa050fb28f3ad046f82f93e7001defca 100644 (file)
@@ -920,7 +920,7 @@ enum StructType {
 // general helper methods.
 impl<'a> TraitDef<'a> {
     fn set_expn_info(&self, mut to_set: Span) -> Span {
-        let trait_name = match self.path.path.last_opt() {
+        let trait_name = match self.path.path.last() {
             None => self.cx.span_bug(self.span, "trait with empty path in generic `deriving`"),
             Some(name) => *name
         };
index 2b90f4221a87f677a3a274424a204956e8f7786b..4c78244bf08435c308c2c2fb17a8c4f9bcafca55 100644 (file)
@@ -190,7 +190,8 @@ pub fn tt_next_token(r: &TtReader) -> TokenAndSpan {
         if !r.stack.get().dotdotdoted || {
                 let repeat_idx = r.repeat_idx.borrow();
                 let repeat_len = r.repeat_len.borrow();
-                *repeat_idx.get().last() == *repeat_len.get().last() - 1
+                *repeat_idx.get().last().unwrap() ==
+                *repeat_len.get().last().unwrap() - 1
             } {
 
             match r.stack.get().up {
index 3cca81180168b555eafae1a01eb64d1eaf90d54a..d6f363eb6a074a06a8a9bc54bdb8151b88d27c00 100644 (file)
@@ -55,10 +55,10 @@ pub fn pop(&mut self) -> T {
         }
     }
 
-    pub fn last<'a>(&'a self) -> &'a T {
+    pub fn last<'a>(&'a self) -> Option<&'a T> {
         match *self {
             Vec(ref v) => v.last(),
-            Empty => fail!("last on empty opt_vec")
+            Empty => None
         }
     }
 
index 3a5e737e026ed59c0ac3a8269695eeeb6fbbe850..30408fa1c2b53790b9e05214431537ebf7e018ea 100644 (file)
@@ -1753,19 +1753,19 @@ pub fn parse_bottom_expr(&mut self) -> @Expr {
                 return self.mk_expr(lo, hi, ExprLit(lit));
             }
             let mut es = ~[self.parse_expr()];
-            self.commit_expr(*es.last(), &[], &[token::COMMA, token::RPAREN]);
+            self.commit_expr(*es.last().unwrap(), &[], &[token::COMMA, token::RPAREN]);
             while self.token == token::COMMA {
                 self.bump();
                 if self.token != token::RPAREN {
                     es.push(self.parse_expr());
-                    self.commit_expr(*es.last(), &[], &[token::COMMA, token::RPAREN]);
+                    self.commit_expr(*es.last().unwrap(), &[], &[token::COMMA, token::RPAREN]);
                 }
                 else {
                     trailing_comma = true;
                 }
             }
             hi = self.span.hi;
-            self.commit_expr_expecting(*es.last(), token::RPAREN);
+            self.commit_expr_expecting(*es.last().unwrap(), token::RPAREN);
 
             return if es.len() == 1 && !trailing_comma {
                 self.mk_expr(lo, self.span.hi, ExprParen(es[0]))
@@ -1924,7 +1924,8 @@ pub fn parse_bottom_expr(&mut self) -> @Expr {
 
                     fields.push(self.parse_field());
                     while self.token != token::RBRACE {
-                        self.commit_expr(fields.last().expr, &[token::COMMA], &[token::RBRACE]);
+                        self.commit_expr(fields.last().unwrap().expr,
+                                         &[token::COMMA], &[token::RBRACE]);
 
                         if self.eat(&token::DOTDOT) {
                             base = Some(self.parse_expr());
@@ -1939,7 +1940,7 @@ pub fn parse_bottom_expr(&mut self) -> @Expr {
                     }
 
                     hi = pth.span.hi;
-                    self.commit_expr_expecting(fields.last().expr, token::RBRACE);
+                    self.commit_expr_expecting(fields.last().unwrap().expr, token::RBRACE);
                     ex = ExprStruct(pth, fields, base);
                     return self.mk_expr(lo, hi, ex);
                 }
@@ -2092,7 +2093,7 @@ fn parse_non_delim_tt_tok(p: &mut Parser) -> TokenTree {
                   // This is a conservative error: only report the last unclosed delimiter. The
                   // previous unclosed delimiters could actually be closed! The parser just hasn't
                   // gotten to them yet.
-                  match p.open_braces.last_opt() {
+                  match p.open_braces.last() {
                       None => {}
                       Some(&sp) => p.span_note(sp, "unclosed delimiter"),
                   };
index 82aa178e62b240f2620b684909e02f77fa805aeb..3ea48969069ce300d05b9345099c34bfdd962f4f 100644 (file)
@@ -1947,7 +1947,7 @@ pub fn print_view_path(s: &mut State, vp: &ast::ViewPath) {
     match vp.node {
       ast::ViewPathSimple(ident, ref path, _) => {
         // FIXME(#6993) can't compare identifiers directly here
-        if path.segments.last().identifier.name != ident.name {
+        if path.segments.last().unwrap().identifier.name != ident.name {
             print_ident(s, ident);
             space(&mut s.s);
             word_space(s, "=");
index f0dd20f44958994185fc9824f14cc58bce9b827a..db46c3db439a7ef0508138d9a171df205b534d09 100644 (file)
@@ -91,7 +91,7 @@ fn recurse_or_fail(depth: int, st: Option<State>) {
                 unique: ~Cons((), @*st.unique),
                 tuple: (@Cons((), st.tuple.first()),
                         ~Cons((), @*st.tuple.second())),
-                vec: st.vec + &[@Cons((), *st.vec.last())],
+                vec: st.vec + &[@Cons((), *st.vec.last().unwrap())],
                 res: r(@Cons((), st.res._l))
             }
           }