auto merge of #7487 : huonw/rust/vec-kill, r=cmr

Continuation of #7430.

I haven't removed the `map` method, since the replacement `v.iter().transform(f).collect::<~[SomeType]>()` is a little ridiculous at the moment.
This commit is contained in:
bors 2013-06-30 21:14:13 -07:00
commit 07feeb95c5
68 changed files with 518 additions and 899 deletions

View File

@ -345,9 +345,9 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
fatal(~"process did not return an error status");
}
let prefixes = vec::map(expected_errors, |ee| {
let prefixes = expected_errors.iter().transform(|ee| {
fmt!("%s:%u:", testfile.to_str(), ee.line)
});
}).collect::<~[~str]>();
// Scan and extract our error/warning messages,
// which look like:

View File

@ -122,14 +122,14 @@ def ch_prefix(ix):
def emit_bsearch_range_table(f):
f.write("""
pure fn bsearch_range_table(c: char, r: &[(char,char)]) -> bool {
use cmp::{EQ, LT, GT};
use vec::bsearch;
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
use cmp::{Equal, Less, Greater};
use vec::ImmutableVector;
use option::None;
(do bsearch(r) |&(lo,hi)| {
if lo <= c && c <= hi { EQ }
else if hi < c { LT }
else { GT }
(do r.bsearch |&(lo,hi)| {
if lo <= c && c <= hi { Equal }
else if hi < c { Less }
else { Greater }
}) != None
}\n\n
""");
@ -140,7 +140,7 @@ def emit_property_module(f, mod, tbl):
keys.sort()
emit_bsearch_range_table(f);
for cat in keys:
f.write(" const %s_table : &[(char,char)] = &[\n" % cat)
f.write(" static %s_table : &'static [(char,char)] = &[\n" % cat)
ix = 0
for pair in tbl[cat]:
f.write(ch_prefix(ix))
@ -148,7 +148,7 @@ def emit_property_module(f, mod, tbl):
ix += 1
f.write("\n ];\n\n")
f.write(" pub pure fn %s(c: char) -> bool {\n" % cat)
f.write(" pub fn %s(c: char) -> bool {\n" % cat)
f.write(" bsearch_range_table(c, %s_table)\n" % cat)
f.write(" }\n\n")
f.write("}\n")
@ -159,7 +159,7 @@ def emit_property_module_old(f, mod, tbl):
keys = tbl.keys()
keys.sort()
for cat in keys:
f.write(" pure fn %s(c: char) -> bool {\n" % cat)
f.write(" fn %s(c: char) -> bool {\n" % cat)
f.write(" ret alt c {\n")
prefix = ' '
for pair in tbl[cat]:
@ -236,8 +236,22 @@ rf = open(r, "w")
(canon_decomp, compat_decomp, gencats) = load_unicode_data("UnicodeData.txt")
# Explain that the source code was generated by this script.
rf.write('// The following code was generated by "src/etc/unicode.py"\n\n')
# Preamble
rf.write('''// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// The following code was generated by "src/etc/unicode.py"
#[allow(missing_doc)];
''')
emit_property_module(rf, "general_category", gencats)

View File

