Skip to content

Commit b3ad685

Browse files
committed
replace all remaining for with foreach or do
1 parent 2a7be1c commit b3ad685

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+767
-791
lines changed

src/compiletest/header.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub fn load_props(testfile: &Path) -> TestProps {
4141
let mut pp_exact = None;
4242
let mut debugger_cmds = ~[];
4343
let mut check_lines = ~[];
44-
for iter_header(testfile) |ln| {
44+
do iter_header(testfile) |ln| {
4545
match parse_error_pattern(ln) {
4646
Some(ep) => error_patterns.push(ep),
4747
None => ()
@@ -74,6 +74,8 @@ pub fn load_props(testfile: &Path) -> TestProps {
7474
Some(cl) => check_lines.push(cl),
7575
None => ()
7676
};
77+
78+
true
7779
};
7880
return TestProps {
7981
error_patterns: error_patterns,
@@ -87,17 +89,19 @@ pub fn load_props(testfile: &Path) -> TestProps {
8789
}
8890

8991
pub fn is_test_ignored(config: &config, testfile: &Path) -> bool {
90-
for iter_header(testfile) |ln| {
91-
if parse_name_directive(ln, "xfail-test") { return true; }
92-
if parse_name_directive(ln, xfail_target()) { return true; }
93-
if config.mode == common::mode_pretty &&
94-
parse_name_directive(ln, "xfail-pretty") { return true; }
95-
};
96-
return false;
97-
9892
fn xfail_target() -> ~str {
9993
~"xfail-" + os::SYSNAME
10094
}
95+
96+
let val = do iter_header(testfile) |ln| {
97+
if parse_name_directive(ln, "xfail-test") { false }
98+
else if parse_name_directive(ln, xfail_target()) { false }
99+
else if config.mode == common::mode_pretty &&
100+
parse_name_directive(ln, "xfail-pretty") { false }
101+
else { true }
102+
};
103+
104+
!val
101105
}
102106

103107
fn iter_header(testfile: &Path, it: &fn(~str) -> bool) -> bool {
@@ -109,7 +113,7 @@ fn iter_header(testfile: &Path, it: &fn(~str) -> bool) -> bool {
109113
// module or function. This doesn't seem to be an optimization
110114
// with a warm page cache. Maybe with a cold one.
111115
if ln.starts_with("fn") || ln.starts_with("mod") {
112-
return false;
116+
return true;
113117
} else { if !(it(ln)) { return false; } }
114118
}
115119
return true;

src/libextra/bitv.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,14 @@ impl BigBitv {
206206
#[inline]
207207
pub fn equals(&self, b: &BigBitv, nbits: uint) -> bool {
208208
let len = b.storage.len();
209-
for uint::iterate(0, len) |i| {
209+
do uint::iterate(0, len) |i| {
210210
let mask = big_mask(nbits, i);
211211
if mask & self.storage[i] != mask & b.storage[i] {
212-
return false;
212+
false
213+
} else {
214+
true
213215
}
214216
}
215-
return true;
216217
}
217218
}
218219

@@ -358,7 +359,7 @@ impl Bitv {
358359
pub fn clear(&mut self) {
359360
match self.rep {
360361
Small(ref mut b) => b.clear(),
361-
Big(ref mut s) => for s.each_storage() |w| { *w = 0u }
362+
Big(ref mut s) => { do s.each_storage() |w| { *w = 0u; true }; }
362363
}
363364
}
364365

@@ -367,15 +368,17 @@ impl Bitv {
367368
pub fn set_all(&mut self) {
368369
match self.rep {
369370
Small(ref mut b) => b.set_all(),
370-
Big(ref mut s) => for s.each_storage() |w| { *w = !0u } }
371+
Big(ref mut s) => { do s.each_storage() |w| { *w = !0u; true }; }
372+
}
371373
}
372374

373375
/// Invert all bits
374376
#[inline]
375377
pub fn negate(&mut self) {
376378
match self.rep {
377379
Small(ref mut b) => b.negate(),
378-
Big(ref mut s) => for s.each_storage() |w| { *w = !*w } }
380+
Big(ref mut s) => { do s.each_storage() |w| { *w = !*w; true }; }
381+
}
379382
}
380383

381384
/**
@@ -718,11 +721,11 @@ impl BitvSet {
718721
}
719722

720723
pub fn difference(&self, other: &BitvSet, f: &fn(&uint) -> bool) -> bool {
721-
for self.common_iter(other).advance |(i, w1, w2)| {
724+
foreach (i, w1, w2) in self.common_iter(other) {
722725
if !iterate_bits(i, w1 & !w2, |b| f(&b)) {
723-
return false;
726+
return false
724727
}
725-
}
728+
};
726729
/* everything we have that they don't also shows up */
727730
self.outlier_iter(other).advance(|(mine, i, w)|
728731
!mine || iterate_bits(i, w, |b| f(&b))
@@ -731,11 +734,11 @@ impl BitvSet {
731734

732735
pub fn symmetric_difference(&self, other: &BitvSet,
733736
f: &fn(&uint) -> bool) -> bool {
734-
for self.common_iter(other).advance |(i, w1, w2)| {
737+
foreach (i, w1, w2) in self.common_iter(other) {
735738
if !iterate_bits(i, w1 ^ w2, |b| f(&b)) {
736-
return false;
739+
return false
737740
}
738-
}
741+
};
739742
self.outlier_iter(other).advance(|(_, i, w)| iterate_bits(i, w, |b| f(&b)))
740743
}
741744

@@ -744,11 +747,11 @@ impl BitvSet {
744747
}
745748

746749
pub fn union(&self, other: &BitvSet, f: &fn(&uint) -> bool) -> bool {
747-
for self.common_iter(other).advance |(i, w1, w2)| {
750+
foreach (i, w1, w2) in self.common_iter(other) {
748751
if !iterate_bits(i, w1 | w2, |b| f(&b)) {
749-
return false;
752+
return false
750753
}
751-
}
754+
};
752755
self.outlier_iter(other).advance(|(_, i, w)| iterate_bits(i, w, |b| f(&b)))
753756
}
754757
}
@@ -758,12 +761,12 @@ impl cmp::Eq for BitvSet {
758761
if self.size != other.size {
759762
return false;
760763
}
761-
for self.common_iter(other).advance |(_, w1, w2)| {
764+
foreach (_, w1, w2) in self.common_iter(other) {
762765
if w1 != w2 {
763766
return false;
764767
}
765768
}
766-
for self.outlier_iter(other).advance |(_, _, w)| {
769+
foreach (_, _, w) in self.outlier_iter(other) {
767770
if w != 0 {
768771
return false;
769772
}
@@ -798,15 +801,15 @@ impl Set<uint> for BitvSet {
798801
}
799802

800803
fn is_subset(&self, other: &BitvSet) -> bool {
801-
for self.common_iter(other).advance |(_, w1, w2)| {
804+
foreach (_, w1, w2) in self.common_iter(other) {
802805
if w1 & w2 != w1 {
803806
return false;
804807
}
805808
}
806809
/* If anything is not ours, then everything is not ours so we're
807810
definitely a subset in that case. Otherwise if there's any stray
808811
ones that 'other' doesn't have, we're not a subset. */
809-
for self.outlier_iter(other).advance |(mine, _, w)| {
812+
foreach (mine, _, w) in self.outlier_iter(other) {
810813
if !mine {
811814
return true;
812815
} else if w != 0 {

src/libextra/crypto/sha2.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl Engine512State {
112112

113113
// Putting the message schedule inside the same loop as the round calculations allows for
114114
// the compiler to generate better code.
115-
for uint::range_step(0, 64, 8) |t| {
115+
do uint::range_step(0, 64, 8) |t| {
116116
schedule_round!(t + 16);
117117
schedule_round!(t + 17);
118118
schedule_round!(t + 18);
@@ -130,9 +130,10 @@ impl Engine512State {
130130
sha2_round!(d, e, f, g, h, a, b, c, K64, t + 5);
131131
sha2_round!(c, d, e, f, g, h, a, b, K64, t + 6);
132132
sha2_round!(b, c, d, e, f, g, h, a, K64, t + 7);
133-
}
133+
true
134+
};
134135

135-
for uint::range_step(64, 80, 8) |t| {
136+
do uint::range_step(64, 80, 8) |t| {
136137
sha2_round!(a, b, c, d, e, f, g, h, K64, t);
137138
sha2_round!(h, a, b, c, d, e, f, g, K64, t + 1);
138139
sha2_round!(g, h, a, b, c, d, e, f, K64, t + 2);
@@ -141,7 +142,8 @@ impl Engine512State {
141142
sha2_round!(d, e, f, g, h, a, b, c, K64, t + 5);
142143
sha2_round!(c, d, e, f, g, h, a, b, K64, t + 6);
143144
sha2_round!(b, c, d, e, f, g, h, a, K64, t + 7);
144-
}
145+
true
146+
};
145147

146148
self.H0 += a;
147149
self.H1 += b;
@@ -507,7 +509,7 @@ impl Engine256State {
507509

508510
// Putting the message schedule inside the same loop as the round calculations allows for
509511
// the compiler to generate better code.
510-
for uint::range_step(0, 48, 8) |t| {
512+
do uint::range_step(0, 48, 8) |t| {
511513
schedule_round!(t + 16);
512514
schedule_round!(t + 17);
513515
schedule_round!(t + 18);
@@ -525,9 +527,10 @@ impl Engine256State {
525527
sha2_round!(d, e, f, g, h, a, b, c, K32, t + 5);
526528
sha2_round!(c, d, e, f, g, h, a, b, K32, t + 6);
527529
sha2_round!(b, c, d, e, f, g, h, a, K32, t + 7);
528-
}
530+
true
531+
};
529532

530-
for uint::range_step(48, 64, 8) |t| {
533+
do uint::range_step(48, 64, 8) |t| {
531534
sha2_round!(a, b, c, d, e, f, g, h, K32, t);
532535
sha2_round!(h, a, b, c, d, e, f, g, K32, t + 1);
533536
sha2_round!(g, h, a, b, c, d, e, f, K32, t + 2);
@@ -536,7 +539,8 @@ impl Engine256State {
536539
sha2_round!(d, e, f, g, h, a, b, c, K32, t + 5);
537540
sha2_round!(c, d, e, f, g, h, a, b, K32, t + 6);
538541
sha2_round!(b, c, d, e, f, g, h, a, K32, t + 7);
539-
}
542+
true
543+
};
540544

541545
self.H0 += a;
542546
self.H1 += b;

src/libextra/fileinput.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,10 @@ mod test {
505505
}
506506

507507
let mut read_lines = ~[];
508-
for input_vec(filenames) |line| {
508+
do input_vec(filenames) |line| {
509509
read_lines.push(line.to_owned());
510-
}
510+
true
511+
};
511512
assert_eq!(read_lines, all_lines);
512513
}
513514

@@ -523,13 +524,14 @@ mod test {
523524
make_file(filename.get_ref(), contents);
524525
}
525526

526-
for input_vec_state(filenames) |line, state| {
527+
do input_vec_state(filenames) |line, state| {
527528
let nums: ~[&str] = line.split_iter(' ').collect();
528529
let file_num = uint::from_str(nums[0]).get();
529530
let line_num = uint::from_str(nums[1]).get();
530531
assert_eq!(line_num, state.line_num_file);
531532
assert_eq!(file_num * 3 + line_num, state.line_num);
532-
}
533+
true
534+
};
533535
}
534536

535537
#[test]
@@ -543,15 +545,16 @@ mod test {
543545
make_file(filenames[2].get_ref(), [~"3", ~"4"]);
544546
545547
let mut count = 0;
546-
for input_vec_state(filenames.clone()) |line, state| {
548+
do input_vec_state(filenames.clone()) |line, state| {
547549
let expected_path = match line {
548550
"1" | "2" => filenames[0].clone(),
549551
"3" | "4" => filenames[2].clone(),
550552
_ => fail!("unexpected line")
551553
};
552554
assert_eq!(state.current_path.clone(), expected_path);
553555
count += 1;
554-
}
556+
true
557+
};
555558
assert_eq!(count, 4);
556559
}
557560
@@ -570,9 +573,10 @@ mod test {
570573
wr.write_str("3\n4");
571574
572575
let mut lines = ~[];
573-
for input_vec(~[f1, f2]) |line| {
576+
do input_vec(~[f1, f2]) |line| {
574577
lines.push(line.to_owned());
575-
}
578+
true
579+
};
576580
assert_eq!(lines, ~[~"1", ~"2", ~"3", ~"4"]);
577581
}
578582
@@ -610,8 +614,9 @@ mod test {
610614
#[test]
611615
#[should_fail]
612616
fn test_input_vec_missing_file() {
613-
for input_vec(pathify([~"this/file/doesnt/exist"], true)) |line| {
617+
do input_vec(pathify([~"this/file/doesnt/exist"], true)) |line| {
614618
println(line);
615-
}
619+
true
620+
};
616621
}
617622
}

src/libextra/smallintmap.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,12 @@ impl<V> SmallIntMap<V> {
155155

156156
/// Visit all key-value pairs in reverse order
157157
pub fn each_reverse<'a>(&'a self, it: &fn(uint, &'a V) -> bool) -> bool {
158-
for uint::range_rev(self.v.len(), 0) |i| {
158+
do uint::range_rev(self.v.len(), 0) |i| {
159159
match self.v[i] {
160-
Some(ref elt) => if !it(i, elt) { return false; },
161-
None => ()
160+
Some(ref elt) => it(i, elt),
161+
None => true
162162
}
163163
}
164-
return true;
165164
}
166165

167166
pub fn get<'a>(&'a self, key: &uint) -> &'a V {

src/librustc/metadata/cstore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ struct crate_hash {
148148
pub fn get_dep_hashes(cstore: &CStore) -> ~[@str] {
149149
let mut result = ~[];
150150

151-
for cstore.extern_mod_crate_map.each_value |&cnum| {
151+
foreach (_, &cnum) in cstore.extern_mod_crate_map.iter() {
152152
let cdata = cstore::get_crate_data(cstore, cnum);
153153
let hash = decoder::get_crate_hash(cdata.data);
154154
let vers = decoder::get_crate_vers(cdata.data);

0 commit comments

Comments
 (0)