]> git.lizzy.rs Git - rust.git/commitdiff
[std::vec] Rename .shift_opt() to .shift(), drop the old .shift() behavior
authorSimon Sapin <simon.sapin@exyr.org>
Mon, 23 Dec 2013 15:40:42 +0000 (16:40 +0100)
committerSimon Sapin <simon.sapin@exyr.org>
Tue, 21 Jan 2014 23:48:47 +0000 (15:48 -0800)
src/compiletest/runtest.rs
src/libextra/dlist.rs
src/librustc/lib.rs
src/librustc/middle/lint.rs
src/libstd/io/buffered.rs
src/libstd/io/fs.rs
src/libstd/str.rs
src/libstd/vec.rs
src/test/bench/core-std.rs

index 6f8a3ad83a3ebafa5484a32aa4b8f6b79b4d16dd..bbfba84cc9e6622d5e5e63b12eda8fd87a59b5c7 100644 (file)
@@ -788,7 +788,7 @@ fn make_run_args(config: &config, _props: &TestProps, testfile: &Path) ->
     let exe_file = make_exe_name(config, testfile);
     // FIXME (#9639): This needs to handle non-utf8 paths
     args.push(exe_file.as_str().unwrap().to_owned());
-    let prog = args.shift();
+    let prog = args.shift().unwrap();
     return ProcArgs {prog: prog, args: args};
 }
 
index 009cc53289e43831064de3030e13b02e10a2504d..115700e7408a3b7288100633e0c189080bf6b236 100644 (file)
@@ -1053,7 +1053,7 @@ fn fuzz_test(sz: int) {
                 }
                 1 => {
                     m.pop_front();
-                    if v.len() > 0 { v.shift(); }
+                    v.shift();
                 }
                 2 | 4 =>  {
                     m.push_front(-i);
index 26b20fb49dc74d271351955264f488c8751d6350..7ecf2b1e18c4202dcb62d22b080d5c90ee5f05cd 100644 (file)
@@ -190,7 +190,7 @@ pub fn describe_debug_flags() {
 
 pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) {
     let mut args = args.to_owned();
-    let binary = args.shift();
+    let binary = args.shift().unwrap();
 
     if args.is_empty() { usage(binary); return; }
 
index e780864ffd507749df76b096ae48fa894ba0f9da..7e6db24a4a319138a685e0eedbd3e39571378f6b 100644 (file)
@@ -524,7 +524,7 @@ fn with_lint_attrs(&mut self,
         // rollback
         self.is_doc_hidden = old_is_doc_hidden;
         pushed.times(|| {
-            let (lint, lvl, src) = self.lint_stack.pop();
+            let (lint, lvl, src) = self.lint_stack.pop().unwrap();
             self.set_level(lint, lvl, src);
         })
     }
index 928482b64dfa26a2cffee6f7c59db4cb2674fb5e..745273a1d74be3064559d44f578b0589a9ea86c7 100644 (file)
@@ -370,7 +370,7 @@ pub struct ShortReader {
 
     impl Reader for ShortReader {
         fn read(&mut self, _: &mut [u8]) -> Option<uint> {
-            self.lengths.shift_opt()
+            self.lengths.shift()
         }
     }
 
index aac565f2c45e970ef4baee77a68065d5a88ecc80..80dbaebe01c042a65da92f505f8e15dda237133d 100644 (file)
@@ -519,7 +519,7 @@ pub struct Directories {
 
 impl Iterator<Path> for Directories {
     fn next(&mut self) -> Option<Path> {
-        match self.stack.shift_opt() {
+        match self.stack.shift() {
             Some(path) => {
                 if path.is_dir() {
                     self.stack.push_all_move(readdir(&path));
index ff029565cf1a49d018fa536c4f46d0a6e2dba3da..f59cd855c32c940076b6126ab2f6c50002e553e6 100644 (file)
@@ -703,7 +703,7 @@ fn next(&mut self) -> Option<char> {
             self.sorted = true;
         }
 
-        match self.buffer.shift_opt() {
+        match self.buffer.shift() {
             Some((c, 0)) => {
                 self.sorted = false;
                 Some(c)
index 1dfd2ea560008cbed8258eee3db493d2f783e30e..6300abb55a1997484b1425c1b6ade776bf6d0317 100644 (file)
@@ -1383,10 +1383,8 @@ pub trait OwnedVector<T> {
     fn push_all_move(&mut self, rhs: ~[T]);
     /// Remove the last element from a vector and return it, or `None` if it is empty
     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
-    fn shift_opt(&mut self) -> Option<T>;
+    fn shift(&mut self) -> Option<T>;
     /// Prepend an element to the vector
     fn unshift(&mut self, x: T);
 
@@ -1578,14 +1576,11 @@ fn pop(&mut self) -> Option<T> {
 
 
     #[inline]
-    fn shift(&mut self) -> T {
-        self.shift_opt().expect("shift: empty vector")
-    }
-
-    fn shift_opt(&mut self) -> Option<T> {
+    fn shift(&mut self) -> Option<T> {
         self.remove_opt(0)
     }
 
+    #[inline]
     fn unshift(&mut self, x: T) {
         self.insert(0, x)
     }
@@ -1645,7 +1640,7 @@ fn swap_remove(&mut self, index: uint) -> T {
         if index < ln - 1 {
             self.swap(index, ln - 1);
         }
-        self.pop()
+        self.pop().unwrap()
     }
     fn truncate(&mut self, newlen: uint) {
         let oldlen = self.len();
@@ -3580,21 +3575,11 @@ fn test_connect() {
     #[test]
     fn test_shift() {
         let mut x = ~[1, 2, 3];
-        assert_eq!(x.shift(), 1);
-        assert_eq!(&x, &~[2, 3]);
-        assert_eq!(x.shift(), 2);
-        assert_eq!(x.shift(), 3);
-        assert_eq!(x.len(), 0);
-    }
-
-    #[test]
-    fn test_shift_opt() {
-        let mut x = ~[1, 2, 3];
-        assert_eq!(x.shift_opt(), Some(1));
+        assert_eq!(x.shift(), Some(1));
         assert_eq!(&x, &~[2, 3]);
-        assert_eq!(x.shift_opt(), Some(2));
-        assert_eq!(x.shift_opt(), Some(3));
-        assert_eq!(x.shift_opt(), None);
+        assert_eq!(x.shift(), Some(2));
+        assert_eq!(x.shift(), Some(3));
+        assert_eq!(x.shift(), None);
         assert_eq!(x.len(), 0);
     }
 
index 4d5c4ec24f305d1d63581e8950120c181588b18a..6ad2d8f8c8d66ec1831ca779ed9cd4fb3cd7a0d5 100644 (file)
@@ -65,7 +65,7 @@ fn shift_push() {
     let mut v2 = ~[];
 
     while v1.len() > 0 {
-        v2.push(v1.shift());
+        v2.push(v1.shift().unwrap());
     }
 }