about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2013-12-23 16:20:52 +0100
committerSimon Sapin <simon.sapin@exyr.org>2014-01-21 15:48:47 -0800
commitbada25e425ae30583ad343e36a034e59c66fcad6 (patch)
tree4e07ddbe72ef54075d401322c8283de064f02b4e /src/libstd
parentaa66b91767ce92c45192ca11718575529d631d21 (diff)
downloadrust-bada25e425ae30583ad343e36a034e59c66fcad6.tar.gz
rust-bada25e425ae30583ad343e36a034e59c66fcad6.zip
[std::vec] Rename .pop_opt() to .pop(), drop the old .pop() behavior
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/io/process.rs7
-rw-r--r--src/libstd/num/strconv.rs2
-rw-r--r--src/libstd/path/posix.rs2
-rw-r--r--src/libstd/path/windows.rs2
-rw-r--r--src/libstd/repr.rs6
-rw-r--r--src/libstd/vec.rs31
6 files changed, 17 insertions, 33 deletions
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<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 {
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<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) {
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<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 => {
@@ -1580,11 +1578,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);
     }