Skip to content

cleanup: use the for x in &xs form instead of for x in xs.iter() #21830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
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
8 changes: 4 additions & 4 deletions src/compiletest/procsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ pub fn run(lib_path: &str,
let mut cmd = Command::new(prog);
cmd.args(args);
add_target_env(&mut cmd, lib_path, aux_path);
for (key, val) in env.into_iter() {
for (key, val) in env {
cmd.env(key, val);
}

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 All @@ -72,13 +72,13 @@ pub fn run_background(lib_path: &str,
let mut cmd = Command::new(prog);
cmd.args(args);
add_target_env(&mut cmd, lib_path, aux_path);
for (key, val) in env.into_iter() {
for (key, val) in env {
cmd.env(key, val);
}

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
20 changes: 10 additions & 10 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
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 @@ -1503,14 +1503,14 @@ fn _arm_exec_compiled_test(config: &Config,

// run test via adb_run_wrapper
runargs.push("shell".to_string());
for (key, val) in env.into_iter() {
for (key, val) in env {
runargs.push(format!("{}={}", key, val));
}
runargs.push(format!("{}/adb_run_wrapper.sh", config.adb_test_dir));
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
6 changes: 3 additions & 3 deletions src/libcollections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ impl<'a, T> IntoIterator for &'a BinaryHeap<T> where T: Ord {

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Ord> Extend<T> for BinaryHeap<T> {
fn extend<Iter: Iterator<Item=T>>(&mut self, mut iter: Iter) {
fn extend<Iter: Iterator<Item=T>>(&mut self, iter: Iter) {
let (lower, _) = iter.size_hint();

self.reserve(lower);
Expand All @@ -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
28 changes: 14 additions & 14 deletions src/libcollections/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ impl Bitv {
/// ```
#[inline]
pub fn set_all(&mut self) {
for w in self.storage.iter_mut() { *w = !0u32; }
for w in &mut self.storage { *w = !0u32; }
self.fix_last_block();
}

Expand All @@ -451,7 +451,7 @@ impl Bitv {
/// ```
#[inline]
pub fn negate(&mut self) {
for w in self.storage.iter_mut() { *w = !*w; }
for w in &mut self.storage { *w = !*w; }
self.fix_last_block();
}

Expand Down Expand Up @@ -912,7 +912,7 @@ impl Bitv {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn clear(&mut self) {
for w in self.storage.iter_mut() { *w = 0u32; }
for w in &mut self.storage { *w = 0u32; }
}
}

Expand All @@ -934,7 +934,7 @@ impl FromIterator<bool> for Bitv {
#[stable(feature = "rust1", since = "1.0.0")]
impl Extend<bool> for Bitv {
#[inline]
fn extend<I: Iterator<Item=bool>>(&mut self, mut iterator: I) {
fn extend<I: Iterator<Item=bool>>(&mut self, iterator: I) {
let (min, _) = iterator.size_hint();
self.reserve(min);
for element in iterator {
Expand Down 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 @@ -1141,7 +1141,7 @@ impl FromIterator<uint> for BitvSet {
#[stable(feature = "rust1", since = "1.0.0")]
impl Extend<uint> for BitvSet {
#[inline]
fn extend<I: Iterator<Item=uint>>(&mut self, mut iterator: I) {
fn extend<I: Iterator<Item=uint>>(&mut self, iterator: I) {
for i in iterator {
self.insert(i);
}
Expand Down Expand Up @@ -1353,7 +1353,7 @@ impl BitvSet {
}

// virtually pad other with 0's for equal lengths
let mut other_words = {
let other_words = {
let (_, result) = match_words(self_bitv, other_bitv);
result
};
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
8 changes: 4 additions & 4 deletions src/libcollections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
pub fn clear(&mut self) {
let b = self.b;
// avoid recursive destructors by manually traversing the tree
for _ in mem::replace(self, BTreeMap::with_b(b)).into_iter() {};
for _ in mem::replace(self, BTreeMap::with_b(b)) {};
}

// Searching in a B-Tree is pretty straightforward.
Expand Down Expand Up @@ -846,7 +846,7 @@ impl<K: Ord, V> FromIterator<(K, V)> for BTreeMap<K, V> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<K: Ord, V> Extend<(K, V)> for BTreeMap<K, V> {
#[inline]
fn extend<T: Iterator<Item=(K, V)>>(&mut self, mut iter: T) {
fn extend<T: Iterator<Item=(K, V)>>(&mut self, iter: T) {
for (k, v) in iter {
self.insert(k, v);
}
Expand All @@ -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
Original file line number Diff line number Diff line change
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
8 changes: 4 additions & 4 deletions src/libcollections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ impl<'a, T> IntoIterator for &'a BTreeSet<T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Ord> Extend<T> for BTreeSet<T> {
#[inline]
fn extend<Iter: Iterator<Item=T>>(&mut self, mut iter: Iter) {
fn extend<Iter: Iterator<Item=T>>(&mut self, iter: Iter) {
for elem in iter {
self.insert(elem);
}
Expand Down 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
Loading