Skip to content

Commit d5f61b4

Browse files
author
Jorge Aparicio
committed
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`
1 parent d5d7e65 commit d5f61b4

File tree

34 files changed

+54
-54
lines changed

34 files changed

+54
-54
lines changed

src/libcollections/bit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ impl Bitv {
431431
/// ```
432432
#[inline]
433433
pub fn set_all(&mut self) {
434-
for w in self.storage.iter_mut() { *w = !0u32; }
434+
for w in &mut self.storage { *w = !0u32; }
435435
self.fix_last_block();
436436
}
437437

@@ -451,7 +451,7 @@ impl Bitv {
451451
/// ```
452452
#[inline]
453453
pub fn negate(&mut self) {
454-
for w in self.storage.iter_mut() { *w = !*w; }
454+
for w in &mut self.storage { *w = !*w; }
455455
self.fix_last_block();
456456
}
457457

@@ -912,7 +912,7 @@ impl Bitv {
912912
#[inline]
913913
#[stable(feature = "rust1", since = "1.0.0")]
914914
pub fn clear(&mut self) {
915-
for w in self.storage.iter_mut() { *w = 0u32; }
915+
for w in &mut self.storage { *w = 0u32; }
916916
}
917917
}
918918

src/libcollections/ring_buf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1869,7 +1869,7 @@ mod tests {
18691869

18701870
b.iter(|| {
18711871
let mut sum = 0;
1872-
for i in ring.iter_mut() {
1872+
for i in &mut ring {
18731873
sum += *i;
18741874
}
18751875
test::black_box(sum);

src/libcollections/slice.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ impl Iterator for ElementSwaps {
12281228
self.sdir.swap(i, j);
12291229

12301230
// Swap the direction of each larger SizeDirection
1231-
for x in self.sdir.iter_mut() {
1231+
for x in &mut self.sdir {
12321232
if x.size > sd.size {
12331233
x.dir = match x.dir { Pos => Neg, Neg => Pos };
12341234
}
@@ -2356,7 +2356,7 @@ mod tests {
23562356
#[test]
23572357
fn test_mut_iterator() {
23582358
let mut xs = [1, 2, 3, 4, 5];
2359-
for x in xs.iter_mut() {
2359+
for x in &mut xs {
23602360
*x += 1;
23612361
}
23622362
assert!(xs == [2, 3, 4, 5, 6])
@@ -2656,15 +2656,15 @@ mod tests {
26562656
let left: &[_] = left;
26572657
assert!(left[..left.len()] == [1, 2][]);
26582658
}
2659-
for p in left.iter_mut() {
2659+
for p in left {
26602660
*p += 1;
26612661
}
26622662

26632663
{
26642664
let right: &[_] = right;
26652665
assert!(right[..right.len()] == [3, 4, 5][]);
26662666
}
2667-
for p in right.iter_mut() {
2667+
for p in right {
26682668
*p += 2;
26692669
}
26702670
}
@@ -2693,7 +2693,7 @@ mod tests {
26932693
}
26942694
assert_eq!(cnt, 5);
26952695

2696-
for f in v.iter_mut() {
2696+
for f in &mut v {
26972697
assert!(*f == Foo);
26982698
cnt += 1;
26992699
}
@@ -2796,7 +2796,7 @@ mod tests {
27962796
let mut v = [0u8, 1, 2, 3, 4, 5, 6];
27972797
assert_eq!(v.chunks_mut(2).len(), 4);
27982798
for (i, chunk) in v.chunks_mut(3).enumerate() {
2799-
for x in chunk.iter_mut() {
2799+
for x in chunk {
28002800
*x = i as u8;
28012801
}
28022802
}
@@ -2808,7 +2808,7 @@ mod tests {
28082808
fn test_mut_chunks_rev() {
28092809
let mut v = [0u8, 1, 2, 3, 4, 5, 6];
28102810
for (i, chunk) in v.chunks_mut(3).rev().enumerate() {
2811-
for x in chunk.iter_mut() {
2811+
for x in chunk {
28122812
*x = i as u8;
28132813
}
28142814
}
@@ -2872,7 +2872,7 @@ mod bench {
28722872

28732873
b.iter(|| {
28742874
let mut i = 0;
2875-
for x in v.iter_mut() {
2875+
for x in &mut v {
28762876
*x = i;
28772877
i += 1;
28782878
}
@@ -3006,7 +3006,7 @@ mod bench {
30063006
unsafe {
30073007
v.set_len(1024);
30083008
}
3009-
for x in v.iter_mut() {
3009+
for x in &mut v {
30103010
*x = 0;
30113011
}
30123012
v

src/libcollections/vec.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,7 +2022,7 @@ mod tests {
20222022
{
20232023
let slice = &mut values[2 ..];
20242024
assert!(slice == [3, 4, 5]);
2025-
for p in slice.iter_mut() {
2025+
for p in slice {
20262026
*p += 2;
20272027
}
20282028
}
@@ -2036,7 +2036,7 @@ mod tests {
20362036
{
20372037
let slice = &mut values[.. 2];
20382038
assert!(slice == [1, 2]);
2039-
for p in slice.iter_mut() {
2039+
for p in slice {
20402040
*p += 1;
20412041
}
20422042
}
@@ -2053,15 +2053,15 @@ mod tests {
20532053
let left: &[_] = left;
20542054
assert!(&left[..left.len()] == &[1, 2][]);
20552055
}
2056-
for p in left.iter_mut() {
2056+
for p in left {
20572057
*p += 1;
20582058
}
20592059

20602060
{
20612061
let right: &[_] = right;
20622062
assert!(&right[..right.len()] == &[3, 4, 5][]);
20632063
}
2064-
for p in right.iter_mut() {
2064+
for p in right {
20652065
*p += 2;
20662066
}
20672067
}
@@ -2137,7 +2137,7 @@ mod tests {
21372137
v.push(());
21382138
assert_eq!(v.iter_mut().count(), 4);
21392139

2140-
for &mut () in v.iter_mut() {}
2140+
for &mut () in &mut v {}
21412141
unsafe { v.set_len(0); }
21422142
assert_eq!(v.iter_mut().count(), 0);
21432143
}

src/libcollections/vec_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ mod test_map {
924924
assert!(m.insert(6, 10).is_none());
925925
assert!(m.insert(10, 11).is_none());
926926

927-
for (k, v) in m.iter_mut() {
927+
for (k, v) in &mut m {
928928
*v += k as int;
929929
}
930930

src/libcore/iter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,7 +2205,7 @@ impl<A, B, I, U, F> Iterator for FlatMap<A, B, I, U, F> where
22052205
#[inline]
22062206
fn next(&mut self) -> Option<B> {
22072207
loop {
2208-
for inner in self.frontiter.iter_mut() {
2208+
if let Some(ref mut inner) = self.frontiter {
22092209
for x in inner.by_ref() {
22102210
return Some(x)
22112211
}
@@ -2238,7 +2238,7 @@ impl<A, B, I, U, F> DoubleEndedIterator for FlatMap<A, B, I, U, F> where
22382238
#[inline]
22392239
fn next_back(&mut self) -> Option<B> {
22402240
loop {
2241-
for inner in self.backiter.iter_mut() {
2241+
if let Some(ref mut inner) = self.backiter {
22422242
match inner.next_back() {
22432243
None => (),
22442244
y => return y

src/librand/chacha.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl<'a> SeedableRng<&'a [u32]> for ChaChaRng {
194194
impl Rand for ChaChaRng {
195195
fn rand<R: Rng>(other: &mut R) -> ChaChaRng {
196196
let mut key : [u32; KEY_WORDS] = [0; KEY_WORDS];
197-
for word in key.iter_mut() {
197+
for word in &mut key {
198198
*word = other.gen();
199199
}
200200
SeedableRng::from_seed(key.as_slice())

src/librand/distributions/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl<'a, T: Clone> WeightedChoice<'a, T> {
123123
// we convert the list from individual weights to cumulative
124124
// weights so we can binary search. This *could* drop elements
125125
// with weight == 0 as an optimisation.
126-
for item in items.iter_mut() {
126+
for item in &mut *items {
127127
running_total = match running_total.checked_add(item.weight) {
128128
Some(n) => n,
129129
None => panic!("WeightedChoice::new called with a total weight \

src/librand/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub trait Rng : Sized {
154154
// optimisations are on.
155155
let mut count = 0;
156156
let mut num = 0;
157-
for byte in dest.iter_mut() {
157+
for byte in dest {
158158
if count == 0 {
159159
// we could micro-optimise here by generating a u32 if
160160
// we only need a few more bytes to fill the vector

src/librustc/lint/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ macro_rules! run_lints { ($cx:expr, $f:ident, $($args:expr),*) => ({
329329
// Move the vector of passes out of `$cx` so that we can
330330
// iterate over it mutably while passing `$cx` to the methods.
331331
let mut passes = $cx.lints.passes.take().unwrap();
332-
for obj in passes.iter_mut() {
332+
for obj in &mut passes {
333333
obj.$f($cx, $($args),*);
334334
}
335335
$cx.lints.passes = Some(passes);

src/librustc/middle/dataflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ impl<'a, 'b, 'tcx, O:DataFlowOperator> PropagationContext<'a, 'b, 'tcx, O> {
501501

502502
fn reset(&mut self, bits: &mut [uint]) {
503503
let e = if self.dfcx.oper.initial_value() {uint::MAX} else {0};
504-
for b in bits.iter_mut() {
504+
for b in bits {
505505
*b = e;
506506
}
507507
}

src/librustc/middle/infer/error_reporting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
335335
same_frs: &FreeRegionsFromSameFn) {
336336
let scope_id = same_frs.scope_id;
337337
let (sub_fr, sup_fr) = (same_frs.sub_fr, same_frs.sup_fr);
338-
for sr in same_regions.iter_mut() {
338+
for sr in &mut *same_regions {
339339
if sr.contains(&sup_fr.bound_region)
340340
&& scope_id == sr.scope_id {
341341
sr.push(sub_fr.bound_region);

src/librustc_borrowck/borrowck/gather_loans/move_error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn group_errors_with_same_origin<'tcx>(errors: &Vec<MoveError<'tcx>>)
9595
} else {
9696
Vec::new()
9797
};
98-
for ge in grouped_errors.iter_mut() {
98+
for ge in &mut *grouped_errors {
9999
if move_from_id == ge.move_from.id && error.move_to.is_some() {
100100
debug!("appending move_to to list");
101101
ge.move_to_places.extend(move_to.into_iter());

src/librustc_trans/trans/cabi_x86_64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fn classify_ty(ty: Type) -> Vec<RegClass> {
151151
}
152152

153153
fn all_mem(cls: &mut [RegClass]) {
154-
for elt in cls.iter_mut() {
154+
for elt in cls {
155155
*elt = Memory;
156156
}
157157
}

src/librustc_trans/trans/debuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2050,7 +2050,7 @@ fn prepare_struct_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
20502050

20512051
// The `Ty` values returned by `ty::struct_fields` can still contain
20522052
// `ty_projection` variants, so normalize those away.
2053-
for field in fields.iter_mut() {
2053+
for field in &mut fields {
20542054
field.mt.ty = monomorphize::normalize_associated_type(cx.tcx(), &field.mt.ty);
20552055
}
20562056

src/librustc_typeck/astconv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ fn ast_type_binding_to_projection_predicate<'tcx>(
733733
// If converting for an object type, then remove the dummy-ty from `Self` now.
734734
// Yuckety yuck.
735735
if self_ty.is_none() {
736-
for candidate in candidates.iter_mut() {
736+
for candidate in &mut candidates {
737737
let mut dummy_substs = candidate.0.substs.clone();
738738
assert!(dummy_substs.self_ty() == Some(dummy_self_ty));
739739
dummy_substs.types.pop(SelfSpace);

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13411341
/// ! gets replaced with (), unconstrained ints with i32, and unconstrained floats with f64.
13421342
pub fn default_type_parameters(&self) {
13431343
use middle::ty::UnconstrainedNumeric::{UnconstrainedInt, UnconstrainedFloat, Neither};
1344-
for (_, &mut ref ty) in self.inh.node_types.borrow_mut().iter_mut() {
1344+
for (_, &mut ref ty) in &mut *self.inh.node_types.borrow_mut() {
13451345
let resolved = self.infcx().resolve_type_vars_if_possible(ty);
13461346
if self.infcx().type_var_diverges(resolved) {
13471347
demand::eqtype(self, codemap::DUMMY_SP, *ty, ty::mk_nil(self.tcx()));

src/librustc_typeck/rscope.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl<'r> RegionScope for ShiftedRscope<'r> {
165165
{
166166
match self.base_scope.anon_regions(span, count) {
167167
Ok(mut v) => {
168-
for r in v.iter_mut() {
168+
for r in &mut v {
169169
*r = ty_fold::shift_region(*r, 1);
170170
}
171171
Ok(v)

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
166166
_ => unreachable!(),
167167
};
168168
let mut tmp = Vec::new();
169-
for child in m.items.iter_mut() {
169+
for child in &mut m.items {
170170
match child.inner {
171171
ModuleItem(..) => {}
172172
_ => continue,

src/librustdoc/html/render.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ impl Context {
12701270
v.push(NameDoc(myname, Some(shorter_line(item.doc_value()))));
12711271
}
12721272

1273-
for (_, items) in map.iter_mut() {
1273+
for (_, items) in &mut map {
12741274
items.sort();
12751275
}
12761276
return map;

src/libstd/ascii.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,15 @@ impl AsciiExt<Vec<u8>> for [u8] {
134134
impl OwnedAsciiExt for Vec<u8> {
135135
#[inline]
136136
fn into_ascii_uppercase(mut self) -> Vec<u8> {
137-
for byte in self.iter_mut() {
137+
for byte in &mut self {
138138
*byte = byte.to_ascii_uppercase();
139139
}
140140
self
141141
}
142142

143143
#[inline]
144144
fn into_ascii_lowercase(mut self) -> Vec<u8> {
145-
for byte in self.iter_mut() {
145+
for byte in &mut self {
146146
*byte = byte.to_ascii_lowercase();
147147
}
148148
self

src/libstd/old_io/net/ip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<'a> Parser<'a> {
125125
// Return result of first successful parser
126126
fn read_or<T>(&mut self, parsers: &mut [Box<FnMut(&mut Parser) -> Option<T>>])
127127
-> Option<T> {
128-
for pf in parsers.iter_mut() {
128+
for pf in parsers {
129129
match self.read_atomically(|p: &mut Parser| pf.call_mut((p,))) {
130130
Some(r) => return Some(r),
131131
None => {}

src/libstd/old_io/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,15 @@ impl<W> MultiWriter<W> where W: Writer {
144144
impl<W> Writer for MultiWriter<W> where W: Writer {
145145
#[inline]
146146
fn write_all(&mut self, buf: &[u8]) -> old_io::IoResult<()> {
147-
for writer in self.writers.iter_mut() {
147+
for writer in &mut self.writers {
148148
try!(writer.write_all(buf));
149149
}
150150
Ok(())
151151
}
152152

153153
#[inline]
154154
fn flush(&mut self) -> old_io::IoResult<()> {
155-
for writer in self.writers.iter_mut() {
155+
for writer in &mut self.writers {
156156
try!(writer.flush());
157157
}
158158
Ok(())

src/libsyntax/ext/tt/macro_parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ pub fn parse(sess: &ParseSess,
444444
if token_name_eq(&tok, &token::Eof) {
445445
if eof_eis.len() == 1us {
446446
let mut v = Vec::new();
447-
for dv in (&mut eof_eis[0]).matches.iter_mut() {
447+
for dv in &mut (&mut eof_eis[0]).matches {
448448
v.push(dv.pop().unwrap());
449449
}
450450
return Success(nameize(sess, ms, &v[]));

src/libsyntax/fold.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub trait MoveMap<T> {
3737

3838
impl<T> MoveMap<T> for Vec<T> {
3939
fn move_map<F>(mut self, mut f: F) -> Vec<T> where F: FnMut(T) -> T {
40-
for p in self.iter_mut() {
40+
for p in &mut self {
4141
unsafe {
4242
// FIXME(#5016) this shouldn't need to zero to be safe.
4343
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
11171117
}, vec![], span)
11181118
};
11191119

1120-
for def in exported_macros.iter_mut() {
1120+
for def in &mut exported_macros {
11211121
def.id = folder.new_id(def.id);
11221122
}
11231123

0 commit comments

Comments
 (0)