@ -100,7 +100,6 @@ total line count).
use std::io::ReaderUtil;
use std::io;
use std::os;
use std::vec;
/**
A summary of the internal state of a `FileInput` object. `line_num`
@ -353,13 +352,13 @@ a literal `-`.
*/
// XXX: stupid, unclear name
pub fn pathify(vec: &[~str], stdin_hyphen : bool) -> ~[Option<Path>] {
vec::map(vec, |&str : & ~str| {
if stdin_hyphen && str == ~"-" {
vec.iter().transform(|str| {
if stdin_hyphen && "-" == *str {
None
} else {
Some(Path(str))
Some(Path(*str))
}
})
}).collect()
}
/**

View File

@ -592,9 +592,9 @@ pub mod groups {
*/
pub fn usage(brief: &str, opts: &[OptGroup]) -> ~str {
let desc_sep = ~"\n" + " ".repeat(24);
let desc_sep = "\n" + " ".repeat(24);
let rows = vec::map(opts, |optref| {
let mut rows = opts.iter().transform(|optref| {
let OptGroup{short_name: short_name,
long_name: long_name,
hint: hint,
@ -669,7 +669,7 @@ pub mod groups {
return str::to_owned(brief) +
"\n\nOptions:\n" +
rows.connect("\n") +
rows.collect::<~[~str]>().connect("\n") +
"\n\n";
}
} // end groups module

View File

@ -283,13 +283,13 @@ impl Mul<BigUint, BigUint> for BigUint {
if n == 1 { return copy *a; }
let mut carry = 0;
let prod = do vec::map(a.data) |ai| {
let prod = do a.data.iter().transform |ai| {
let (hi, lo) = BigDigit::from_uint(
(*ai as uint) * (n as uint) + (carry as uint)
);
carry = hi;
lo
};
}.collect::<~[BigDigit]>();
if carry == 0 { return BigUint::new(prod) };
return BigUint::new(prod + [carry]);
}
@ -618,13 +618,13 @@ impl BigUint {
if n_bits == 0 || self.is_zero() { return copy *self; }
let mut carry = 0;
let shifted = do vec::map(self.data) |elem| {
let shifted = do self.data.iter().transform |elem| {
let (hi, lo) = BigDigit::from_uint(
(*elem as uint) << n_bits | (carry as uint)
);
carry = hi;
lo
};
}.collect::<~[BigDigit]>();
if carry == 0 { return BigUint::new(shifted); }
return BigUint::new(shifted + [carry]);
}
@ -1172,7 +1172,7 @@ mod biguint_tests {
#[test]
fn test_cmp() {
let data = [ &[], &[1], &[2], &[-1], &[0, 1], &[2, 1], &[1, 1, 1] ]
let data: ~[BigUint] = [ &[], &[1], &[2], &[-1], &[0, 1], &[2, 1], &[1, 1, 1] ]
.map(|v| BigUint::from_slice(*v));
for data.iter().enumerate().advance |(i, ni)| {
for data.slice(i, data.len()).iter().enumerate().advance |(j0, nj)| {

View File

@ -92,7 +92,7 @@ pub fn map<A:Copy + Send,B:Copy + Send>(
vec::concat(map_slices(xs, || {
let f = fn_factory();
let result: ~fn(uint, &[A]) -> ~[B] =
|_, slice| vec::map(slice, |x| f(x));
|_, slice| slice.iter().transform(|x| f(x)).collect();
result
}))
}
@ -104,9 +104,9 @@ pub fn mapi<A:Copy + Send,B:Copy + Send>(
let slices = map_slices(xs, || {
let f = fn_factory();
let result: ~fn(uint, &[A]) -> ~[B] = |base, slice| {
vec::mapi(slice, |i, x| {
slice.iter().enumerate().transform(|(i, x)| {
f(i + base, x)
})
}).collect()
};
result
});

View File

@ -107,7 +107,7 @@ impl<T:Ord> PriorityQueue<T> {
let mut end = q.len();
while end > 1 {
end -= 1;
vec::swap(q.data, 0, end);
q.data.swap(0, end);
q.siftdown_range(0, end)
}
q.to_vec()

View File

@ -78,12 +78,12 @@ impl ToStr for Version {
let s = if self.pre.is_empty() {
s
} else {
s + "-" + self.pre.map(|i| i.to_str()).connect(".")
fmt!("%s-%s", s, self.pre.map(|i| i.to_str()).connect("."))
};
if self.build.is_empty() {
s
} else {
s + "+" + self.build.map(|i| i.to_str()).connect(".")
fmt!("%s+%s", s, self.build.map(|i| i.to_str()).connect("."))
}
}
}

View File

@ -20,7 +20,6 @@ use std::cmp;
use std::container::{Container, Mutable, Map, Set};
use std::uint;
use std::util::replace;
use std::vec;
#[allow(missing_doc)]
pub struct SmallIntMap<T> {
@ -86,7 +85,7 @@ impl<V> Map<uint, V> for SmallIntMap<V> {
let exists = self.contains_key(&key);
let len = self.v.len();
if len <= key {
vec::grow_fn(&mut self.v, key - len + 1, |_| None);
self.v.grow_fn(key - len + 1, |_| None);
}
self.v[key] = Some(value);
!exists
@ -383,8 +382,6 @@ mod test_set {
use super::SmallIntSet;
use std::vec;
#[test]
fn test_disjoint() {
let mut xs = SmallIntSet::new();
@ -456,7 +453,7 @@ mod test_set {
let mut i = 0;
let expected = [3, 5, 11, 77];
for a.intersection(&b) |x| {
assert!(vec::contains(expected, x));
assert!(expected.contains(x));
i += 1
}
assert_eq!(i, expected.len());
@ -479,7 +476,7 @@ mod test_set {
let mut i = 0;
let expected = [1, 5, 11];
for a.difference(&b) |x| {
assert!(vec::contains(expected, x));
assert!(expected.contains(x));
i += 1
}
assert_eq!(i, expected.len());
@ -504,7 +501,7 @@ mod test_set {
let mut i = 0;
let expected = [1, 5, 11, 14, 22];
for a.symmetric_difference(&b) |x| {
assert!(vec::contains(expected, x));
assert!(expected.contains(x));
i += 1
}
assert_eq!(i, expected.len());
@ -533,7 +530,7 @@ mod test_set {
let mut i = 0;
let expected = [1, 3, 5, 9, 11, 13, 16, 19, 24];
for a.union(&b) |x| {
assert!(vec::contains(expected, x));
assert!(expected.contains(x));
i += 1
}
assert_eq!(i, expected.len());

View File

@ -65,17 +65,17 @@ pub fn merge_sort<T:Copy>(v: &[T], le: Le<T>) -> ~[T] {
fn part<T>(arr: &mut [T], left: uint,
right: uint, pivot: uint, compare_func: Le<T>) -> uint {
vec::swap(arr, pivot, right);
arr.swap(pivot, right);
let mut storage_index: uint = left;
let mut i: uint = left;
while i < right {
if compare_func(&arr[i], &arr[right]) {
vec::swap(arr, i, storage_index);
arr.swap(i, storage_index);
storage_index += 1;
}
i += 1;
}
vec::swap(arr, storage_index, right);
arr.swap(storage_index, right);
return storage_index;
}
@ -120,29 +120,29 @@ fn qsort3<T:Copy + Ord + Eq>(arr: &mut [T], left: int, right: int) {
j -= 1;
}
if i >= j { break; }
vec::swap(arr, i as uint, j as uint);
arr.swap(i as uint, j as uint);
if arr[i] == v {
p += 1;
vec::swap(arr, p as uint, i as uint);
arr.swap(p as uint, i as uint);
}
if v == arr[j] {
q -= 1;
vec::swap(arr, j as uint, q as uint);
arr.swap(j as uint, q as uint);
}
}
vec::swap(arr, i as uint, right as uint);
arr.swap(i as uint, right as uint);
j = i - 1;
i += 1;
let mut k: int = left;
while k < p {
vec::swap(arr, k as uint, j as uint);
arr.swap(k as uint, j as uint);
k += 1;
j -= 1;
if k == arr.len() as int { break; }
}
k = right - 1;
while k > q {
vec::swap(arr, i as uint, k as uint);
arr.swap(i as uint, k as uint);
k -= 1;
i += 1;
if k == 0 { break; }
@ -259,7 +259,7 @@ fn binarysort<T:Copy + Ord>(array: &mut [T], start: uint) {
fn reverse_slice<T>(v: &mut [T], start: uint, end:uint) {
let mut i = start;
while i < end / 2 {
vec::swap(v, i, end - i - 1);
v.swap(i, end - i - 1);
i += 1;
}
}
@ -479,7 +479,7 @@ impl<T:Copy + Ord> MergeState<T> {
let mut len1 = len1;
let mut len2 = len2;
vec::swap(array, dest, c2);
array.swap(dest, c2);
dest += 1; c2 += 1; len2 -= 1;
if len2 == 0 {
@ -501,7 +501,7 @@ impl<T:Copy + Ord> MergeState<T> {
loop {
assert!(len1 > 1 && len2 != 0);
if array[c2] < tmp[c1] {
vec::swap(array, dest, c2);
array.swap(dest, c2);
dest += 1; c2 += 1; len2 -= 1;
count2 += 1; count1 = 0;
if len2 == 0 {
@ -534,7 +534,7 @@ impl<T:Copy + Ord> MergeState<T> {
dest += count1; c1 += count1; len1 -= count1;
if len1 <= 1 { break_outer = true; break; }
}
vec::swap(array, dest, c2);
array.swap(dest, c2);
dest += 1; c2 += 1; len2 -= 1;
if len2 == 0 { break_outer = true; break; }
@ -589,7 +589,7 @@ impl<T:Copy + Ord> MergeState<T> {
let mut len1 = len1;
let mut len2 = len2;
vec::swap(array, dest, c1);
array.swap(dest, c1);
dest -= 1; c1 -= 1; len1 -= 1;
if len1 == 0 {
@ -613,7 +613,7 @@ impl<T:Copy + Ord> MergeState<T> {
loop {
assert!(len1 != 0 && len2 > 1);
if tmp[c2] < array[c1] {
vec::swap(array, dest, c1);
array.swap(dest, c1);
dest -= 1; c1 -= 1; len1 -= 1;
count1 += 1; count2 = 0;
if len1 == 0 {
@ -666,7 +666,7 @@ impl<T:Copy + Ord> MergeState<T> {
copy_vec(array, dest+1, tmp.slice(c2+1, c2+1+count2));
if len2 <= 1 { break_outer = true; break; }
}
vec::swap(array, dest, c1);
array.swap(dest, c1);
dest -= 1; c1 -= 1; len1 -= 1;
if len1 == 0 { break_outer = true; break; }
min_gallop -= 1;
@ -1049,7 +1049,7 @@ mod big_tests {
fn makeRange(n: uint) -> ~[uint] {
let one = do vec::from_fn(n) |i| { i };
let mut two = copy one;
vec::reverse(two);
two.reverse();
vec::append(two, one)
}
@ -1073,7 +1073,7 @@ mod big_tests {
tim_sort(arr); // *sort
isSorted(arr);
vec::reverse(arr);
arr.reverse();
tim_sort(arr); // \sort
isSorted(arr);
@ -1083,7 +1083,7 @@ mod big_tests {
for 3.times {
let i1 = rng.gen_uint_range(0, n);
let i2 = rng.gen_uint_range(0, n);
vec::swap(arr, i1, i2);
arr.swap(i1, i2);
}
tim_sort(arr); // 3sort
isSorted(arr);
@ -1145,7 +1145,7 @@ mod big_tests {
tim_sort(arr); // *sort
isSorted(arr);
vec::reverse(arr);
arr.reverse();
tim_sort(arr); // \sort
isSorted(arr);
@ -1155,7 +1155,7 @@ mod big_tests {
for 3.times {
let i1 = rng.gen_uint_range(0, n);
let i2 = rng.gen_uint_range(0, n);
vec::swap(arr, i1, i2);
arr.swap(i1, i2);
}
tim_sort(arr); // 3sort
isSorted(arr);

View File

@ -291,12 +291,13 @@ pub fn parse(file: @Reader, longnames: bool) -> Result<~TermInfo, ~str> {
// Find the offset of the NUL we want to go to
let nulpos = vec::position_between(string_table, offset as uint,
string_table_bytes as uint, |&b| b == 0);
let nulpos = string_table.slice(offset as uint, string_table_bytes as uint)
.iter().position_(|&b| b == 0);
match nulpos {
Some(x) => {
Some(len) => {
string_map.insert(name.to_owned(),
string_table.slice(offset as uint, x).to_owned())
string_table.slice(offset as uint,
offset as uint + len).to_owned())
},
None => {
return Err(~"invalid file: missing NUL in string_table");

View File

@ -449,7 +449,7 @@ fn run_tests(opts: &TestOpts,
debug!("using %u test tasks", concurrency);
let mut remaining = filtered_tests;
vec::reverse(remaining);
remaining.reverse();
let mut pending = 0;
let (p, ch) = stream();

View File

@ -52,7 +52,7 @@ fn get_sysroot_absolute_rt_lib(sess: session::Session) -> Path {
}
pub fn rpaths_to_flags(rpaths: &[Path]) -> ~[~str] {
vec::map(rpaths, |rpath| fmt!("-Wl,-rpath,%s",rpath.to_str()))
rpaths.iter().transform(|rpath| fmt!("-Wl,-rpath,%s",rpath.to_str())).collect()
}
fn get_rpaths(os: session::os,
@ -103,9 +103,7 @@ fn get_rpaths(os: session::os,
fn get_rpaths_relative_to_output(os: session::os,
output: &Path,
libs: &[Path]) -> ~[Path] {
vec::map(libs, |a| {
get_rpath_relative_to_output(os, output, a)
})
libs.iter().transform(|a| get_rpath_relative_to_output(os, output, a)).collect()
}
pub fn get_rpath_relative_to_output(os: session::os,
@ -163,7 +161,7 @@ pub fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {
}
fn get_absolute_rpaths(libs: &[Path]) -> ~[Path] {
vec::map(libs, |a| get_absolute_rpath(a) )
libs.iter().transform(|a| get_absolute_rpath(a)).collect()
}
pub fn get_absolute_rpath(lib: &Path) -> Path {

View File

@ -90,7 +90,7 @@ fn fold_foreign_mod(
ast::foreign_mod {
sort: nm.sort,
abis: nm.abis,
view_items: vec::map(filtered_view_items, |x| fld.fold_view_item(*x)),
view_items: filtered_view_items.iter().transform(|x| fld.fold_view_item(*x)).collect(),
items: filtered_items
}
}

View File

@ -117,7 +117,7 @@ fn fold_mod(cx: @mut TestCtxt,
let mod_nomain = ast::_mod {
view_items: /*bad*/copy m.view_items,
items: vec::map(m.items, |i| nomain(cx, *i)),
items: m.items.iter().transform(|i| nomain(cx, *i)).collect(),
};
fold::noop_fold_mod(&mod_nomain, fld)

View File

@ -17,7 +17,6 @@ use metadata::cstore;
use metadata::decoder;
use std::hashmap::HashMap;
use std::vec;
use extra;
use syntax::ast;
use syntax::parse::token::ident_interner;
@ -91,7 +90,7 @@ pub fn iter_crate_data(cstore: &CStore,
}
pub fn add_used_crate_file(cstore: &mut CStore, lib: &Path) {
if !vec::contains(cstore.used_crate_files, lib) {
if !cstore.used_crate_files.contains(lib) {
cstore.used_crate_files.push(copy *lib);
}
}

View File

@ -1441,8 +1441,7 @@ fn encode_crate_deps(ecx: &EncodeContext,
expected_cnum += 1;
}
// mut -> immutable hack for vec::map
deps.slice(0, deps.len()).to_owned()
deps
}
// We're just going to write a list of crate 'name-hash-version's, with

View File

@ -363,7 +363,7 @@ pub fn missing_ctor(cx: &MatchCheckCtxt,
for m.iter().advance |r| {
let r = pat_ctor_id(cx, r[0]);
for r.iter().advance |id| {
if !vec::contains(found, id) {
if !found.contains(id) {
found.push(/*bad*/copy *id);
}
}
@ -417,7 +417,7 @@ pub fn missing_ctor(cx: &MatchCheckCtxt,
}
}
);
vec::dedup(&mut sorted_vec_lens);
sorted_vec_lens.dedup();
let mut found_slice = false;
let mut next = 0;
@ -642,13 +642,13 @@ pub fn specialize(cx: &MatchCheckCtxt,
ty_to_str(cx.tcx, left_ty)));
}
}
let args = vec::map(class_fields, |class_field| {
let args = class_fields.iter().transform(|class_field| {
match flds.iter().find_(|f|
f.ident == class_field.ident) {
Some(f) => f.pat,
_ => wild()
}
});
}).collect();
Some(vec::append(args, vec::to_owned(r.tail())))
}
}

View File

@ -19,7 +19,6 @@ use syntax::ast::*;
use std::float;
use std::hashmap::{HashMap, HashSet};
use std::vec;
//
// This pass classifies expressions by their constant-ness.
@ -70,8 +69,8 @@ pub fn join(a: constness, b: constness) -> constness {
}
}
pub fn join_all(cs: &[constness]) -> constness {
cs.iter().fold(integral_const, |a, b| join(a, *b))
pub fn join_all<It: Iterator<constness>>(mut cs: It) -> constness {
cs.fold(integral_const, |a, b| join(a, b))
}
pub fn classify(e: &expr,
@ -104,7 +103,7 @@ pub fn classify(e: &expr,
ast::expr_tup(ref es) |
ast::expr_vec(ref es, ast::m_imm) => {
join_all(vec::map(*es, |e| classify(*e, tcx)))
join_all(es.iter().transform(|e| classify(*e, tcx)))
}
ast::expr_vstore(e, vstore) => {
@ -118,7 +117,7 @@ pub fn classify(e: &expr,
}
ast::expr_struct(_, ref fs, None) => {
let cs = do vec::map((*fs)) |f| {
let cs = do fs.iter().transform |f| {
classify(f.node.expr, tcx)
};
join_all(cs)

View File

@ -740,11 +740,10 @@ fn check_item_ctypes(cx: &Context, it: &ast::item) {
}
fn check_foreign_fn(cx: &Context, decl: &ast::fn_decl) {
let tys = vec::map(decl.inputs, |a| a.ty );
let r = vec::append_one(tys, decl.output);
for r.iter().advance |ty| {
check_ty(cx, *ty);
for decl.inputs.iter().advance |in| {
check_ty(cx, in.ty);
}
check_ty(cx, decl.output)
}
match it.node {

View File

@ -519,10 +519,10 @@ pub fn trans_const(ccx: &mut CrateContext, r: &Repr, discr: int,
C_struct(build_const_struct(ccx, nonnull, vals))
} else {
assert_eq!(vals.len(), 0);
let vals = do nonnull.fields.mapi |i, &ty| {
let vals = do nonnull.fields.iter().enumerate().transform |(i, &ty)| {
let llty = type_of::sizing_type_of(ccx, ty);
if i == ptrfield { C_null(llty) } else { C_undef(llty) }
};
}.collect::<~[ValueRef]>();
C_struct(build_const_struct(ccx, nonnull, vals))
}
}

View File

@ -1266,7 +1266,7 @@ pub fn cleanup_and_leave(bcx: block,
let mut skip = 0;
let mut dest = None;
{
let r = vec::rfind((*inf).cleanup_paths, |cp| cp.target == leave);
let r = (*inf).cleanup_paths.rev_iter().find_(|cp| cp.target == leave);
for r.iter().advance |cp| {
if cp.size == inf.cleanups.len() {
Br(bcx, cp.dest);

View File

@ -615,12 +615,12 @@ pub fn GEPi(cx: block, base: ValueRef, ixs: &[uint]) -> ValueRef {
// we care about.
if ixs.len() < 16 {
let mut small_vec = [ C_i32(0), ..16 ];
for ixs.iter().enumerate().advance |(i, &ix)| {
small_vec[i] = C_i32(ix as i32)
for small_vec.mut_iter().zip(ixs.iter()).advance |(small_vec_e, &ix)| {
*small_vec_e = C_i32(ix as i32);
}
InBoundsGEP(cx, base, small_vec.slice(0, ixs.len()))
} else {
let v = do vec::map(ixs) |i| { C_i32(*i as i32) };
let v = do ixs.iter().transform |i| { C_i32(*i as i32) }.collect::<~[ValueRef]>();
count_insn(cx, "gepi");
InBoundsGEP(cx, base, v)
}

View File

@ -17,7 +17,6 @@ use middle::trans::type_::Type;
use std::libc::c_uint;
use std::option;
use std::vec;
pub trait ABIInfo {
fn compute_info(&self, atys: &[Type], rty: Type, ret_def: bool) -> FnType;
@ -37,7 +36,7 @@ pub struct FnType {
impl FnType {
pub fn decl_fn(&self, decl: &fn(fnty: Type) -> ValueRef) -> ValueRef {
let atys = vec::map(self.arg_tys, |t| t.ty);
let atys = self.arg_tys.iter().transform(|t| t.ty).collect::<~[Type]>();
let rty = self.ret_ty.ty;
let fnty = Type::func(atys, &rty);
let llfn = decl(fnty);

View File

@ -981,9 +981,9 @@ pub fn node_id_type_params(bcx: block, id: ast::node_id) -> ~[ty::t] {
match bcx.fcx.param_substs {
Some(substs) => {
do vec::map(params) |t| {
do params.iter().transform |t| {
ty::subst_tps(tcx, substs.tys, substs.self_ty, *t)
}
}.collect()
}
_ => params
}
@ -1007,9 +1007,11 @@ pub fn resolve_vtables_under_param_substs(tcx: ty::ctxt,
param_substs: Option<@param_substs>,
vts: typeck::vtable_res)
-> typeck::vtable_res {
@vec::map(*vts, |ds|
@vec::map(**ds, |d|
resolve_vtable_under_param_substs(tcx, param_substs, copy *d)))
@vts.iter().transform(|ds|
@ds.iter().transform(
|d| resolve_vtable_under_param_substs(tcx, param_substs, copy *d))
.collect::<~[typeck::vtable_origin]>())
.collect::<~[typeck::vtable_param_res]>()
}
@ -1030,9 +1032,9 @@ pub fn resolve_vtable_under_param_substs(tcx: ty::ctxt,
typeck::vtable_static(trait_id, tys, sub) => {
let tys = match param_substs {
Some(substs) => {
do vec::map(tys) |t| {
do tys.iter().transform |t| {
ty::subst_tps(tcx, substs.tys, substs.self_ty, *t)
}
}.collect()
}
_ => tys
};

View File

@ -588,8 +588,9 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr,
}
ast::expr_tup(ref args) => {
let repr = adt::represent_type(bcx.ccx(), expr_ty(bcx, expr));
return trans_adt(bcx, repr, 0, args.mapi(|i, arg| (i, *arg)),
None, dest);
let numbered_fields: ~[(uint, @ast::expr)] =
args.iter().enumerate().transform(|(i, arg)| (i, *arg)).collect();
return trans_adt(bcx, repr, 0, numbered_fields, None, dest);
}
ast::expr_lit(@codemap::spanned {node: ast::lit_str(s), _}) => {
return tvec::trans_lit_str(bcx, expr, s, dest);

View File

@ -30,7 +30,6 @@ use middle::ty::{FnSig};
use middle::typeck;
use util::ppaux::{Repr,ty_to_str};
use std::vec;
use syntax::ast;
use syntax::ast_map;
use syntax::ast_map::path_name;
@ -62,12 +61,12 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
assert!(real_substs.tps.iter().all(|t| !ty::type_needs_infer(*t)));
let _icx = push_ctxt("monomorphic_fn");
let mut must_cast = false;
let substs = vec::map(real_substs.tps, |t| {
let substs = real_substs.tps.iter().transform(|t| {
match normalize_for_monomorphization(ccx.tcx, *t) {
Some(t) => { must_cast = true; t }
None => *t
}
});
}).collect::<~[ty::t]>();
for real_substs.tps.iter().advance |s| { assert!(!ty::type_has_params(*s)); }
for substs.iter().advance |s| { assert!(!ty::type_has_params(*s)); }
@ -325,22 +324,22 @@ pub fn make_mono_id(ccx: @mut CrateContext,
vtables: Option<typeck::vtable_res>,
impl_did_opt: Option<ast::def_id>,
param_uses: Option<@~[type_use::type_uses]>) -> mono_id {
let precise_param_ids = match vtables {
// FIXME (possibly #5801): Need a lot of type hints to get
// .collect() to work.
let precise_param_ids: ~[(ty::t, Option<@~[mono_id]>)] = match vtables {
Some(vts) => {
debug!("make_mono_id vtables=%s substs=%s",
vts.repr(ccx.tcx), substs.repr(ccx.tcx));
vec::map_zip(*vts, substs, |vtable, subst| {
vts.iter().zip(substs.iter()).transform(|(vtable, subst)| {
let v = vtable.map(|vt| meth::vtable_id(ccx, vt));
(*subst, if !v.is_empty() { Some(@v) } else { None })
})
}
None => {
vec::map(substs, |subst| (*subst, None))
}).collect()
}
None => substs.iter().transform(|subst| (*subst, None::<@~[mono_id]>)).collect()
};
let param_ids = match param_uses {
Some(ref uses) => {
vec::map_zip(precise_param_ids, **uses, |id, uses| {
precise_param_ids.iter().zip(uses.iter()).transform(|(id, uses)| {
if ccx.sess.no_monomorphic_collapse() {
match copy *id {
(a, b) => mono_precise(a, b)
@ -377,13 +376,13 @@ pub fn make_mono_id(ccx: @mut CrateContext,
}
}
}
})
}).collect()
}
None => {
precise_param_ids.map(|x| {
precise_param_ids.iter().transform(|x| {
let (a, b) = copy *x;
mono_precise(a, b)
})
}).collect()
}
};
@mono_id_ {def: item, params: param_ids, impl_did_opt: impl_did_opt}

View File

@ -2323,7 +2323,7 @@ pub fn is_instantiable(cx: ctxt, r_ty: t) -> bool {
false
}
ty_struct(ref did, _) if vec::contains(*seen, did) => {
ty_struct(ref did, _) if seen.contains(did) => {
false
}
@ -2339,7 +2339,7 @@ pub fn is_instantiable(cx: ctxt, r_ty: t) -> bool {
ts.iter().any_(|t| type_requires(cx, seen, r_ty, *t))
}
ty_enum(ref did, _) if vec::contains(*seen, did) => {
ty_enum(ref did, _) if seen.contains(did) => {
false
}
@ -3266,7 +3266,7 @@ pub fn occurs_check(tcx: ctxt, sp: span, vid: TyVid, rt: t) {
if !type_needs_infer(rt) { return; }
// Occurs check!
if vec::contains(vars_in_type(rt), &vid) {
if vars_in_type(rt).contains(&vid) {
// Maybe this should be span_err -- however, there's an
// assertion later on that the type doesn't contain
// variables, so in this case we have to be sure to die.
@ -3674,15 +3674,15 @@ pub fn substd_enum_variants(cx: ctxt,
id: ast::def_id,
substs: &substs)
-> ~[VariantInfo] {
do vec::map(*enum_variants(cx, id)) |variant_info| {
let substd_args = vec::map(variant_info.args,
|aty| subst(cx, substs, *aty));
do enum_variants(cx, id).iter().transform |variant_info| {
let substd_args = variant_info.args.iter()
.transform(|aty| subst(cx, substs, *aty)).collect();
let substd_ctor_ty = subst(cx, substs, variant_info.ctor_ty);
@VariantInfo_{args: substd_args, ctor_ty: substd_ctor_ty,
../*bad*/copy **variant_info}
}
}.collect()
}
pub fn item_path_str(cx: ctxt, id: ast::def_id) -> ~str {
@ -3815,7 +3815,7 @@ pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[VariantInfo] {
_
}, _) => {
let mut disr_val = -1;
@vec::map(enum_definition.variants, |variant| {
@enum_definition.variants.iter().transform(|variant| {
match variant.node.kind {
ast::tuple_variant_kind(ref args) => {
let ctor_ty = node_id_to_type(cx, variant.node.id);
@ -3848,7 +3848,7 @@ pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[VariantInfo] {
fail!("struct variant kinds unimpl in enum_variants")
}
}
})
}).collect()
}
_ => cx.sess.bug("tag_variants: id not bound to an enum")
}

View File

@ -718,14 +718,14 @@ pub fn ty_of_closure<AC:AstConv,RS:region_scope + Copy + 'static>(
let bound_lifetime_names = bound_lifetimes(this, lifetimes);
let rb = in_binding_rscope(rscope, RegionParamNames(copy bound_lifetime_names));
let input_tys = do decl.inputs.mapi |i, a| {
let input_tys = do decl.inputs.iter().enumerate().transform |(i, a)| {
let expected_arg_ty = do expected_sig.chain_ref |e| {
// no guarantee that the correct number of expected args
// were supplied
if i < e.inputs.len() {Some(e.inputs[i])} else {None}
};
ty_of_arg(this, &rb, *a, expected_arg_ty)
};
}.collect();
let expected_ret_ty = expected_sig.map(|e| e.output);
let output_ty = match decl.output.node {

View File

@ -985,7 +985,7 @@ pub fn do_autoderef(fcx: @mut FnCtxt, sp: span, t: ty::t) -> (ty::t, uint) {
// concerned with this, as an error will be reported
// on the enum definition as well because the enum is
// not instantiable.
if vec::contains(enum_dids, did) {
if enum_dids.contains(did) {
return (t1, autoderefs);
}
enum_dids.push(*did);
@ -1781,7 +1781,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
_ => ()
}
let tps = vec::map(tys, |ty| fcx.to_ty(*ty));
let tps = tys.iter().transform(|ty| fcx.to_ty(*ty)).collect::<~[ty::t]>();
match method::lookup(fcx,
expr,
base,
@ -2766,7 +2766,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
let mut bot_field = false;
let mut err_field = false;
let elt_ts = do elts.mapi |i, e| {
let elt_ts = do elts.iter().enumerate().transform |(i, e)| {
let opt_hint = match flds {
Some(ref fs) if i < fs.len() => Some(fs[i]),
_ => None
@ -2776,7 +2776,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
err_field = err_field || ty::type_is_error(t);
bot_field = bot_field || ty::type_is_bot(t);
t
};
}.collect();
if bot_field {
fcx.write_bot(id);
} else if err_field {
@ -3156,7 +3156,7 @@ pub fn check_enum_variants(ccx: @mut CrateCtxt,
}
}
}
if vec::contains(*disr_vals, &*disr_val) {
if disr_vals.contains(&*disr_val) {
ccx.tcx.sess.span_err(v.span,
"discriminator value already exists");
}

View File

@ -712,7 +712,7 @@ pub fn convert_methods(ccx: &CrateCtxt,
-> ~[ConvertedMethod]
{
let tcx = ccx.tcx;
return vec::map(ms, |m| {
return ms.iter().transform(|m| {
let num_rcvr_ty_params = rcvr_ty_generics.type_param_defs.len();
let m_ty_generics =
ty_generics(ccx, rcvr_ty_generics.region_param, &m.generics,
@ -742,7 +742,7 @@ pub fn convert_methods(ccx: &CrateCtxt,
tcx.methods.insert(mty.def_id, mty);
ConvertedMethod {mty: mty, id: m.id,
span: m.span, body_id: m.body.node.id}
});
}).collect();
fn ty_of_method(ccx: &CrateCtxt,
m: &ast::method,

View File

@ -1478,7 +1478,7 @@ impl RegionVarBindings {
// overlapping locations.
let mut dup_vec = graph.nodes.map(|_| uint::max_value);
graph.nodes.mapi(|idx, node| {
graph.nodes.iter().enumerate().transform(|(idx, node)| {
match node.value {
Value(_) => {
/* Inference successful */
@ -1528,7 +1528,7 @@ impl RegionVarBindings {
}
node.value
})
}).collect()
}
pub fn report_error_for_expanding_node(&mut self,

View File

@ -57,7 +57,6 @@ use middle::typeck::infer::unify::{Root, UnifyInferCtxtMethods};
use util::common::{indent, indenter};
use util::ppaux::ty_to_str;
use std::vec;
use syntax::ast;
pub static resolve_nested_tvar: uint = 0b0000000001;
@ -204,7 +203,7 @@ impl ResolveState {
}
pub fn resolve_ty_var(&mut self, vid: TyVid) -> ty::t {
if vec::contains(self.v_seen, &vid) {
if self.v_seen.contains(&vid) {
self.err = Some(cyclic_ty(vid));
return ty::mk_var(self.infcx.tcx, vid);
} else {

View File

@ -26,7 +26,6 @@ use fold::Fold;
use fold;
use pass::Pass;
use std::vec;
use syntax::ast;
use syntax::ast_map;
@ -124,7 +123,7 @@ fn fold_enum(
let doc = fold::default_seq_fold_enum(fold, doc);
doc::EnumDoc {
variants: do vec::map(doc.variants) |variant| {
variants: do doc.variants.iter().transform |variant| {
let variant = copy *variant;
let desc = {
let variant = copy variant;
@ -153,7 +152,7 @@ fn fold_enum(
desc: desc,
.. variant
}
},
}.collect(),
.. doc
}
}
@ -183,7 +182,7 @@ fn merge_method_attrs(
ast_map::node_item(@ast::item {
node: ast::item_trait(_, _, ref methods), _
}, _) => {
vec::map(*methods, |method| {
methods.iter().transform(|method| {
match copy *method {
ast::required(ty_m) => {
(to_str(ty_m.ident),
@ -193,21 +192,21 @@ fn merge_method_attrs(
(to_str(m.ident), attr_parser::parse_desc(copy m.attrs))
}
}
})
}).collect()
}
ast_map::node_item(@ast::item {
node: ast::item_impl(_, _, _, ref methods), _
}, _) => {
vec::map(*methods, |method| {
methods.iter().transform(|method| {
(to_str(method.ident),
attr_parser::parse_desc(copy method.attrs))
})
}).collect()
}
_ => fail!("unexpected item")
}
};
do vec::map_zip(docs, attrs) |doc, attrs| {
do docs.iter().zip(attrs.iter()).transform |(doc, attrs)| {
assert!(doc.name == attrs.first());
let desc = attrs.second();
@ -215,7 +214,7 @@ fn merge_method_attrs(
desc: desc,
.. copy *doc
}
}
}.collect()
}

View File

@ -186,7 +186,7 @@ fn enumdoc_from_enum(
fn variantdocs_from_variants(
variants: ~[ast::variant]
) -> ~[doc::VariantDoc] {
vec::map(variants, variantdoc_from_variant)
variants.iter().transform(variantdoc_from_variant).collect()
}
fn variantdoc_from_variant(variant: &ast::variant) -> doc::VariantDoc {
@ -203,7 +203,7 @@ fn traitdoc_from_trait(
) -> doc::TraitDoc {
doc::TraitDoc {
item: itemdoc,
methods: do vec::map(methods) |method| {
methods: do methods.iter().transform |method| {
match copy *method {
ast::required(ty_m) => {
doc::MethodDoc {
@ -226,7 +226,7 @@ fn traitdoc_from_trait(
}
}
}
}
}.collect()
}
}
@ -239,7 +239,7 @@ fn impldoc_from_impl(
bounds_str: None,
trait_types: ~[],
self_ty: None,
methods: do vec::map(methods) |method| {
methods: do methods.iter().transform |method| {
doc::MethodDoc {
name: to_str(method.ident),
brief: None,
@ -248,7 +248,7 @@ fn impldoc_from_impl(
sig: None,
implementation: doc::Provided,
}
}
}.collect()
}
}

View File

@ -13,8 +13,6 @@ use doc;
#[cfg(test)] use extract;
#[cfg(test)] use parse;
use std::vec;
pub struct Fold<T> {
ctxt: T,
fold_doc: FoldDoc<T>,
@ -155,7 +153,7 @@ pub fn default_par_fold<T:Clone>(ctxt: T) -> Fold<T> {
pub fn default_seq_fold_doc<T>(fold: &Fold<T>, doc: doc::Doc) -> doc::Doc {
doc::Doc {
pages: do vec::map(doc.pages) |page| {
pages: do doc.pages.iter().transform |page| {
match copy *page {
doc::CratePage(doc) => {
doc::CratePage((fold.fold_crate)(fold, doc))
@ -164,7 +162,7 @@ pub fn default_seq_fold_doc<T>(fold: &Fold<T>, doc: doc::Doc) -> doc::Doc {
doc::ItemPage(fold_ItemTag(fold, doc))
}
}
},
}.collect(),
.. doc
}
}
@ -191,9 +189,9 @@ pub fn default_any_fold_mod<T:Clone>(
) -> doc::ModDoc {
doc::ModDoc {
item: (fold.fold_item)(fold, copy doc.item),
items: vec::map(doc.items, |ItemTag| {
items: doc.items.iter().transform(|ItemTag| {
fold_ItemTag(fold, copy *ItemTag)
}),
}).collect(),
.. doc
}
}
@ -204,9 +202,9 @@ pub fn default_seq_fold_mod<T>(
) -> doc::ModDoc {
doc::ModDoc {
item: (fold.fold_item)(fold, copy doc.item),
items: vec::map(doc.items, |ItemTag| {
items: doc.items.iter().transform(|ItemTag| {
fold_ItemTag(fold, copy *ItemTag)
}),
}).collect(),
.. doc
}
}
@ -217,9 +215,9 @@ pub fn default_par_fold_mod<T:Clone>(
) -> doc::ModDoc {
doc::ModDoc {
item: (fold.fold_item)(fold, copy doc.item),
items: vec::map(doc.items, |ItemTag| {
items: doc.items.iter().transform(|ItemTag| {
fold_ItemTag(fold, copy *ItemTag)
}),
}).collect(),
.. doc
}
}
@ -230,9 +228,9 @@ pub fn default_any_fold_nmod<T:Clone>(
) -> doc::NmodDoc {
doc::NmodDoc {
item: (fold.fold_item)(fold, copy doc.item),
fns: vec::map(doc.fns, |FnDoc| {
fns: doc.fns.iter().transform(|FnDoc| {
(fold.fold_fn)(fold, copy *FnDoc)
}),
}).collect(),
.. doc
}
}
@ -243,9 +241,9 @@ pub fn default_seq_fold_nmod<T>(
) -> doc::NmodDoc {
doc::NmodDoc {
item: (fold.fold_item)(fold, copy doc.item),
fns: vec::map(doc.fns, |FnDoc| {
fns: doc.fns.iter().transform(|FnDoc| {
(fold.fold_fn)(fold, copy *FnDoc)
}),
}).collect(),
.. doc
}
}
@ -256,9 +254,9 @@ pub fn default_par_fold_nmod<T:Clone>(
) -> doc::NmodDoc {
doc::NmodDoc {
item: (fold.fold_item)(fold, copy doc.item),
fns: vec::map(doc.fns, |FnDoc| {
fns: doc.fns.iter().transform(|FnDoc| {
(fold.fold_fn)(fold, copy *FnDoc)
}),
}).collect(),
.. doc
}
}

View File

@ -20,7 +20,6 @@ use fold::Fold;
use fold;
use pass::Pass;
use std::vec;
use syntax::ast;
use syntax::print::pprust;
use syntax::parse::token;
@ -114,7 +113,7 @@ fn fold_enum(
let srv = fold.ctxt.clone();
doc::EnumDoc {
variants: do vec::map(doc.variants) |variant| {
variants: do doc.variants.iter().transform |variant| {
let sig = {
let variant = copy *variant;
do astsrv::exec(srv.clone()) |ctxt| {
@ -139,7 +138,7 @@ fn fold_enum(
sig: Some(sig),
.. copy *variant
}
},
}.collect(),
.. doc
}
}
@ -159,12 +158,12 @@ fn merge_methods(
item_id: doc::AstId,
docs: ~[doc::MethodDoc]
) -> ~[doc::MethodDoc] {
do vec::map(docs) |doc| {
do docs.iter().transform |doc| {
doc::MethodDoc {
sig: get_method_sig(srv.clone(), item_id, copy doc.name),
.. copy *doc
}
}
}.collect()
}
fn get_method_sig(

View File

@ -597,9 +597,9 @@ fn rust_path_contents() {
let cwd = os::getcwd().push(".rust");
let parent = cwd.pop().pop().push(".rust");
let grandparent = cwd.pop().pop().pop().push(".rust");
assert!(vec::contains(p, &cwd));
assert!(vec::contains(p, &parent));
assert!(vec::contains(p, &grandparent));
assert!(p.contains(&cwd));
assert!(p.contains(&parent));
assert!(p.contains(&grandparent));
for p.iter().advance() |a_path| {
assert!(!a_path.components.is_empty());
}
@ -610,9 +610,9 @@ fn rust_path_contents() {
fn rust_path_parse() {
os::setenv("RUST_PATH", "/a/b/c:/d/e/f:/g/h/i");
let paths = rust_path();
assert!(vec::contains(paths, &Path("/g/h/i")));
assert!(vec::contains(paths, &Path("/d/e/f")));
assert!(vec::contains(paths, &Path("/a/b/c")));
assert!(paths.contains(&Path("/g/h/i")));
assert!(paths.contains(&Path("/d/e/f")));
assert!(paths.contains(&Path("/a/b/c")));
os::unsetenv("RUST_PATH");
}

View File

@ -939,7 +939,7 @@ mod test_map {
mod test_set {
use super::*;
use container::{Container, Map, Set};
use vec;
use vec::ImmutableEqVector;
use uint;
#[test]
@ -1030,7 +1030,7 @@ mod test_set {
let mut i = 0;
let expected = [3, 5, 11, 77];
for a.intersection(&b) |x| {
assert!(vec::contains(expected, x));
assert!(expected.contains(x));
i += 1
}
assert_eq!(i, expected.len());
@ -1053,7 +1053,7 @@ mod test_set {
let mut i = 0;
let expected = [1, 5, 11];
for a.difference(&b) |x| {
assert!(vec::contains(expected, x));
assert!(expected.contains(x));
i += 1
}
assert_eq!(i, expected.len());
@ -1079,7 +1079,7 @@ mod test_set {
let mut i = 0;
let expected = [-2, 1, 5, 11, 14, 22];
for a.symmetric_difference(&b) |x| {
assert!(vec::contains(expected, x));
assert!(expected.contains(x));
i += 1
}
assert_eq!(i, expected.len());
@ -1109,7 +1109,7 @@ mod test_set {
let mut i = 0;
let expected = [-2, 1, 3, 5, 9, 11, 13, 16, 19, 24];
for a.union(&b) |x| {
assert!(vec::contains(expected, x));
assert!(expected.contains(x));
i += 1
}
assert_eq!(i, expected.len());

View File

@ -1912,7 +1912,9 @@ mod tests {
if len <= ivals.len() {
assert_eq!(res.len(), len);
}
assert!(ivals.slice(0u, res.len()) == vec::map(res, |x| *x as int));
for ivals.iter().zip(res.iter()).advance |(iv, c)| {
assert!(*iv == *c as int)
}
}
}
let mut i = 0;

View File

@ -85,8 +85,7 @@ pub trait IteratorUtil<A> {
// FIXME: #5898: should be called map
/// Creates a new iterator which will apply the specified function to each
/// element returned by the first, yielding the mapped element instead. This
/// similar to the `vec::map` function.
/// element returned by the first, yielding the mapped element instead.
///
/// # Example
///

View File

@ -18,8 +18,7 @@ use char;
use str;
use str::StrSlice;
use kinds::Copy;
use vec;
use vec::{CopyableVector, ImmutableVector};
use vec::{CopyableVector, ImmutableVector, MutableVector};
use vec::OwnedVector;
use num::{NumCast, Zero, One, cast, pow_with_uint, Integer};
use num::{Round, Float, FPNaN, FPInfinite};
@ -292,7 +291,7 @@ pub fn float_to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Float+Round+
_ => ()
}
vec::reverse(buf);
buf.reverse();
// Remember start of the fractional digits.
// Points one beyond end of buf if none get generated,

View File

@ -1544,10 +1544,10 @@ mod tests {
let mut e = env();
setenv(n, "VALUE");
assert!(!vec::contains(e, &(copy n, ~"VALUE")));
assert!(!e.contains(&(copy n, ~"VALUE")));
e = env();
assert!(vec::contains(e, &(n, ~"VALUE")));
assert!(e.contains(&(n, ~"VALUE")));
}
#[test]

View File

@ -73,8 +73,8 @@ pub use tuple::{ImmutableTuple2, ImmutableTuple3, ImmutableTuple4, ImmutableTupl
pub use tuple::{ImmutableTuple6, ImmutableTuple7, ImmutableTuple8, ImmutableTuple9};
pub use tuple::{ImmutableTuple10, ImmutableTuple11, ImmutableTuple12};
pub use vec::{VectorVector, CopyableVector, ImmutableVector};
pub use vec::{ImmutableEqVector, ImmutableCopyableVector};
pub use vec::{OwnedVector, OwnedCopyableVector, MutableVector};
pub use vec::{ImmutableEqVector, ImmutableTotalOrdVector, ImmutableCopyableVector};
pub use vec::{OwnedVector, OwnedCopyableVector,OwnedEqVector, MutableVector};
pub use io::{Reader, ReaderUtil, Writer, WriterUtil};
// Reexported runtime types

View File

@ -590,7 +590,7 @@ impl<R: Rng> RngUtil for R {
// invariant: elements with index >= i have been locked in place.
i -= 1u;
// lock element i in place.
vec::swap(values, i, self.gen_uint_range(0u, i + 1u));
values.swap(i, self.gen_uint_range(0u, i + 1u));
}
}
}

View File

@ -14,6 +14,8 @@
use kinds::Copy;
use vec;
use vec::ImmutableVector;
use iterator::IteratorUtil;
pub use self::inner::*;
@ -96,7 +98,7 @@ impl<'self,A:Copy,B:Copy> ExtendedTupleOps<A,B> for (&'self [A], &'self [B]) {
fn map<C>(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C] {
match *self {
(ref a, ref b) => {
vec::map_zip(*a, *b, f)
a.iter().zip(b.iter()).transform(|(aa, bb)| f(aa, bb)).collect()
}
}
}
@ -116,7 +118,7 @@ impl<A:Copy,B:Copy> ExtendedTupleOps<A,B> for (~[A], ~[B]) {
fn map<C>(&self, f: &fn(a: &A, b: &B) -> C) -> ~[C] {
match *self {
(ref a, ref b) => {
vec::map_zip(*a, *b, f)
a.iter().zip(b.iter()).transform(|(aa, bb)| f(aa, bb)).collect()
}
}
}

View File

@ -16,9 +16,9 @@ pub mod general_category {
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
use cmp::{Equal, Less, Greater};
use vec::bsearch;
use vec::ImmutableVector;
use option::None;
(do bsearch(r) |&(lo,hi)| {
(do r.bsearch |&(lo,hi)| {
if lo <= c && c <= hi { Equal }
else if hi < c { Less }
else { Greater }
@ -1447,15 +1447,13 @@ pub mod general_category {
}
}
pub mod derived_property {
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
use cmp::{Equal, Less, Greater};
use vec::bsearch;
use vec::ImmutableVector;
use option::None;
(do bsearch(r) |&(lo,hi)| {
(do r.bsearch |&(lo,hi)| {
if lo <= c && c <= hi { Equal }
else if hi < c { Less }
else { Greater }
@ -2641,4 +2639,5 @@ pub mod derived_property {
pub fn XID_Start(c: char) -> bool {
bsearch_range_table(c, XID_Start_table)
}
}

File diff suppressed because it is too large Load Diff

View File

@ -814,7 +814,7 @@ mod test {
// convert a list of uints to an @[ident]
// (ignores the interner completely)
fn uints_to_idents (uints: &~[uint]) -> @~[ident] {
@uints.map(|u|{ ident {name:*u, ctxt: empty_ctxt} })
@uints.map(|u| ident {name:*u, ctxt: empty_ctxt})
}
fn id (u : uint, s: SyntaxContext) -> ident {

View File

@ -91,9 +91,9 @@ fn decodable_substructure(cx: @ExtCtxt, span: span,
}
}
Right(ref fields) => {
let fields = do fields.mapi |i, f| {
let fields = do fields.iter().enumerate().transform |(i, f)| {
cx.field_imm(span, *f, getarg(cx.str_of(*f), i))
};
}.collect();
cx.expr_struct_ident(span, substr.type_ident, fields)
}
};
@ -133,9 +133,9 @@ fn decodable_substructure(cx: @ExtCtxt, span: span,
}
}
Right(ref fields) => {
let fields = do fields.mapi |i, f| {
let fields = do fields.iter().enumerate().transform |(i, f)| {
cx.field_imm(span, *f, getarg(i))
};
}.collect();
cx.expr_struct_ident(span, name, fields)
}
};

View File

@ -591,14 +591,14 @@ impl<'self> MethodDef<'self> {
// transpose raw_fields
let fields = match raw_fields {
[self_arg, .. rest] => {
do self_arg.mapi |i, &(opt_id, field)| {
do self_arg.iter().enumerate().transform |(i, &(opt_id, field))| {
let other_fields = do rest.map |l| {
match &l[i] {
&(_, ex) => ex
}
};
(opt_id, field, other_fields)
}
}.collect()
}
[] => { cx.span_bug(span, "No self arguments to non-static \
method in generic `deriving`") }
@ -745,10 +745,11 @@ impl<'self> MethodDef<'self> {
}
}
let field_tuples =
do vec::map_zip(*self_vec,
enum_matching_fields) |&(id, self_f), &other| {
do self_vec.iter()
.zip(enum_matching_fields.iter())
.transform |(&(id, self_f), &other)| {
(id, self_f, other)
};
}.collect();
substructure = EnumMatching(variant_index, variant, field_tuples);
}
None => {

View File

@ -91,7 +91,7 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr {
let rand_variant = cx.expr_binary(span, ast::rem,
rv_call, variant_count);
let mut arms = do variants.mapi |i, id_sum| {
let mut arms = do variants.iter().enumerate().transform |(i, id_sum)| {
let i_expr = cx.expr_uint(span, i);
let pat = cx.pat_lit(span, i_expr);
@ -102,7 +102,7 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr {
rand_thing(cx, span, ident, summary, || rand_call()))
}
}
};
}.collect::<~[ast::arm]>();
// _ => {} at the end. Should never occur
arms.push(cx.arm_unreachable(span));

View File

@ -54,8 +54,9 @@ impl gen_send for message {
let next = this.proto.get_state(next_state.state);
assert!(next_state.tys.len() ==
next.generics.ty_params.len());
let arg_names = tys.mapi(|i, _ty| cx.ident_of(~"x_"+i.to_str()));
let args_ast = vec::map_zip(arg_names, *tys, |n, t| cx.arg(span, *n, *t));
let arg_names = vec::from_fn(tys.len(), |i| cx.ident_of("x_"+i.to_str()));
let args_ast: ~[ast::arg] = arg_names.iter().zip(tys.iter())
.transform(|(n, t)| cx.arg(span, *n, *t)).collect();
let pipe_ty = cx.ty_path(
path(~[this.data_name()], span)
@ -133,11 +134,10 @@ impl gen_send for message {
message(ref _id, span, ref tys, this, None) => {
debug!("pipec: no next state");
let arg_names = tys.mapi(|i, _ty| (~"x_" + i.to_str()));
let arg_names = vec::from_fn(tys.len(), |i| "x_" + i.to_str());
let args_ast = do vec::map_zip(arg_names, *tys) |n, t| {
cx.arg(span, cx.ident_of(*n), *t)
};
let args_ast: ~[ast::arg] = arg_names.iter().zip(tys.iter())
.transform(|(n, t)| cx.arg(span, cx.ident_of(*n), *t)).collect();
let args_ast = vec::append(
~[cx.arg(span,

View File

@ -21,7 +21,6 @@ use print::pprust;
use std::io;
use std::result;
use std::vec;
// These macros all relate to the file system; they either return
// the column/row/filename of the expression, or they include
@ -106,9 +105,7 @@ pub fn expand_include_bin(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
let file = get_single_str_from_tts(cx, sp, tts, "include_bin!");
match io::read_whole_file(&res_rel_file(cx, sp, &Path(file))) {
result::Ok(src) => {
let u8_exprs = vec::map(src, |char| {
cx.expr_u8(sp, *char)
});
let u8_exprs: ~[@ast::expr] = src.iter().transform(|char| cx.expr_u8(sp, *char)).collect();
base::MRExpr(cx.expr_vec(sp, u8_exprs))
}
result::Err(ref e) => {

View File

@ -326,8 +326,7 @@ pub fn parse(
cur_eis.push(new_ei);
}
let matches = vec::map(ei.matches, // fresh, same size:
|_m| ~[]);
let matches = vec::from_elem(ei.matches.len(), ~[]);
let ei_t = ei;
cur_eis.push(~MatcherPos {
elts: copy *matchers,

View File

@ -699,7 +699,7 @@ pub fn noop_fold_ty(t: &ty_, fld: @ast_fold) -> ty_ {
// ...nor do modules
pub fn noop_fold_mod(m: &_mod, fld: @ast_fold) -> _mod {
ast::_mod {
view_items: vec::map(m.view_items, |x| fld.fold_view_item(*x)),
view_items: m.view_items.iter().transform(|x| fld.fold_view_item(*x)).collect(),
items: vec::filter_mapped(m.items, |x| fld.fold_item(*x)),
}
}
@ -708,8 +708,8 @@ fn noop_fold_foreign_mod(nm: &foreign_mod, fld: @ast_fold) -> foreign_mod {
ast::foreign_mod {
sort: nm.sort,
abis: nm.abis,
view_items: vec::map(nm.view_items, |x| fld.fold_view_item(*x)),
items: vec::map(nm.items, |x| fld.fold_foreign_item(*x)),
view_items: nm.view_items.iter().transform(|x| fld.fold_view_item(*x)).collect(),
items: nm.items.iter().transform(|x| fld.fold_foreign_item(*x)).collect(),
}
}
@ -728,8 +728,8 @@ fn noop_fold_variant(v: &variant_, fld: @ast_fold) -> variant_ {
}
struct_variant_kind(struct_def) => {
kind = struct_variant_kind(@ast::struct_def {
fields: vec::map(struct_def.fields,
|f| fld.fold_struct_field(*f)),
fields: struct_def.fields.iter()
.transform(|f| fld.fold_struct_field(*f)).collect(),
ctor_id: struct_def.ctor_id.map(|c| fld.new_id(*c))
})
}
@ -824,8 +824,7 @@ impl ast_fold for AstFoldFns {
@view_item {
@ast::view_item {
node: (self.fold_view_item)(&x.node, self as @ast_fold),
attrs: vec::map(x.attrs, |a|
fold_attribute_(*a, self as @ast_fold)),
attrs: x.attrs.iter().transform(|a| fold_attribute_(*a, self as @ast_fold)).collect(),
vis: x.vis,
span: (self.new_span)(x.span),
}

View File

@ -191,13 +191,13 @@ fn bfs2(graph: graph, key: node_id) -> bfs_result {
// Do the BFS.
info!("PBFS iteration %?", i);
i += 1;
colors = do colors.mapi() |i, c| {
colors = do colors.iter().enumerate().transform |(i, c)| {
let c : color = *c;
match c {
white => {
let i = i as node_id;
let neighbors = copy graph[i];
let neighbors = &graph[i];
let mut color = white;
@ -214,17 +214,17 @@ fn bfs2(graph: graph, key: node_id) -> bfs_result {
gray(parent) => { black(parent) }
black(parent) => { black(parent) }
}
}
}.collect()
}
// Convert the results.
do vec::map(colors) |c| {
do colors.iter().transform |c| {
match *c {
white => { -1i64 }
black(parent) => { parent }
_ => { fail!("Found remaining gray nodes in BFS") }
}
}
}.collect()
}
/// A parallel version of the bfs function.
@ -341,7 +341,7 @@ fn validate(edges: ~[(node_id, node_id)],
}
else {
while parent != root {
if vec::contains(path, &parent) {
if path.contains(&parent) {
status = false;
}

View File

@ -152,7 +152,7 @@ fn rendezvous(nn: uint, set: ~[color]) {
// these channels will allow us to talk to each creature by 'name'/index
let to_creature: ~[Chan<Option<CreatureInfo>>] =
vec::mapi(set, |ii, col| {
set.iter().enumerate().transform(|(ii, col)| {
// create each creature as a listener with a port, and
// give us a channel to talk to each
let ii = ii;
@ -166,7 +166,7 @@ fn rendezvous(nn: uint, set: ~[color]) {
to_rendezvous_log.clone());
}
to_creature
});
}).collect();
let mut creatures_met = 0;

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// xfail-pretty (extra blank line is inserted in vec::mapi call)
// xfail-pretty the `let to_child` line gets an extra newline
// multi tasking k-nucleotide
extern mod extra;
@ -163,14 +163,13 @@ fn main() {
// initialize each sequence sorter
let sizes = ~[1,2,3,4,6,12,18];
let streams = vec::map(sizes, |_sz| Some(stream()));
let mut streams = streams;
// initialize each sequence sorter
let sizes = ~[1u,2,3,4,6,12,18];
let mut streams = vec::from_fn(sizes.len(), |_| Some(stream::<~str>()));
let mut from_child = ~[];
let to_child = vec::mapi(sizes, |ii, sz| {
let to_child = do sizes.iter().zip(streams.mut_iter()).transform |(sz, stream_ref)| {
let sz = *sz;
let stream = util::replace(&mut streams[ii], None);
let stream = util::replace(stream_ref, None);
let (from_child_, to_parent_) = stream.unwrap();
from_child.push(from_child_);
@ -182,7 +181,7 @@ fn main() {
};
to_child
});
}.collect::<~[Chan<~[u8]>]>();
// latch stores true after we've started

View File

@ -30,7 +30,7 @@ use std::io::WriterUtil;
// Make sure this import is warned about when at least one of its imported names
// is unused
use std::vec::{filter, map}; //~ ERROR unused import
use std::vec::{filter, from_elem}; //~ ERROR unused import
mod foo {
pub struct Point{x: int, y: int}
@ -58,7 +58,5 @@ fn main() {
let a = 3;
ignore(a);
io::stdout().write_str("a");
let _a = do map([2]) |&x| {
x + 2
};
let _a = from_elem(0, 0);
}

View File

@ -1,8 +1,6 @@
// Tests that references to move-by-default values trigger moves when
// they occur as part of various kinds of expressions.
use std::vec;
struct Foo<A> { f: A }
fn guard(_s: ~str) -> bool {fail!()}
fn touch<A>(_a: &A) {}
@ -92,7 +90,7 @@ fn f110() {
fn f120() {
let mut x = ~[~"hi", ~"ho"];
vec::swap(x, 0, 1);
x.swap(0, 1);
touch(&x[0]);
touch(&x[1]);
}

View File

@ -28,7 +28,7 @@ pub fn main() {
assert!(any_negative);
// Higher precedence than unary operations:
let abs_v = do vec::map(v) |e| { e.abs() };
let abs_v = do v.iter().transform |e| { e.abs() }.collect::<~[float]>();
assert!(do abs_v.iter().all |e| { e.is_positive() });
assert!(!do abs_v.iter().any_ |e| { e.is_negative() });

View File

@ -1,20 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::vec;
pub fn main() {
let v =
vec::map_zip(~[1, 2, 3, 4, 5],
~[true, false, false, true, true],
|i, b| if *b { -(*i) } else { *i } );
error!(v.clone());
assert_eq!(v, ~[-1, 2, 3, -4, -5]);
}

View File

@ -1,13 +1,11 @@
use std::vec;
trait Reverser {
fn reverse(&self);
fn reverse(v: &mut [uint]) {
v.reverse();
}
fn bar(v: &mut [uint]) {
vec::reverse(v);
vec::reverse(v);
vec::reverse(v);
reverse(v);
reverse(v);
reverse(v);
}
pub fn main() {

View File

@ -1,15 +1,3 @@
use std::vec;
trait Reverser {
fn reverse(self);
}
impl<'self> Reverser for &'self mut [uint] {
fn reverse(self) {
vec::reverse(self);
}
}
fn bar(v: &mut [uint]) {
v.reverse();
v.reverse();

View File

@ -69,9 +69,7 @@ fn AsciiArt(width: uint, height: uint, fill: char) -> AsciiArt {
// blank characters for each position in our canvas.
let mut lines = do vec::build_sized(height) |push| {
for height.times {
let mut line = ~[];
vec::grow_set(&mut line, width-1, &'.', '.');
push(line);
push(vec::from_elem(width, '.'));
}
};

View File

@ -9,11 +9,10 @@
// except according to those terms.
use std::util;
use std::vec;
pub fn main() {
let mut a: ~[int] = ~[0, 1, 2, 3, 4, 5, 6];
vec::swap(a, 2, 4);
a.swap(2, 4);
assert_eq!(a[2], 4);
assert_eq!(a[4], 2);
let mut n = 42;

View File

@ -15,7 +15,9 @@
extern mod std;
use std::str::StrVector;
use std::{int, vec};
use std::vec::ImmutableVector;
use std::iterator::IteratorUtil;
use std::int;
trait to_str {
fn to_str(&self) -> ~str;
@ -27,7 +29,7 @@ impl to_str for int {
impl<T:to_str> to_str for ~[T] {
fn to_str(&self) -> ~str {
~"[" + vec::map(*self, |e| e.to_str()).connect(", ") + "]"
fmt!("[%s]", self.iter().transform(|e| e.to_str()).collect::<~[~str]>().connect(", "))
}
}