1
Fork 0

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`
This commit is contained in:
Jorge Aparicio 2015-01-31 20:02:00 -05:00
parent d5d7e6565a
commit d5f61b4332
34 changed files with 54 additions and 54 deletions

View file

@ -431,7 +431,7 @@ impl Bitv {
/// ``` /// ```
#[inline] #[inline]
pub fn set_all(&mut self) { 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(); self.fix_last_block();
} }
@ -451,7 +451,7 @@ impl Bitv {
/// ``` /// ```
#[inline] #[inline]
pub fn negate(&mut self) { 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(); self.fix_last_block();
} }
@ -912,7 +912,7 @@ impl Bitv {
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub fn clear(&mut self) { pub fn clear(&mut self) {
for w in self.storage.iter_mut() { *w = 0u32; } for w in &mut self.storage { *w = 0u32; }
} }
} }

View file

@ -1869,7 +1869,7 @@ mod tests {
b.iter(|| { b.iter(|| {
let mut sum = 0; let mut sum = 0;
for i in ring.iter_mut() { for i in &mut ring {
sum += *i; sum += *i;
} }
test::black_box(sum); test::black_box(sum);

View file

@ -1228,7 +1228,7 @@ impl Iterator for ElementSwaps {
self.sdir.swap(i, j); self.sdir.swap(i, j);
// Swap the direction of each larger SizeDirection // 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 { if x.size > sd.size {
x.dir = match x.dir { Pos => Neg, Neg => Pos }; x.dir = match x.dir { Pos => Neg, Neg => Pos };
} }
@ -2356,7 +2356,7 @@ mod tests {
#[test] #[test]
fn test_mut_iterator() { fn test_mut_iterator() {
let mut xs = [1, 2, 3, 4, 5]; let mut xs = [1, 2, 3, 4, 5];
for x in xs.iter_mut() { for x in &mut xs {
*x += 1; *x += 1;
} }
assert!(xs == [2, 3, 4, 5, 6]) assert!(xs == [2, 3, 4, 5, 6])
@ -2656,7 +2656,7 @@ mod tests {
let left: &[_] = left; let left: &[_] = left;
assert!(left[..left.len()] == [1, 2][]); assert!(left[..left.len()] == [1, 2][]);
} }
for p in left.iter_mut() { for p in left {
*p += 1; *p += 1;
} }
@ -2664,7 +2664,7 @@ mod tests {
let right: &[_] = right; let right: &[_] = right;
assert!(right[..right.len()] == [3, 4, 5][]); assert!(right[..right.len()] == [3, 4, 5][]);
} }
for p in right.iter_mut() { for p in right {
*p += 2; *p += 2;
} }
} }
@ -2693,7 +2693,7 @@ mod tests {
} }
assert_eq!(cnt, 5); assert_eq!(cnt, 5);
for f in v.iter_mut() { for f in &mut v {
assert!(*f == Foo); assert!(*f == Foo);
cnt += 1; cnt += 1;
} }
@ -2796,7 +2796,7 @@ mod tests {
let mut v = [0u8, 1, 2, 3, 4, 5, 6]; let mut v = [0u8, 1, 2, 3, 4, 5, 6];
assert_eq!(v.chunks_mut(2).len(), 4); assert_eq!(v.chunks_mut(2).len(), 4);
for (i, chunk) in v.chunks_mut(3).enumerate() { for (i, chunk) in v.chunks_mut(3).enumerate() {
for x in chunk.iter_mut() { for x in chunk {
*x = i as u8; *x = i as u8;
} }
} }
@ -2808,7 +2808,7 @@ mod tests {
fn test_mut_chunks_rev() { fn test_mut_chunks_rev() {
let mut v = [0u8, 1, 2, 3, 4, 5, 6]; let mut v = [0u8, 1, 2, 3, 4, 5, 6];
for (i, chunk) in v.chunks_mut(3).rev().enumerate() { for (i, chunk) in v.chunks_mut(3).rev().enumerate() {
for x in chunk.iter_mut() { for x in chunk {
*x = i as u8; *x = i as u8;
} }
} }
@ -2872,7 +2872,7 @@ mod bench {
b.iter(|| { b.iter(|| {
let mut i = 0; let mut i = 0;
for x in v.iter_mut() { for x in &mut v {
*x = i; *x = i;
i += 1; i += 1;
} }
@ -3006,7 +3006,7 @@ mod bench {
unsafe { unsafe {
v.set_len(1024); v.set_len(1024);
} }
for x in v.iter_mut() { for x in &mut v {
*x = 0; *x = 0;
} }
v v

View file

@ -2022,7 +2022,7 @@ mod tests {
{ {
let slice = &mut values[2 ..]; let slice = &mut values[2 ..];
assert!(slice == [3, 4, 5]); assert!(slice == [3, 4, 5]);
for p in slice.iter_mut() { for p in slice {
*p += 2; *p += 2;
} }
} }
@ -2036,7 +2036,7 @@ mod tests {
{ {
let slice = &mut values[.. 2]; let slice = &mut values[.. 2];
assert!(slice == [1, 2]); assert!(slice == [1, 2]);
for p in slice.iter_mut() { for p in slice {
*p += 1; *p += 1;
} }
} }
@ -2053,7 +2053,7 @@ mod tests {
let left: &[_] = left; let left: &[_] = left;
assert!(&left[..left.len()] == &[1, 2][]); assert!(&left[..left.len()] == &[1, 2][]);
} }
for p in left.iter_mut() { for p in left {
*p += 1; *p += 1;
} }
@ -2061,7 +2061,7 @@ mod tests {
let right: &[_] = right; let right: &[_] = right;
assert!(&right[..right.len()] == &[3, 4, 5][]); assert!(&right[..right.len()] == &[3, 4, 5][]);
} }
for p in right.iter_mut() { for p in right {
*p += 2; *p += 2;
} }
} }
@ -2137,7 +2137,7 @@ mod tests {
v.push(()); v.push(());
assert_eq!(v.iter_mut().count(), 4); assert_eq!(v.iter_mut().count(), 4);
for &mut () in v.iter_mut() {} for &mut () in &mut v {}
unsafe { v.set_len(0); } unsafe { v.set_len(0); }
assert_eq!(v.iter_mut().count(), 0); assert_eq!(v.iter_mut().count(), 0);
} }

View file

@ -924,7 +924,7 @@ mod test_map {
assert!(m.insert(6, 10).is_none()); assert!(m.insert(6, 10).is_none());
assert!(m.insert(10, 11).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; *v += k as int;
} }

View file

@ -2205,7 +2205,7 @@ impl<A, B, I, U, F> Iterator for FlatMap<A, B, I, U, F> where
#[inline] #[inline]
fn next(&mut self) -> Option<B> { fn next(&mut self) -> Option<B> {
loop { loop {
for inner in self.frontiter.iter_mut() { if let Some(ref mut inner) = self.frontiter {
for x in inner.by_ref() { for x in inner.by_ref() {
return Some(x) return Some(x)
} }
@ -2238,7 +2238,7 @@ impl<A, B, I, U, F> DoubleEndedIterator for FlatMap<A, B, I, U, F> where
#[inline] #[inline]
fn next_back(&mut self) -> Option<B> { fn next_back(&mut self) -> Option<B> {
loop { loop {
for inner in self.backiter.iter_mut() { if let Some(ref mut inner) = self.backiter {
match inner.next_back() { match inner.next_back() {
None => (), None => (),
y => return y y => return y

View file

@ -194,7 +194,7 @@ impl<'a> SeedableRng<&'a [u32]> for ChaChaRng {
impl Rand for ChaChaRng { impl Rand for ChaChaRng {
fn rand<R: Rng>(other: &mut R) -> ChaChaRng { fn rand<R: Rng>(other: &mut R) -> ChaChaRng {
let mut key : [u32; KEY_WORDS] = [0; KEY_WORDS]; let mut key : [u32; KEY_WORDS] = [0; KEY_WORDS];
for word in key.iter_mut() { for word in &mut key {
*word = other.gen(); *word = other.gen();
} }
SeedableRng::from_seed(key.as_slice()) SeedableRng::from_seed(key.as_slice())

View file

@ -123,7 +123,7 @@ impl<'a, T: Clone> WeightedChoice<'a, T> {
// we convert the list from individual weights to cumulative // we convert the list from individual weights to cumulative
// weights so we can binary search. This *could* drop elements // weights so we can binary search. This *could* drop elements
// with weight == 0 as an optimisation. // 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) { running_total = match running_total.checked_add(item.weight) {
Some(n) => n, Some(n) => n,
None => panic!("WeightedChoice::new called with a total weight \ None => panic!("WeightedChoice::new called with a total weight \

View file

@ -154,7 +154,7 @@ pub trait Rng : Sized {
// optimisations are on. // optimisations are on.
let mut count = 0; let mut count = 0;
let mut num = 0; let mut num = 0;
for byte in dest.iter_mut() { for byte in dest {
if count == 0 { if count == 0 {
// we could micro-optimise here by generating a u32 if // we could micro-optimise here by generating a u32 if
// we only need a few more bytes to fill the vector // we only need a few more bytes to fill the vector

View file

@ -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 // Move the vector of passes out of `$cx` so that we can
// iterate over it mutably while passing `$cx` to the methods. // iterate over it mutably while passing `$cx` to the methods.
let mut passes = $cx.lints.passes.take().unwrap(); let mut passes = $cx.lints.passes.take().unwrap();
for obj in passes.iter_mut() { for obj in &mut passes {
obj.$f($cx, $($args),*); obj.$f($cx, $($args),*);
} }
$cx.lints.passes = Some(passes); $cx.lints.passes = Some(passes);

View file

@ -501,7 +501,7 @@ impl<'a, 'b, 'tcx, O:DataFlowOperator> PropagationContext<'a, 'b, 'tcx, O> {
fn reset(&mut self, bits: &mut [uint]) { fn reset(&mut self, bits: &mut [uint]) {
let e = if self.dfcx.oper.initial_value() {uint::MAX} else {0}; let e = if self.dfcx.oper.initial_value() {uint::MAX} else {0};
for b in bits.iter_mut() { for b in bits {
*b = e; *b = e;
} }
} }

View file

@ -335,7 +335,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
same_frs: &FreeRegionsFromSameFn) { same_frs: &FreeRegionsFromSameFn) {
let scope_id = same_frs.scope_id; let scope_id = same_frs.scope_id;
let (sub_fr, sup_fr) = (same_frs.sub_fr, same_frs.sup_fr); 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) if sr.contains(&sup_fr.bound_region)
&& scope_id == sr.scope_id { && scope_id == sr.scope_id {
sr.push(sub_fr.bound_region); sr.push(sub_fr.bound_region);

View file

@ -95,7 +95,7 @@ fn group_errors_with_same_origin<'tcx>(errors: &Vec<MoveError<'tcx>>)
} else { } else {
Vec::new() 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() { if move_from_id == ge.move_from.id && error.move_to.is_some() {
debug!("appending move_to to list"); debug!("appending move_to to list");
ge.move_to_places.extend(move_to.into_iter()); ge.move_to_places.extend(move_to.into_iter());

View file

@ -151,7 +151,7 @@ fn classify_ty(ty: Type) -> Vec<RegClass> {
} }
fn all_mem(cls: &mut [RegClass]) { fn all_mem(cls: &mut [RegClass]) {
for elt in cls.iter_mut() { for elt in cls {
*elt = Memory; *elt = Memory;
} }
} }

View file

@ -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 // The `Ty` values returned by `ty::struct_fields` can still contain
// `ty_projection` variants, so normalize those away. // `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); field.mt.ty = monomorphize::normalize_associated_type(cx.tcx(), &field.mt.ty);
} }

View file

@ -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. // If converting for an object type, then remove the dummy-ty from `Self` now.
// Yuckety yuck. // Yuckety yuck.
if self_ty.is_none() { if self_ty.is_none() {
for candidate in candidates.iter_mut() { for candidate in &mut candidates {
let mut dummy_substs = candidate.0.substs.clone(); let mut dummy_substs = candidate.0.substs.clone();
assert!(dummy_substs.self_ty() == Some(dummy_self_ty)); assert!(dummy_substs.self_ty() == Some(dummy_self_ty));
dummy_substs.types.pop(SelfSpace); dummy_substs.types.pop(SelfSpace);

View file

@ -1341,7 +1341,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// ! gets replaced with (), unconstrained ints with i32, and unconstrained floats with f64. /// ! gets replaced with (), unconstrained ints with i32, and unconstrained floats with f64.
pub fn default_type_parameters(&self) { pub fn default_type_parameters(&self) {
use middle::ty::UnconstrainedNumeric::{UnconstrainedInt, UnconstrainedFloat, Neither}; 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); let resolved = self.infcx().resolve_type_vars_if_possible(ty);
if self.infcx().type_var_diverges(resolved) { if self.infcx().type_var_diverges(resolved) {
demand::eqtype(self, codemap::DUMMY_SP, *ty, ty::mk_nil(self.tcx())); demand::eqtype(self, codemap::DUMMY_SP, *ty, ty::mk_nil(self.tcx()));

View file

@ -165,7 +165,7 @@ impl<'r> RegionScope for ShiftedRscope<'r> {
{ {
match self.base_scope.anon_regions(span, count) { match self.base_scope.anon_regions(span, count) {
Ok(mut v) => { Ok(mut v) => {
for r in v.iter_mut() { for r in &mut v {
*r = ty_fold::shift_region(*r, 1); *r = ty_fold::shift_region(*r, 1);
} }
Ok(v) Ok(v)

View file

@ -166,7 +166,7 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
_ => unreachable!(), _ => unreachable!(),
}; };
let mut tmp = Vec::new(); let mut tmp = Vec::new();
for child in m.items.iter_mut() { for child in &mut m.items {
match child.inner { match child.inner {
ModuleItem(..) => {} ModuleItem(..) => {}
_ => continue, _ => continue,

View file

@ -1270,7 +1270,7 @@ impl Context {
v.push(NameDoc(myname, Some(shorter_line(item.doc_value())))); v.push(NameDoc(myname, Some(shorter_line(item.doc_value()))));
} }
for (_, items) in map.iter_mut() { for (_, items) in &mut map {
items.sort(); items.sort();
} }
return map; return map;

View file

@ -134,7 +134,7 @@ impl AsciiExt<Vec<u8>> for [u8] {
impl OwnedAsciiExt for Vec<u8> { impl OwnedAsciiExt for Vec<u8> {
#[inline] #[inline]
fn into_ascii_uppercase(mut self) -> Vec<u8> { fn into_ascii_uppercase(mut self) -> Vec<u8> {
for byte in self.iter_mut() { for byte in &mut self {
*byte = byte.to_ascii_uppercase(); *byte = byte.to_ascii_uppercase();
} }
self self
@ -142,7 +142,7 @@ impl OwnedAsciiExt for Vec<u8> {
#[inline] #[inline]
fn into_ascii_lowercase(mut self) -> Vec<u8> { fn into_ascii_lowercase(mut self) -> Vec<u8> {
for byte in self.iter_mut() { for byte in &mut self {
*byte = byte.to_ascii_lowercase(); *byte = byte.to_ascii_lowercase();
} }
self self

View file

@ -125,7 +125,7 @@ impl<'a> Parser<'a> {
// Return result of first successful parser // Return result of first successful parser
fn read_or<T>(&mut self, parsers: &mut [Box<FnMut(&mut Parser) -> Option<T>>]) fn read_or<T>(&mut self, parsers: &mut [Box<FnMut(&mut Parser) -> Option<T>>])
-> Option<T> { -> Option<T> {
for pf in parsers.iter_mut() { for pf in parsers {
match self.read_atomically(|p: &mut Parser| pf.call_mut((p,))) { match self.read_atomically(|p: &mut Parser| pf.call_mut((p,))) {
Some(r) => return Some(r), Some(r) => return Some(r),
None => {} None => {}

View file

@ -144,7 +144,7 @@ impl<W> MultiWriter<W> where W: Writer {
impl<W> Writer for MultiWriter<W> where W: Writer { impl<W> Writer for MultiWriter<W> where W: Writer {
#[inline] #[inline]
fn write_all(&mut self, buf: &[u8]) -> old_io::IoResult<()> { 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)); try!(writer.write_all(buf));
} }
Ok(()) Ok(())
@ -152,7 +152,7 @@ impl<W> Writer for MultiWriter<W> where W: Writer {
#[inline] #[inline]
fn flush(&mut self) -> old_io::IoResult<()> { fn flush(&mut self) -> old_io::IoResult<()> {
for writer in self.writers.iter_mut() { for writer in &mut self.writers {
try!(writer.flush()); try!(writer.flush());
} }
Ok(()) Ok(())

View file

@ -444,7 +444,7 @@ pub fn parse(sess: &ParseSess,
if token_name_eq(&tok, &token::Eof) { if token_name_eq(&tok, &token::Eof) {
if eof_eis.len() == 1us { if eof_eis.len() == 1us {
let mut v = Vec::new(); 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()); v.push(dv.pop().unwrap());
} }
return Success(nameize(sess, ms, &v[])); return Success(nameize(sess, ms, &v[]));

View file

@ -37,7 +37,7 @@ pub trait MoveMap<T> {
impl<T> MoveMap<T> for Vec<T> { impl<T> MoveMap<T> for Vec<T> {
fn move_map<F>(mut self, mut f: F) -> Vec<T> where F: FnMut(T) -> T { fn move_map<F>(mut self, mut f: F) -> Vec<T> where F: FnMut(T) -> T {
for p in self.iter_mut() { for p in &mut self {
unsafe { unsafe {
// FIXME(#5016) this shouldn't need to zero to be safe. // FIXME(#5016) this shouldn't need to zero to be safe.
ptr::write(p, f(ptr::read_and_zero(p))); ptr::write(p, f(ptr::read_and_zero(p)));
@ -1117,7 +1117,7 @@ pub fn noop_fold_crate<T: Folder>(Crate {module, attrs, config, mut exported_mac
}, vec![], span) }, vec![], span)
}; };
for def in exported_macros.iter_mut() { for def in &mut exported_macros {
def.id = folder.new_id(def.id); def.id = folder.new_id(def.id);
} }

View file

@ -1060,7 +1060,7 @@ impl Bencher {
let loop_run = Duration::span(|| { let loop_run = Duration::span(|| {
for p in samples.iter_mut() { for p in &mut *samples {
self.bench_n(n, |x| f(x)); self.bench_n(n, |x| f(x));
*p = self.ns_per_iter() as f64; *p = self.ns_per_iter() as f64;
}; };
@ -1068,7 +1068,7 @@ impl Bencher {
stats::winsorize(samples, 5.0); stats::winsorize(samples, 5.0);
summ = Some(stats::Summary::new(samples)); 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)); self.bench_n(5 * n, |x| f(x));
*p = self.ns_per_iter() as f64; *p = self.ns_per_iter() as f64;
}; };

View file

@ -321,7 +321,7 @@ pub fn winsorize<T: Float + FromPrimitive>(samples: &mut [T], pct: T) {
let lo = percentile_of_sorted(tmp.as_slice(), pct); let lo = percentile_of_sorted(tmp.as_slice(), pct);
let hundred: T = FromPrimitive::from_uint(100).unwrap(); let hundred: T = FromPrimitive::from_uint(100).unwrap();
let hi = percentile_of_sorted(tmp.as_slice(), hundred-pct); let hi = percentile_of_sorted(tmp.as_slice(), hundred-pct);
for samp in samples.iter_mut() { for samp in samples {
if *samp > hi { if *samp > hi {
*samp = hi *samp = hi
} else if *samp < lo { } else if *samp < lo {

View file

@ -99,7 +99,7 @@ fn main() {
thread_ring(0, msg_per_task, num_chan, num_port); thread_ring(0, msg_per_task, num_chan, num_port);
// synchronize // synchronize
for f in futures.iter_mut() { for f in &mut futures {
f.get() f.get()
} }
}); });

View file

@ -45,7 +45,7 @@ impl Noise2DContext {
let mut rng = StdRng::new().unwrap(); let mut rng = StdRng::new().unwrap();
let mut rgradients = [Vec2 { x: 0.0, y: 0.0 }; 256]; 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); *x = random_gradient(&mut rng);
} }

View file

@ -116,9 +116,9 @@ fn transform(piece: Vec<(i32, i32)> , all: bool) -> Vec<Vec<(i32, i32)>> {
}).collect(); }).collect();
// translating to (0, 0) as minimum coordinates. // 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(); 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; *y -= dy; *x -= dx;
} }
} }

View file

@ -109,7 +109,7 @@ fn advance(bodies: &mut [Planet;N_BODIES], dt: f64, steps: int) {
Some(bi) => bi, Some(bi) => bi,
None => break None => break
}; };
for bj in b_slice.iter_mut() { for bj in &mut *b_slice {
let dx = bi.x - bj.x; let dx = bi.x - bj.x;
let dy = bi.y - bj.y; let dy = bi.y - bj.y;
let dz = bi.z - bj.z; let dz = bi.z - bj.z;

View file

@ -11,7 +11,7 @@
fn main() { fn main() {
let mut xs: Vec<isize> = vec!(); let mut xs: Vec<isize> = vec!();
for x in xs.iter_mut() { for x in &mut xs {
xs.push(1) //~ ERROR cannot borrow `xs` xs.push(1) //~ ERROR cannot borrow `xs`
} }
} }

View file

@ -23,7 +23,7 @@ static mut closures: &'static mut [S<fn()>] = &mut [S(f as fn()), S(f as fn())];
pub fn main() { pub fn main() {
unsafe { unsafe {
for &bare_fn in bare_fns { bare_fn() } 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; let S(ref mut closure) = *closure;
(*closure)() (*closure)()
} }

View file

@ -16,7 +16,7 @@ fn test1() {
fn test2() { fn test2() {
let mut ints = [0; 32]; 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); } for i in &ints { assert!(*i == 22); }
} }