Skip to content

Commit 7d57b48

Browse files
committed
Remove deprecated modes from list.rs (and temporarily delete list::push)
1 parent 34bf846 commit 7d57b48

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

src/libstd/list.rs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//! A standard linked list
2+
#[forbid(deprecated_mode)];
3+
#[forbid(deprecated_pattern)];
24

35
import core::cmp::Eq;
46
import core::option;
@@ -28,9 +30,9 @@ fn from_vec<T: copy>(v: &[T]) -> @list<T> {
2830
* * z - The initial value
2931
* * f - The function to apply
3032
*/
31-
fn foldl<T: copy, U>(z: T, ls: @list<U>, f: fn(T, U) -> T) -> T {
33+
fn foldl<T: copy, U>(+z: T, ls: @list<U>, f: fn((&T), (&U)) -> T) -> T {
3234
let mut accum: T = z;
33-
do iter(ls) |elt| { accum = f(accum, elt);}
35+
do iter(ls) |elt| { accum = f(&accum, &elt);}
3436
accum
3537
}
3638

@@ -41,12 +43,12 @@ fn foldl<T: copy, U>(z: T, ls: @list<U>, f: fn(T, U) -> T) -> T {
4143
* When function `f` returns true then an option containing the element
4244
* is returned. If `f` matches no elements then none is returned.
4345
*/
44-
fn find<T: copy>(ls: @list<T>, f: fn(T) -> bool) -> Option<T> {
46+
fn find<T: copy>(ls: @list<T>, f: fn((&T)) -> bool) -> Option<T> {
4547
let mut ls = ls;
4648
loop {
4749
ls = match *ls {
4850
cons(hd, tl) => {
49-
if f(hd) { return Some(hd); }
51+
if f(&hd) { return Some(hd); }
5052
tl
5153
}
5254
nil => return None
@@ -55,7 +57,7 @@ fn find<T: copy>(ls: @list<T>, f: fn(T) -> bool) -> Option<T> {
5557
}
5658

5759
/// Returns true if a list contains an element with the given value
58-
fn has<T: copy Eq>(ls: @list<T>, elt: T) -> bool {
60+
fn has<T: copy Eq>(ls: @list<T>, +elt: T) -> bool {
5961
for each(ls) |e| {
6062
if e == elt { return true; }
6163
}
@@ -110,10 +112,13 @@ pure fn append<T: copy>(l: @list<T>, m: @list<T>) -> @list<T> {
110112
}
111113
}
112114

113-
/// Push an element to the front of a list
114-
fn push<T: copy>(&l: list<T>, v: T) {
115-
l = cons(v, @l);
115+
/*
116+
/// Push one element into the front of a list, returning a new list
117+
/// THIS VERSION DOESN'T ACTUALLY WORK
118+
pure fn push<T: copy>(ll: &mut @list<T>, +vv: T) {
119+
ll = &mut @cons(vv, *ll)
116120
}
121+
*/
117122

118123
/// Iterate over a list
119124
fn iter<T>(l: @list<T>, f: fn(T)) {
@@ -201,7 +206,7 @@ mod tests {
201206

202207
#[test]
203208
fn test_foldl() {
204-
fn add(&&a: uint, &&b: int) -> uint { return a + (b as uint); }
209+
fn add(a: &uint, b: &int) -> uint { return *a + (*b as uint); }
205210
let l = from_vec(~[0, 1, 2, 3, 4]);
206211
let empty = @list::nil::<int>;
207212
assert (list::foldl(0u, l, add) == 10u);
@@ -210,23 +215,23 @@ mod tests {
210215

211216
#[test]
212217
fn test_foldl2() {
213-
fn sub(&&a: int, &&b: int) -> int {
214-
a - b
218+
fn sub(a: &int, b: &int) -> int {
219+
*a - *b
215220
}
216221
let l = from_vec(~[1, 2, 3, 4]);
217222
assert (list::foldl(0, l, sub) == -10);
218223
}
219224

220225
#[test]
221226
fn test_find_success() {
222-
fn match_(&&i: int) -> bool { return i == 2; }
227+
fn match_(i: &int) -> bool { return *i == 2; }
223228
let l = from_vec(~[0, 1, 2]);
224229
assert (list::find(l, match_) == option::Some(2));
225230
}
226231

227232
#[test]
228233
fn test_find_fail() {
229-
fn match_(&&_i: int) -> bool { return false; }
234+
fn match_(_i: &int) -> bool { return false; }
230235
let l = from_vec(~[0, 1, 2]);
231236
let empty = @list::nil::<int>;
232237
assert (list::find(l, match_) == option::None::<int>);
@@ -251,6 +256,11 @@ mod tests {
251256
assert (list::len(empty) == 0u);
252257
}
253258

259+
#[test]
260+
fn test_append() {
261+
assert from_vec(~[1,2,3,4])
262+
== list::append(list::from_vec(~[1,2]), list::from_vec(~[3,4]));
263+
}
254264
}
255265

256266
// Local Variables:

src/libstd/prettyprint.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[forbid(deprecated_mode)];
2+
#[forbid(deprecated_pattern)];
3+
14
import io::Writer;
25
import io::WriterUtil;
36
import serialization::serializer;

src/rustc/middle/trans/type_use.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fn type_needs_inner(cx: ctx, use: uint, ty: ty::t,
140140
ty::ty_fn(_) | ty::ty_ptr(_) | ty::ty_rptr(_, _)
141141
| ty::ty_trait(_, _, _) => false,
142142
ty::ty_enum(did, substs) => {
143-
if option::is_none(list::find(enums_seen, |id| id == did)) {
143+
if option::is_none(list::find(enums_seen, |id| *id == did)) {
144144
let seen = @cons(did, enums_seen);
145145
for vec::each(*ty::enum_variants(cx.ccx.tcx, did)) |v| {
146146
for vec::each(v.args) |aty| {

0 commit comments

Comments
 (0)