Skip to content

Commit

Permalink
s/while let/for/g now that rust-lang#21245 has been fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Aparicio committed Jan 30, 2015
1 parent c013a01 commit 2d76c94
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 54 deletions.
4 changes: 1 addition & 3 deletions src/libcollections/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ type MatchWords<'a> = Chain<Enumerate<Blocks<'a>>, Skip<Take<Enumerate<Repeat<u3

fn reverse_bits(byte: u8) -> u8 {
let mut result = 0;
// FIXME(#21245) use a for loop
let mut iter = 0..u8::BITS;
while let Some(i) = iter.next() {
for i in 0..u8::BITS {
result |= ((byte >> i) & 1) << (u8::BITS - 1 - i);
}
result
Expand Down
8 changes: 2 additions & 6 deletions src/libcollections/ring_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1793,9 +1793,7 @@ mod tests {
fn bench_push_back_100(b: &mut test::Bencher) {
let mut deq = RingBuf::with_capacity(101);
b.iter(|| {
// FIXME(#21245) use a for loop
let mut iter = 0i..100;
while let Some(i) = iter.next() {
for i in 0i..100 {
deq.push_back(i);
}
deq.head = 0;
Expand All @@ -1807,9 +1805,7 @@ mod tests {
fn bench_push_front_100(b: &mut test::Bencher) {
let mut deq = RingBuf::with_capacity(101);
b.iter(|| {
// FIXME(#21245) use a for loop
let mut iter = 0i..100;
while let Some(i) = iter.next() {
for i in 0i..100 {
deq.push_front(i);
}
deq.head = 0;
Expand Down
4 changes: 1 addition & 3 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1567,9 +1567,7 @@ impl<T> Drop for Vec<T> {
// zeroed (when moving out, because of #[unsafe_no_drop_flag]).
if self.cap != 0 {
unsafe {
// FIXME(#21245) use a for loop
let mut iter = self.iter();
while let Some(x) = iter.next() {
for x in self.iter() {
ptr::read(x);
}
dealloc(*self.ptr, self.cap)
Expand Down
4 changes: 1 addition & 3 deletions src/librustc/middle/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,7 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
for (word_index, &word) in words.iter().enumerate() {
if word != 0 {
let base_index = word_index * uint::BITS;
// FIXME(#21245) use a for loop
let mut iter = 0u..uint::BITS;
while let Some(offset) = iter.next() {
for offset in 0u..uint::BITS {
let bit = 1 << offset;
if (word & bit) != 0 {
// NB: we round up the total number of bits
Expand Down
4 changes: 1 addition & 3 deletions src/libserialize/collection_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ impl<
fn decode<D: Decoder>(d: &mut D) -> Result<EnumSet<T>, D::Error> {
let bits = try!(d.read_uint());
let mut set = EnumSet::new();
// FIXME(#21245) use a for loop
let mut iter = 0..uint::BITS;
while let Some(bit) = iter.next() {
for bit in 0..uint::BITS {
if bits & (1 << bit) != 0 {
set.insert(CLike::from_uint(1 << bit));
}
Expand Down
5 changes: 1 addition & 4 deletions src/libstd/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,7 @@ pub fn escape_default<F>(c: u8, mut f: F) where
_ => {
f(b'\\');
f(b'x');
// FIXME(#21245) use a for loop
let arr = [4u, 0u];
let mut iter = arr.iter();
while let ::option::Option::Some(&offset) = ::iter::Iterator::next(&mut iter) {
for &offset in [4u, 0u].iter() {
match ((c as i32) >> offset) & 0xf {
i @ 0 ... 9 => f(b'0' + (i as u8)),
i => f(b'a' + (i as u8 - 10)),
Expand Down
4 changes: 1 addition & 3 deletions src/libstd/rand/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,7 @@ mod test {
}

// start all the tasks
// FIXME(#21245) use a for loop
let mut iter = txs.iter();
while let Some(tx) = iter.next() {
for tx in txs.iter() {
tx.send(()).unwrap();
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/libstd/sync/mpsc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1476,9 +1476,7 @@ mod test {

let _t = Thread::spawn(move|| {
let mut count = 0;
// FIXME(#21245) use a for loop
let mut iter = rx.iter();
while let Some(x) = iter.next() {
for x in rx.iter() {
if count >= 3 {
break;
} else {
Expand Down Expand Up @@ -1942,9 +1940,7 @@ mod sync_tests {

let _t = Thread::spawn(move|| {
let mut count = 0;
// FIXME(#21245) use a for loop
let mut iter = rx.iter();
while let Some(x) = iter.next() {
for x in rx.iter() {
if count >= 3 {
break;
} else {
Expand Down
4 changes: 1 addition & 3 deletions src/libstd/sync/mpsc/mpsc_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,7 @@ mod tests {
let tx = tx.clone();
let q = q.clone();
Thread::spawn(move|| {
// FIXME(#21245) use a for loop
let mut iter = 0..nmsgs;
while let Some(i) = iter.next() {
for i in 0..nmsgs {
q.push(i);
}
tx.send(()).unwrap();
Expand Down
12 changes: 4 additions & 8 deletions src/libsyntax/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,10 @@ pub trait MoveMap<T> {

impl<T> MoveMap<T> for Vec<T> {
fn move_map<F>(mut self, mut f: F) -> Vec<T> where F: FnMut(T) -> T {
// FIXME(#21245) use a for loop
{
let mut iter = self.iter_mut();
while let Some(p) = iter.next() {
unsafe {
// FIXME(#5016) this shouldn't need to zero to be safe.
ptr::write(p, f(ptr::read_and_zero(p)));
}
for p in self.iter_mut() {
unsafe {
// FIXME(#5016) this shouldn't need to zero to be safe.
ptr::write(p, f(ptr::read_and_zero(p)));
}
}
self
Expand Down
8 changes: 2 additions & 6 deletions src/test/bench/shootout-mandelbrot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ fn mandelbrot<W: old_io::Writer>(w: uint, mut out: W) -> old_io::IoResult<()> {
(i + 1) * chunk_size
};

// FIXME(#21245) use a for loop
let mut iter = vec_init_i[start..end].iter();
while let Some(&init_i) = iter.next() {
for &init_i in vec_init_i[start..end].iter() {
write_line(init_i, init_r_slice, &mut res);
}

Expand All @@ -144,9 +142,7 @@ fn mandelbrot<W: old_io::Writer>(w: uint, mut out: W) -> old_io::IoResult<()> {
}).collect::<Vec<_>>();

try!(writeln!(&mut out as &mut Writer, "P4\n{} {}", w, h));
// FIXME(#21245) use a for loop
let mut iter = data.into_iter();
while let Some(res) = iter.next() {
for res in data.into_iter() {
try!(out.write(res.join().ok().unwrap().as_slice()));
}
out.flush()
Expand Down
8 changes: 2 additions & 6 deletions src/test/bench/shootout-meteor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ fn make_masks() -> Vec<Vec<Vec<u64> > > {
// all unused piece can be placed on the board.
fn is_board_unfeasible(board: u64, masks: &Vec<Vec<Vec<u64>>>) -> bool {
let mut coverable = board;
// FIXME(#21245) use a for loop
let mut iter = masks.iter().enumerate();
while let Some((i, masks_at)) = iter.next() {
for (i, masks_at) in masks.iter().enumerate() {
if board & 1 << i != 0 { continue; }
for (cur_id, pos_masks) in masks_at.iter().enumerate() {
if board & 1 << (50 + cur_id) != 0 { continue; }
Expand Down Expand Up @@ -224,9 +222,7 @@ fn to_vec(raw_sol: &List<u64>) -> Vec<u8> {
let mut sol = repeat('.' as u8).take(50).collect::<Vec<_>>();
for &m in raw_sol.iter() {
let id = '0' as u8 + get_id(m);
// FIXME(#21245) use a for loop
let mut iter = 0u..50;
while let Some(i) = iter.next() {
for i in 0u..50 {
if m & 1 << i != 0 {
sol[i] = id;
}
Expand Down

0 comments on commit 2d76c94

Please sign in to comment.