Skip to content

Commit

Permalink
for x in xs.iter() -> for x in &xs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Aparicio committed Feb 2, 2015
1 parent 9f90d66 commit d5d7e65
Show file tree
Hide file tree
Showing 269 changed files with 1,063 additions and 1,064 deletions.
6 changes: 3 additions & 3 deletions src/compiletest/compiletest.rs
Expand Up @@ -276,7 +276,7 @@ pub fn make_tests(config: &Config) -> Vec<test::TestDescAndFn> {
config.src_base.display());
let mut tests = Vec::new();
let dirs = fs::readdir(&config.src_base).unwrap();
for file in dirs.iter() {
for file in &dirs {
let file = file.clone();
debug!("inspecting file {:?}", file.display());
if is_test(config, &file) {
Expand Down Expand Up @@ -304,13 +304,13 @@ pub fn is_test(config: &Config, testfile: &Path) -> bool {

let mut valid = false;

for ext in valid_extensions.iter() {
for ext in &valid_extensions {
if name.ends_with(ext.as_slice()) {
valid = true;
}
}

for pre in invalid_prefixes.iter() {
for pre in &invalid_prefixes {
if name.starts_with(pre.as_slice()) {
valid = false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/compiletest/procsrv.rs
Expand Up @@ -46,7 +46,7 @@ pub fn run(lib_path: &str,

match cmd.spawn() {
Ok(mut process) => {
for input in input.iter() {
if let Some(input) = input {
process.stdin.as_mut().unwrap().write_all(input.as_bytes()).unwrap();
}
let ProcessOutput { status, output, error } =
Expand Down Expand Up @@ -78,7 +78,7 @@ pub fn run_background(lib_path: &str,

match cmd.spawn() {
Ok(mut process) => {
for input in input.iter() {
if let Some(input) = input {
process.stdin.as_mut().unwrap().write_all(input.as_bytes()).unwrap();
}

Expand Down
18 changes: 9 additions & 9 deletions src/compiletest/runtest.rs
Expand Up @@ -547,7 +547,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
exe_file.as_str().unwrap().replace("\\", "\\\\"))[]);

// Add line breakpoints
for line in breakpoint_lines.iter() {
for line in &breakpoint_lines {
script_str.push_str(&format!("break '{}':{}\n",
testfile.filename_display(),
*line)[]);
Expand Down Expand Up @@ -683,13 +683,13 @@ fn run_debuginfo_lldb_test(config: &Config, props: &TestProps, testfile: &Path)
script_str.push_str("type category enable Rust\n");

// Set breakpoints on every line that contains the string "#break"
for line in breakpoint_lines.iter() {
for line in &breakpoint_lines {
script_str.push_str(format!("breakpoint set --line {}\n",
line).as_slice());
}

// Append the other commands
for line in commands.iter() {
for line in &commands {
script_str.push_str(line.as_slice());
script_str.push_str("\n");
}
Expand Down Expand Up @@ -847,7 +847,7 @@ fn check_debugger_output(debugger_run_result: &ProcRes, check_lines: &[String])
let mut rest = line.trim();
let mut first = true;
let mut failed = false;
for frag in check_fragments[i].iter() {
for frag in &check_fragments[i] {
let found = if first {
if rest.starts_with(frag.as_slice()) {
Some(0)
Expand Down Expand Up @@ -915,7 +915,7 @@ fn check_error_patterns(props: &TestProps,
missing_patterns[0]).as_slice(),
proc_res);
} else {
for pattern in missing_patterns.iter() {
for pattern in missing_patterns {
error(format!("error pattern '{}' not found!",
*pattern).as_slice());
}
Expand All @@ -935,7 +935,7 @@ fn check_no_compiler_crash(proc_res: &ProcRes) {
fn check_forbid_output(props: &TestProps,
output_to_check: &str,
proc_res: &ProcRes) {
for pat in props.forbid_output.iter() {
for pat in &props.forbid_output {
if output_to_check.contains(pat.as_slice()) {
fatal_proc_rec("forbidden pattern found in compiler output", proc_res);
}
Expand Down Expand Up @@ -1173,7 +1173,7 @@ fn compose_and_run_compiler(
// FIXME (#9639): This needs to handle non-utf8 paths
let extra_link_args = vec!("-L".to_string(), aux_dir.as_str().unwrap().to_string());

for rel_ab in props.aux_builds.iter() {
for rel_ab in &props.aux_builds {
let abs_ab = config.aux_base.join(rel_ab.as_slice());
let aux_props = header::load_props(&abs_ab);
let mut crate_type = if aux_props.no_prefer_dynamic {
Expand Down Expand Up @@ -1510,7 +1510,7 @@ fn _arm_exec_compiled_test(config: &Config,
runargs.push(format!("{}", config.adb_test_dir));
runargs.push(format!("{}", prog_short));

for tv in args.args.iter() {
for tv in &args.args {
runargs.push(tv.to_string());
}
procsrv::run("",
Expand Down Expand Up @@ -1591,7 +1591,7 @@ fn _arm_push_aux_shared_library(config: &Config, testfile: &Path) {
let tdir = aux_output_dir_name(config, testfile);

let dirs = fs::readdir(&tdir).unwrap();
for file in dirs.iter() {
for file in &dirs {
if file.extension_str() == Some("so") {
// FIXME (#9639): This needs to handle non-utf8 paths
let copy_result = procsrv::run("",
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/util.rs
Expand Up @@ -26,7 +26,7 @@ static OS_TABLE: &'static [(&'static str, &'static str)] = &[
];

pub fn get_os(triple: &str) -> &'static str {
for &(triple_os, os) in OS_TABLE.iter() {
for &(triple_os, os) in OS_TABLE {
if triple.contains(triple_os) {
return os
}
Expand Down
2 changes: 1 addition & 1 deletion src/libarena/lib.rs
Expand Up @@ -127,7 +127,7 @@ impl Drop for Arena {
fn drop(&mut self) {
unsafe {
destroy_chunk(&*self.head.borrow());
for chunk in self.chunks.borrow().iter() {
for chunk in &*self.chunks.borrow() {
if !chunk.is_copy.get() {
destroy_chunk(chunk);
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/bench.rs
Expand Up @@ -73,7 +73,7 @@ pub fn find_rand_n<M, T, I, F>(n: uint,
let mut keys = (0..n).map(|_| rng.gen::<uint>() % n)
.collect::<Vec<_>>();

for k in keys.iter() {
for k in &keys {
insert(map, *k);
}

Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/binary_heap.rs
Expand Up @@ -696,7 +696,7 @@ mod tests {
let iterout = [9, 5, 3];
let heap = BinaryHeap::from_vec(data);
let mut i = 0;
for el in heap.iter() {
for el in &heap {
assert_eq!(*el, iterout[i]);
i += 1;
}
Expand Down Expand Up @@ -884,7 +884,7 @@ mod tests {

let mut q: BinaryHeap<uint> = xs.iter().rev().map(|&x| x).collect();

for &x in xs.iter() {
for &x in &xs {
assert_eq!(q.pop().unwrap(), x);
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/libcollections/bit.rs
Expand Up @@ -976,7 +976,7 @@ impl Ord for Bitv {
#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Debug for Bitv {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
for bit in self.iter() {
for bit in self {
try!(write!(fmt, "{}", if bit { 1u32 } else { 0u32 }));
}
Ok(())
Expand Down Expand Up @@ -1743,7 +1743,7 @@ impl fmt::Debug for BitvSet {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
try!(write!(fmt, "BitvSet {{"));
let mut first = true;
for n in self.iter() {
for n in self {
if !first {
try!(write!(fmt, ", "));
}
Expand All @@ -1756,7 +1756,7 @@ impl fmt::Debug for BitvSet {

impl<S: hash::Writer + hash::Hasher> hash::Hash<S> for BitvSet {
fn hash(&self, state: &mut S) {
for pos in self.iter() {
for pos in self {
pos.hash(state);
}
}
Expand Down Expand Up @@ -2600,7 +2600,7 @@ mod bitv_bench {
b.iter(|| {
let mut sum = 0u;
for _ in 0u..10 {
for pres in bitv.iter() {
for pres in &bitv {
sum += pres as uint;
}
}
Expand All @@ -2613,7 +2613,7 @@ mod bitv_bench {
let bitv = Bitv::from_elem(BENCH_BITS, false);
b.iter(|| {
let mut sum = 0u;
for pres in bitv.iter() {
for pres in &bitv {
sum += pres as uint;
}
sum
Expand Down Expand Up @@ -2674,8 +2674,8 @@ mod bitv_set_test {
fn test_bitv_set_frombitv_init() {
let bools = [true, false];
let lengths = [10, 64, 100];
for &b in bools.iter() {
for &l in lengths.iter() {
for &b in &bools {
for &l in &lengths {
let bitset = BitvSet::from_bitv(Bitv::from_elem(l, b));
assert_eq!(bitset.contains(&1u), b);
assert_eq!(bitset.contains(&(l-1u)), b);
Expand Down Expand Up @@ -3062,7 +3062,7 @@ mod bitv_set_bench {
|idx| {idx % 3 == 0}));
b.iter(|| {
let mut sum = 0u;
for idx in bitv.iter() {
for idx in &bitv {
sum += idx as uint;
}
sum
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/btree/map.rs
Expand Up @@ -856,7 +856,7 @@ impl<K: Ord, V> Extend<(K, V)> for BTreeMap<K, V> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<S: Hasher, K: Hash<S>, V: Hash<S>> Hash<S> for BTreeMap<K, V> {
fn hash(&self, state: &mut S) {
for elt in self.iter() {
for elt in self {
elt.hash(state);
}
}
Expand Down Expand Up @@ -1946,7 +1946,7 @@ mod bench {
}

b.iter(|| {
for entry in map.iter() {
for entry in &map {
black_box(entry);
}
});
Expand Down
6 changes: 3 additions & 3 deletions src/libcollections/btree/node.rs
Expand Up @@ -435,13 +435,13 @@ impl<K: Clone, V: Clone> Clone for Node<K, V> {
let mut vals = RawItems::from_parts(ret.vals().as_ptr(), 0);
let mut edges = RawItems::from_parts(ret.edges().as_ptr(), 0);

for key in self.keys().iter() {
for key in self.keys() {
keys.push(key.clone())
}
for val in self.vals().iter() {
for val in self.vals() {
vals.push(val.clone())
}
for edge in self.edges().iter() {
for edge in self.edges() {
edges.push(edge.clone())
}

Expand Down
6 changes: 3 additions & 3 deletions src/libcollections/btree/set.rs
Expand Up @@ -791,8 +791,8 @@ mod test {
let mut set_a = BTreeSet::new();
let mut set_b = BTreeSet::new();

for x in a.iter() { assert!(set_a.insert(*x)) }
for y in b.iter() { assert!(set_b.insert(*y)) }
for x in a { assert!(set_a.insert(*x)) }
for y in b { assert!(set_b.insert(*y)) }

let mut i = 0;
f(&set_a, &set_b, Counter { i: &mut i, expected: expected });
Expand Down Expand Up @@ -894,7 +894,7 @@ mod test {

let set: BTreeSet<int> = xs.iter().map(|&x| x).collect();

for x in xs.iter() {
for x in &xs {
assert!(set.contains(x));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/dlist.rs
Expand Up @@ -917,7 +917,7 @@ impl<A: fmt::Debug> fmt::Debug for DList<A> {
impl<S: Writer + Hasher, A: Hash<S>> Hash<S> for DList<A> {
fn hash(&self, state: &mut S) {
self.len().hash(state);
for elt in self.iter() {
for elt in self {
elt.hash(state);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/enum_set.rs
Expand Up @@ -36,7 +36,7 @@ impl<E:CLike + fmt::Debug> fmt::Debug for EnumSet<E> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
try!(write!(fmt, "EnumSet {{"));
let mut first = true;
for e in self.iter() {
for e in self {
if !first {
try!(write!(fmt, ", "));
}
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/ring_buf.rs
Expand Up @@ -1573,7 +1573,7 @@ impl<A: Ord> Ord for RingBuf<A> {
impl<S: Writer + Hasher, A: Hash<S>> Hash<S> for RingBuf<A> {
fn hash(&self, state: &mut S) {
self.len().hash(state);
for elt in self.iter() {
for elt in self {
elt.hash(state);
}
}
Expand Down Expand Up @@ -1856,7 +1856,7 @@ mod tests {

b.iter(|| {
let mut sum = 0;
for &i in ring.iter() {
for &i in &ring {
sum += i;
}
test::black_box(sum);
Expand Down
12 changes: 6 additions & 6 deletions src/libcollections/slice.rs
Expand Up @@ -1118,7 +1118,7 @@ impl<T: Clone, V: AsSlice<T>> SliceConcatExt<T, Vec<T>> for [V] {
fn concat(&self) -> Vec<T> {
let size = self.iter().fold(0u, |acc, v| acc + v.as_slice().len());
let mut result = Vec::with_capacity(size);
for v in self.iter() {
for v in self {
result.push_all(v.as_slice())
}
result
Expand All @@ -1128,7 +1128,7 @@ impl<T: Clone, V: AsSlice<T>> SliceConcatExt<T, Vec<T>> for [V] {
let size = self.iter().fold(0u, |acc, v| acc + v.as_slice().len());
let mut result = Vec::with_capacity(size + self.len());
let mut first = true;
for v in self.iter() {
for v in self {
if first { first = false } else { result.push(sep.clone()) }
result.push_all(v.as_slice())
}
Expand Down Expand Up @@ -2681,13 +2681,13 @@ mod tests {
assert_eq!(v.len(), 3);
let mut cnt = 0u;

for f in v.iter() {
for f in &v {
assert!(*f == Foo);
cnt += 1;
}
assert_eq!(cnt, 3);

for f in v[1..3].iter() {
for f in &v[1..3] {
assert!(*f == Foo);
cnt += 1;
}
Expand All @@ -2707,7 +2707,7 @@ mod tests {

let xs: [Foo; 3] = [Foo, Foo, Foo];
cnt = 0;
for f in xs.iter() {
for f in &xs {
assert!(*f == Foo);
cnt += 1;
}
Expand Down Expand Up @@ -2858,7 +2858,7 @@ mod bench {

b.iter(|| {
let mut sum = 0;
for x in v.iter() {
for x in &v {
sum += *x;
}
// sum == 11806, to stop dead code elimination.
Expand Down

0 comments on commit d5d7e65

Please sign in to comment.