From d5f61b4332f3edd83c43f3f0d52d0381d7a6c37a Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 31 Jan 2015 20:02:00 -0500 Subject: [PATCH] `for x in xs.iter_mut()` -> `for x in &mut xs` Also `for x in option.iter_mut()` -> `if let Some(ref mut x) = option` --- src/libcollections/bit.rs | 6 +++--- src/libcollections/ring_buf.rs | 2 +- src/libcollections/slice.rs | 18 +++++++++--------- src/libcollections/vec.rs | 10 +++++----- src/libcollections/vec_map.rs | 2 +- src/libcore/iter.rs | 4 ++-- src/librand/chacha.rs | 2 +- src/librand/distributions/mod.rs | 2 +- src/librand/lib.rs | 2 +- src/librustc/lint/context.rs | 2 +- src/librustc/middle/dataflow.rs | 2 +- src/librustc/middle/infer/error_reporting.rs | 2 +- .../borrowck/gather_loans/move_error.rs | 2 +- src/librustc_trans/trans/cabi_x86_64.rs | 2 +- src/librustc_trans/trans/debuginfo.rs | 2 +- src/librustc_typeck/astconv.rs | 2 +- src/librustc_typeck/check/mod.rs | 2 +- src/librustc_typeck/rscope.rs | 2 +- src/librustdoc/clean/mod.rs | 2 +- src/librustdoc/html/render.rs | 2 +- src/libstd/ascii.rs | 4 ++-- src/libstd/old_io/net/ip.rs | 2 +- src/libstd/old_io/util.rs | 4 ++-- src/libsyntax/ext/tt/macro_parser.rs | 2 +- src/libsyntax/fold.rs | 4 ++-- src/libtest/lib.rs | 4 ++-- src/libtest/stats.rs | 2 +- src/test/bench/msgsend-ring-mutex-arcs.rs | 2 +- src/test/bench/noise.rs | 2 +- src/test/bench/shootout-meteor.rs | 4 ++-- src/test/bench/shootout-nbody.rs | 2 +- src/test/compile-fail/vec-mut-iter-borrow.rs | 2 +- src/test/run-pass/const-vec-of-fns.rs | 2 +- ...bility-inherits-through-fixed-length-vec.rs | 2 +- 34 files changed, 54 insertions(+), 54 deletions(-) diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index 3d16dd4b166..da00b25bbbc 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -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(); } @@ -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(); } @@ -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; } } } diff --git a/src/libcollections/ring_buf.rs b/src/libcollections/ring_buf.rs index 4b9f3980db2..b7d16b864fd 100644 --- a/src/libcollections/ring_buf.rs +++ b/src/libcollections/ring_buf.rs @@ -1869,7 +1869,7 @@ mod tests { b.iter(|| { let mut sum = 0; - for i in ring.iter_mut() { + for i in &mut ring { sum += *i; } test::black_box(sum); diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 9be918dbe15..3830ab9ee7b 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -1228,7 +1228,7 @@ impl Iterator for ElementSwaps { self.sdir.swap(i, j); // Swap the direction of each larger SizeDirection - for x in self.sdir.iter_mut() { + for x in &mut self.sdir { if x.size > sd.size { x.dir = match x.dir { Pos => Neg, Neg => Pos }; } @@ -2356,7 +2356,7 @@ mod tests { #[test] fn test_mut_iterator() { let mut xs = [1, 2, 3, 4, 5]; - for x in xs.iter_mut() { + for x in &mut xs { *x += 1; } assert!(xs == [2, 3, 4, 5, 6]) @@ -2656,7 +2656,7 @@ mod tests { let left: &[_] = left; assert!(left[..left.len()] == [1, 2][]); } - for p in left.iter_mut() { + for p in left { *p += 1; } @@ -2664,7 +2664,7 @@ mod tests { let right: &[_] = right; assert!(right[..right.len()] == [3, 4, 5][]); } - for p in right.iter_mut() { + for p in right { *p += 2; } } @@ -2693,7 +2693,7 @@ mod tests { } assert_eq!(cnt, 5); - for f in v.iter_mut() { + for f in &mut v { assert!(*f == Foo); cnt += 1; } @@ -2796,7 +2796,7 @@ mod tests { let mut v = [0u8, 1, 2, 3, 4, 5, 6]; assert_eq!(v.chunks_mut(2).len(), 4); for (i, chunk) in v.chunks_mut(3).enumerate() { - for x in chunk.iter_mut() { + for x in chunk { *x = i as u8; } } @@ -2808,7 +2808,7 @@ mod tests { fn test_mut_chunks_rev() { let mut v = [0u8, 1, 2, 3, 4, 5, 6]; for (i, chunk) in v.chunks_mut(3).rev().enumerate() { - for x in chunk.iter_mut() { + for x in chunk { *x = i as u8; } } @@ -2872,7 +2872,7 @@ mod bench { b.iter(|| { let mut i = 0; - for x in v.iter_mut() { + for x in &mut v { *x = i; i += 1; } @@ -3006,7 +3006,7 @@ mod bench { unsafe { v.set_len(1024); } - for x in v.iter_mut() { + for x in &mut v { *x = 0; } v diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index e570d401609..acf4b480dfb 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -2022,7 +2022,7 @@ mod tests { { let slice = &mut values[2 ..]; assert!(slice == [3, 4, 5]); - for p in slice.iter_mut() { + for p in slice { *p += 2; } } @@ -2036,7 +2036,7 @@ mod tests { { let slice = &mut values[.. 2]; assert!(slice == [1, 2]); - for p in slice.iter_mut() { + for p in slice { *p += 1; } } @@ -2053,7 +2053,7 @@ mod tests { let left: &[_] = left; assert!(&left[..left.len()] == &[1, 2][]); } - for p in left.iter_mut() { + for p in left { *p += 1; } @@ -2061,7 +2061,7 @@ mod tests { let right: &[_] = right; assert!(&right[..right.len()] == &[3, 4, 5][]); } - for p in right.iter_mut() { + for p in right { *p += 2; } } @@ -2137,7 +2137,7 @@ mod tests { v.push(()); assert_eq!(v.iter_mut().count(), 4); - for &mut () in v.iter_mut() {} + for &mut () in &mut v {} unsafe { v.set_len(0); } assert_eq!(v.iter_mut().count(), 0); } diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index 1adea45f630..b07e172079e 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -924,7 +924,7 @@ mod test_map { assert!(m.insert(6, 10).is_none()); assert!(m.insert(10, 11).is_none()); - for (k, v) in m.iter_mut() { + for (k, v) in &mut m { *v += k as int; } diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index c782452d4cf..b6b6c52d568 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -2205,7 +2205,7 @@ impl Iterator for FlatMap where #[inline] fn next(&mut self) -> Option { loop { - for inner in self.frontiter.iter_mut() { + if let Some(ref mut inner) = self.frontiter { for x in inner.by_ref() { return Some(x) } @@ -2238,7 +2238,7 @@ impl DoubleEndedIterator for FlatMap where #[inline] fn next_back(&mut self) -> Option { loop { - for inner in self.backiter.iter_mut() { + if let Some(ref mut inner) = self.backiter { match inner.next_back() { None => (), y => return y diff --git a/src/librand/chacha.rs b/src/librand/chacha.rs index 6bd971e7b5d..aef6301dad7 100644 --- a/src/librand/chacha.rs +++ b/src/librand/chacha.rs @@ -194,7 +194,7 @@ impl<'a> SeedableRng<&'a [u32]> for ChaChaRng { impl Rand for ChaChaRng { fn rand(other: &mut R) -> ChaChaRng { let mut key : [u32; KEY_WORDS] = [0; KEY_WORDS]; - for word in key.iter_mut() { + for word in &mut key { *word = other.gen(); } SeedableRng::from_seed(key.as_slice()) diff --git a/src/librand/distributions/mod.rs b/src/librand/distributions/mod.rs index fb543e3d549..4958784f614 100644 --- a/src/librand/distributions/mod.rs +++ b/src/librand/distributions/mod.rs @@ -123,7 +123,7 @@ impl<'a, T: Clone> WeightedChoice<'a, T> { // we convert the list from individual weights to cumulative // weights so we can binary search. This *could* drop elements // with weight == 0 as an optimisation. - for item in items.iter_mut() { + for item in &mut *items { running_total = match running_total.checked_add(item.weight) { Some(n) => n, None => panic!("WeightedChoice::new called with a total weight \ diff --git a/src/librand/lib.rs b/src/librand/lib.rs index 3ff40038872..5290e680333 100644 --- a/src/librand/lib.rs +++ b/src/librand/lib.rs @@ -154,7 +154,7 @@ pub trait Rng : Sized { // optimisations are on. let mut count = 0; let mut num = 0; - for byte in dest.iter_mut() { + for byte in dest { if count == 0 { // we could micro-optimise here by generating a u32 if // we only need a few more bytes to fill the vector diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 4ed61c6ffa1..2bc29e61d0d 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -329,7 +329,7 @@ macro_rules! run_lints { ($cx:expr, $f:ident, $($args:expr),*) => ({ // Move the vector of passes out of `$cx` so that we can // iterate over it mutably while passing `$cx` to the methods. let mut passes = $cx.lints.passes.take().unwrap(); - for obj in passes.iter_mut() { + for obj in &mut passes { obj.$f($cx, $($args),*); } $cx.lints.passes = Some(passes); diff --git a/src/librustc/middle/dataflow.rs b/src/librustc/middle/dataflow.rs index a06a57beb61..8f5906db589 100644 --- a/src/librustc/middle/dataflow.rs +++ b/src/librustc/middle/dataflow.rs @@ -501,7 +501,7 @@ impl<'a, 'b, 'tcx, O:DataFlowOperator> PropagationContext<'a, 'b, 'tcx, O> { fn reset(&mut self, bits: &mut [uint]) { let e = if self.dfcx.oper.initial_value() {uint::MAX} else {0}; - for b in bits.iter_mut() { + for b in bits { *b = e; } } diff --git a/src/librustc/middle/infer/error_reporting.rs b/src/librustc/middle/infer/error_reporting.rs index 2efc07a4023..17b62e463da 100644 --- a/src/librustc/middle/infer/error_reporting.rs +++ b/src/librustc/middle/infer/error_reporting.rs @@ -335,7 +335,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> { same_frs: &FreeRegionsFromSameFn) { let scope_id = same_frs.scope_id; let (sub_fr, sup_fr) = (same_frs.sub_fr, same_frs.sup_fr); - for sr in same_regions.iter_mut() { + for sr in &mut *same_regions { if sr.contains(&sup_fr.bound_region) && scope_id == sr.scope_id { sr.push(sub_fr.bound_region); diff --git a/src/librustc_borrowck/borrowck/gather_loans/move_error.rs b/src/librustc_borrowck/borrowck/gather_loans/move_error.rs index 2cd25de431e..d9e86bd4b6d 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/move_error.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/move_error.rs @@ -95,7 +95,7 @@ fn group_errors_with_same_origin<'tcx>(errors: &Vec>) } else { Vec::new() }; - for ge in grouped_errors.iter_mut() { + for ge in &mut *grouped_errors { if move_from_id == ge.move_from.id && error.move_to.is_some() { debug!("appending move_to to list"); ge.move_to_places.extend(move_to.into_iter()); diff --git a/src/librustc_trans/trans/cabi_x86_64.rs b/src/librustc_trans/trans/cabi_x86_64.rs index 22318fb6c14..2484e74e193 100644 --- a/src/librustc_trans/trans/cabi_x86_64.rs +++ b/src/librustc_trans/trans/cabi_x86_64.rs @@ -151,7 +151,7 @@ fn classify_ty(ty: Type) -> Vec { } fn all_mem(cls: &mut [RegClass]) { - for elt in cls.iter_mut() { + for elt in cls { *elt = Memory; } } diff --git a/src/librustc_trans/trans/debuginfo.rs b/src/librustc_trans/trans/debuginfo.rs index 9032eaeae50..291a88d17c1 100644 --- a/src/librustc_trans/trans/debuginfo.rs +++ b/src/librustc_trans/trans/debuginfo.rs @@ -2050,7 +2050,7 @@ fn prepare_struct_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, // The `Ty` values returned by `ty::struct_fields` can still contain // `ty_projection` variants, so normalize those away. - for field in fields.iter_mut() { + for field in &mut fields { field.mt.ty = monomorphize::normalize_associated_type(cx.tcx(), &field.mt.ty); } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index d14945d1c9f..3bf34dfcd70 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -733,7 +733,7 @@ fn ast_type_binding_to_projection_predicate<'tcx>( // If converting for an object type, then remove the dummy-ty from `Self` now. // Yuckety yuck. if self_ty.is_none() { - for candidate in candidates.iter_mut() { + for candidate in &mut candidates { let mut dummy_substs = candidate.0.substs.clone(); assert!(dummy_substs.self_ty() == Some(dummy_self_ty)); dummy_substs.types.pop(SelfSpace); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index a704508e6fa..d80b8791c26 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1341,7 +1341,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// ! gets replaced with (), unconstrained ints with i32, and unconstrained floats with f64. pub fn default_type_parameters(&self) { use middle::ty::UnconstrainedNumeric::{UnconstrainedInt, UnconstrainedFloat, Neither}; - for (_, &mut ref ty) in self.inh.node_types.borrow_mut().iter_mut() { + for (_, &mut ref ty) in &mut *self.inh.node_types.borrow_mut() { let resolved = self.infcx().resolve_type_vars_if_possible(ty); if self.infcx().type_var_diverges(resolved) { demand::eqtype(self, codemap::DUMMY_SP, *ty, ty::mk_nil(self.tcx())); diff --git a/src/librustc_typeck/rscope.rs b/src/librustc_typeck/rscope.rs index 7aaf56336a8..ddb485d9776 100644 --- a/src/librustc_typeck/rscope.rs +++ b/src/librustc_typeck/rscope.rs @@ -165,7 +165,7 @@ impl<'r> RegionScope for ShiftedRscope<'r> { { match self.base_scope.anon_regions(span, count) { Ok(mut v) => { - for r in v.iter_mut() { + for r in &mut v { *r = ty_fold::shift_region(*r, 1); } Ok(v) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index b140e26e037..07679480bfb 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -166,7 +166,7 @@ impl<'a, 'tcx> Clean for visit_ast::RustdocVisitor<'a, 'tcx> { _ => unreachable!(), }; let mut tmp = Vec::new(); - for child in m.items.iter_mut() { + for child in &mut m.items { match child.inner { ModuleItem(..) => {} _ => continue, diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 20ba0bb9e90..80e72777f93 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1270,7 +1270,7 @@ impl Context { v.push(NameDoc(myname, Some(shorter_line(item.doc_value())))); } - for (_, items) in map.iter_mut() { + for (_, items) in &mut map { items.sort(); } return map; diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index d3094cc745e..274c669d8df 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -134,7 +134,7 @@ impl AsciiExt> for [u8] { impl OwnedAsciiExt for Vec { #[inline] fn into_ascii_uppercase(mut self) -> Vec { - for byte in self.iter_mut() { + for byte in &mut self { *byte = byte.to_ascii_uppercase(); } self @@ -142,7 +142,7 @@ impl OwnedAsciiExt for Vec { #[inline] fn into_ascii_lowercase(mut self) -> Vec { - for byte in self.iter_mut() { + for byte in &mut self { *byte = byte.to_ascii_lowercase(); } self diff --git a/src/libstd/old_io/net/ip.rs b/src/libstd/old_io/net/ip.rs index 565f9d83818..d85251795c8 100644 --- a/src/libstd/old_io/net/ip.rs +++ b/src/libstd/old_io/net/ip.rs @@ -125,7 +125,7 @@ impl<'a> Parser<'a> { // Return result of first successful parser fn read_or(&mut self, parsers: &mut [Box Option>]) -> Option { - for pf in parsers.iter_mut() { + for pf in parsers { match self.read_atomically(|p: &mut Parser| pf.call_mut((p,))) { Some(r) => return Some(r), None => {} diff --git a/src/libstd/old_io/util.rs b/src/libstd/old_io/util.rs index 9a55f32c372..f78e3ac1f14 100644 --- a/src/libstd/old_io/util.rs +++ b/src/libstd/old_io/util.rs @@ -144,7 +144,7 @@ impl MultiWriter where W: Writer { impl Writer for MultiWriter where W: Writer { #[inline] fn write_all(&mut self, buf: &[u8]) -> old_io::IoResult<()> { - for writer in self.writers.iter_mut() { + for writer in &mut self.writers { try!(writer.write_all(buf)); } Ok(()) @@ -152,7 +152,7 @@ impl Writer for MultiWriter where W: Writer { #[inline] fn flush(&mut self) -> old_io::IoResult<()> { - for writer in self.writers.iter_mut() { + for writer in &mut self.writers { try!(writer.flush()); } Ok(()) diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index ac4a149a3ed..0eec182e0fc 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -444,7 +444,7 @@ pub fn parse(sess: &ParseSess, if token_name_eq(&tok, &token::Eof) { if eof_eis.len() == 1us { let mut v = Vec::new(); - for dv in (&mut eof_eis[0]).matches.iter_mut() { + for dv in &mut (&mut eof_eis[0]).matches { v.push(dv.pop().unwrap()); } return Success(nameize(sess, ms, &v[])); diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index a1362f5382c..9012ec2114d 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -37,7 +37,7 @@ pub trait MoveMap { impl MoveMap for Vec { fn move_map(mut self, mut f: F) -> Vec where F: FnMut(T) -> T { - for p in self.iter_mut() { + for p in &mut self { unsafe { // FIXME(#5016) this shouldn't need to zero to be safe. ptr::write(p, f(ptr::read_and_zero(p))); @@ -1117,7 +1117,7 @@ pub fn noop_fold_crate(Crate {module, attrs, config, mut exported_mac }, vec![], span) }; - for def in exported_macros.iter_mut() { + for def in &mut exported_macros { def.id = folder.new_id(def.id); } diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index a985c049fec..63969e996d3 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -1060,7 +1060,7 @@ impl Bencher { let loop_run = Duration::span(|| { - for p in samples.iter_mut() { + for p in &mut *samples { self.bench_n(n, |x| f(x)); *p = self.ns_per_iter() as f64; }; @@ -1068,7 +1068,7 @@ impl Bencher { stats::winsorize(samples, 5.0); summ = Some(stats::Summary::new(samples)); - for p in samples.iter_mut() { + for p in &mut *samples { self.bench_n(5 * n, |x| f(x)); *p = self.ns_per_iter() as f64; }; diff --git a/src/libtest/stats.rs b/src/libtest/stats.rs index 54f06fd0662..0ce115a0c1f 100644 --- a/src/libtest/stats.rs +++ b/src/libtest/stats.rs @@ -321,7 +321,7 @@ pub fn winsorize(samples: &mut [T], pct: T) { let lo = percentile_of_sorted(tmp.as_slice(), pct); let hundred: T = FromPrimitive::from_uint(100).unwrap(); let hi = percentile_of_sorted(tmp.as_slice(), hundred-pct); - for samp in samples.iter_mut() { + for samp in samples { if *samp > hi { *samp = hi } else if *samp < lo { diff --git a/src/test/bench/msgsend-ring-mutex-arcs.rs b/src/test/bench/msgsend-ring-mutex-arcs.rs index c344084a4c0..5d17e3a460c 100644 --- a/src/test/bench/msgsend-ring-mutex-arcs.rs +++ b/src/test/bench/msgsend-ring-mutex-arcs.rs @@ -99,7 +99,7 @@ fn main() { thread_ring(0, msg_per_task, num_chan, num_port); // synchronize - for f in futures.iter_mut() { + for f in &mut futures { f.get() } }); diff --git a/src/test/bench/noise.rs b/src/test/bench/noise.rs index 664491eed7d..dc5b2f4596e 100644 --- a/src/test/bench/noise.rs +++ b/src/test/bench/noise.rs @@ -45,7 +45,7 @@ impl Noise2DContext { let mut rng = StdRng::new().unwrap(); let mut rgradients = [Vec2 { x: 0.0, y: 0.0 }; 256]; - for x in rgradients.iter_mut() { + for x in &mut rgradients[] { *x = random_gradient(&mut rng); } diff --git a/src/test/bench/shootout-meteor.rs b/src/test/bench/shootout-meteor.rs index 80a21402fe1..d061403d590 100644 --- a/src/test/bench/shootout-meteor.rs +++ b/src/test/bench/shootout-meteor.rs @@ -116,9 +116,9 @@ fn transform(piece: Vec<(i32, i32)> , all: bool) -> Vec> { }).collect(); // translating to (0, 0) as minimum coordinates. - for cur_piece in res.iter_mut() { + for cur_piece in &mut res { let (dy, dx) = *cur_piece.iter().min_by(|e| *e).unwrap(); - for &mut (ref mut y, ref mut x) in cur_piece.iter_mut() { + for &mut (ref mut y, ref mut x) in cur_piece { *y -= dy; *x -= dx; } } diff --git a/src/test/bench/shootout-nbody.rs b/src/test/bench/shootout-nbody.rs index ca43216c662..a8de1469456 100644 --- a/src/test/bench/shootout-nbody.rs +++ b/src/test/bench/shootout-nbody.rs @@ -109,7 +109,7 @@ fn advance(bodies: &mut [Planet;N_BODIES], dt: f64, steps: int) { Some(bi) => bi, None => break }; - for bj in b_slice.iter_mut() { + for bj in &mut *b_slice { let dx = bi.x - bj.x; let dy = bi.y - bj.y; let dz = bi.z - bj.z; diff --git a/src/test/compile-fail/vec-mut-iter-borrow.rs b/src/test/compile-fail/vec-mut-iter-borrow.rs index 7dcedc8ecad..023ef72c453 100644 --- a/src/test/compile-fail/vec-mut-iter-borrow.rs +++ b/src/test/compile-fail/vec-mut-iter-borrow.rs @@ -11,7 +11,7 @@ fn main() { let mut xs: Vec = vec!(); - for x in xs.iter_mut() { + for x in &mut xs { xs.push(1) //~ ERROR cannot borrow `xs` } } diff --git a/src/test/run-pass/const-vec-of-fns.rs b/src/test/run-pass/const-vec-of-fns.rs index 0914402256d..4b07b1d3b07 100644 --- a/src/test/run-pass/const-vec-of-fns.rs +++ b/src/test/run-pass/const-vec-of-fns.rs @@ -23,7 +23,7 @@ static mut closures: &'static mut [S] = &mut [S(f as fn()), S(f as fn())]; pub fn main() { unsafe { for &bare_fn in bare_fns { bare_fn() } - for closure in closures.iter_mut() { + for closure in &mut *closures { let S(ref mut closure) = *closure; (*closure)() } diff --git a/src/test/run-pass/mutability-inherits-through-fixed-length-vec.rs b/src/test/run-pass/mutability-inherits-through-fixed-length-vec.rs index 36a41896bcd..e074c3fb3d7 100644 --- a/src/test/run-pass/mutability-inherits-through-fixed-length-vec.rs +++ b/src/test/run-pass/mutability-inherits-through-fixed-length-vec.rs @@ -16,7 +16,7 @@ fn test1() { fn test2() { let mut ints = [0; 32]; - for i in ints.iter_mut() { *i += 22; } + for i in &mut ints { *i += 22; } for i in &ints { assert!(*i == 22); } }