about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorKevin Cantu <me@kevincantu.org>2012-08-29 16:28:04 -0700
committerKevin Cantu <me@kevincantu.org>2012-08-31 12:55:39 -0700
commit7d57b4864a90776d46898f97a3f4b9b6519cf38d (patch)
treed707e92cf4563ca8eb080dc14b3b05636c2d0603 /src/libstd
parent34bf84649e811e93cad521bba5116117b86bd57b (diff)
Remove deprecated modes from list.rs (and temporarily delete list::push)
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/list.rs36
-rw-r--r--src/libstd/prettyprint.rs3
2 files changed, 26 insertions, 13 deletions
diff --git a/src/libstd/list.rs b/src/libstd/list.rs
index 651eb1ab077..e1ff5c8b352 100644
--- a/src/libstd/list.rs
+++ b/src/libstd/list.rs
@@ -1,4 +1,6 @@
 //! A standard linked list
+#[forbid(deprecated_mode)];
+#[forbid(deprecated_pattern)];
 
 import core::cmp::Eq;
 import core::option;
@@ -28,9 +30,9 @@ fn from_vec<T: copy>(v: &[T]) -> @list<T> {
  * * z - The initial value
  * * f - The function to apply
  */
-fn foldl<T: copy, U>(z: T, ls: @list<U>, f: fn(T, U) -> T) -> T {
+fn foldl<T: copy, U>(+z: T, ls: @list<U>, f: fn((&T), (&U)) -> T) -> T {
     let mut accum: T = z;
-    do iter(ls) |elt| { accum = f(accum, elt);}
+    do iter(ls) |elt| { accum = f(&accum, &elt);}
     accum
 }
 
@@ -41,12 +43,12 @@ fn foldl<T: copy, U>(z: T, ls: @list<U>, f: fn(T, U) -> T) -> T {
  * When function `f` returns true then an option containing the element
  * is returned. If `f` matches no elements then none is returned.
  */
-fn find<T: copy>(ls: @list<T>, f: fn(T) -> bool) -> Option<T> {
+fn find<T: copy>(ls: @list<T>, f: fn((&T)) -> bool) -> Option<T> {
     let mut ls = ls;
     loop {
         ls = match *ls {
           cons(hd, tl) => {
-            if f(hd) { return Some(hd); }
+            if f(&hd) { return Some(hd); }
             tl
           }
           nil => return None
@@ -55,7 +57,7 @@ fn find<T: copy>(ls: @list<T>, f: fn(T) -> bool) -> Option<T> {
 }
 
 /// Returns true if a list contains an element with the given value
-fn has<T: copy Eq>(ls: @list<T>, elt: T) -> bool {
+fn has<T: copy Eq>(ls: @list<T>, +elt: T) -> bool {
     for each(ls) |e| {
         if e == elt { return true; }
     }
@@ -110,10 +112,13 @@ pure fn append<T: copy>(l: @list<T>, m: @list<T>) -> @list<T> {
     }
 }
 
-/// Push an element to the front of a list
-fn push<T: copy>(&l: list<T>, v: T) {
-    l = cons(v, @l);
+/*
+/// Push one element into the front of a list, returning a new list
+/// THIS VERSION DOESN'T ACTUALLY WORK
+pure fn push<T: copy>(ll: &mut @list<T>, +vv: T) {
+    ll = &mut @cons(vv, *ll)
 }
+*/
 
 /// Iterate over a list
 fn iter<T>(l: @list<T>, f: fn(T)) {
@@ -201,7 +206,7 @@ mod tests {
 
     #[test]
     fn test_foldl() {
-        fn add(&&a: uint, &&b: int) -> uint { return a + (b as uint); }
+        fn add(a: &uint, b: &int) -> uint { return *a + (*b as uint); }
         let l = from_vec(~[0, 1, 2, 3, 4]);
         let empty = @list::nil::<int>;
         assert (list::foldl(0u, l, add) == 10u);
@@ -210,8 +215,8 @@ mod tests {
 
     #[test]
     fn test_foldl2() {
-        fn sub(&&a: int, &&b: int) -> int {
-            a - b
+        fn sub(a: &int, b: &int) -> int {
+            *a - *b
         }
         let l = from_vec(~[1, 2, 3, 4]);
         assert (list::foldl(0, l, sub) == -10);
@@ -219,14 +224,14 @@ mod tests {
 
     #[test]
     fn test_find_success() {
-        fn match_(&&i: int) -> bool { return i == 2; }
+        fn match_(i: &int) -> bool { return *i == 2; }
         let l = from_vec(~[0, 1, 2]);
         assert (list::find(l, match_) == option::Some(2));
     }
 
     #[test]
     fn test_find_fail() {
-        fn match_(&&_i: int) -> bool { return false; }
+        fn match_(_i: &int) -> bool { return false; }
         let l = from_vec(~[0, 1, 2]);
         let empty = @list::nil::<int>;
         assert (list::find(l, match_) == option::None::<int>);
@@ -251,6 +256,11 @@ mod tests {
         assert (list::len(empty) == 0u);
     }
 
+    #[test]
+    fn test_append() {
+        assert from_vec(~[1,2,3,4])
+            == list::append(list::from_vec(~[1,2]), list::from_vec(~[3,4]));
+    }
 }
 
 // Local Variables:
diff --git a/src/libstd/prettyprint.rs b/src/libstd/prettyprint.rs
index 259bb4eb612..d9e64d7b1a0 100644
--- a/src/libstd/prettyprint.rs
+++ b/src/libstd/prettyprint.rs
@@ -1,3 +1,6 @@
+#[forbid(deprecated_mode)];
+#[forbid(deprecated_pattern)];
+
 import io::Writer;
 import io::WriterUtil;
 import serialization::serializer;