Skip to content

Commit b5b3a99

Browse files
committed
Auto merge of #26190 - Veedrac:no-iter, r=alexcrichton
Pull request for #26188.
2 parents deff2f5 + d7f5fa4 commit b5b3a99

File tree

138 files changed

+359
-361
lines changed

Some content is hidden

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

138 files changed

+359
-361
lines changed

src/compiletest/runtest.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ fn run_pretty_test(config: &Config, props: &TestProps, testfile: &Path) {
285285
format!("--target={}", config.target),
286286
"-L".to_string(),
287287
aux_dir.to_str().unwrap().to_string());
288-
args.extend(split_maybe_args(&config.target_rustcflags).into_iter());
289-
args.extend(split_maybe_args(&props.compile_flags).into_iter());
288+
args.extend(split_maybe_args(&config.target_rustcflags));
289+
args.extend(split_maybe_args(&props.compile_flags));
290290
return ProcArgs {
291291
prog: config.rustc_path.to_str().unwrap().to_string(),
292292
args: args,
@@ -333,8 +333,8 @@ actual:\n\
333333
config.build_base.to_str().unwrap().to_string(),
334334
"-L".to_string(),
335335
aux_dir.to_str().unwrap().to_string());
336-
args.extend(split_maybe_args(&config.target_rustcflags).into_iter());
337-
args.extend(split_maybe_args(&props.compile_flags).into_iter());
336+
args.extend(split_maybe_args(&config.target_rustcflags));
337+
args.extend(split_maybe_args(&props.compile_flags));
338338
// FIXME (#9639): This needs to handle non-utf8 paths
339339
return ProcArgs {
340340
prog: config.rustc_path.to_str().unwrap().to_string(),
@@ -380,7 +380,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
380380
script_str.push_str(&format!("set solib-search-path \
381381
./{}/stage2/lib/rustlib/{}/lib/\n",
382382
config.host, config.target));
383-
for line in breakpoint_lines.iter() {
383+
for line in &breakpoint_lines {
384384
script_str.push_str(&format!("break {:?}:{}\n",
385385
testfile.file_name().unwrap()
386386
.to_string_lossy(),
@@ -1171,7 +1171,7 @@ fn document(config: &Config, props: &TestProps,
11711171
out_dir.to_str().unwrap().to_string(),
11721172
testfile.to_str().unwrap().to_string()];
11731173
args.extend(extra_args.iter().cloned());
1174-
args.extend(split_maybe_args(&props.compile_flags).into_iter());
1174+
args.extend(split_maybe_args(&props.compile_flags));
11751175
let args = ProcArgs {
11761176
prog: config.rustdoc_path.to_str().unwrap().to_string(),
11771177
args: args,
@@ -1236,7 +1236,7 @@ fn compose_and_run_compiler(config: &Config, props: &TestProps,
12361236
vec!("--crate-type=dylib".to_string())
12371237
}
12381238
};
1239-
crate_type.extend(extra_link_args.clone().into_iter());
1239+
crate_type.extend(extra_link_args.clone());
12401240
let aux_args =
12411241
make_compile_args(config,
12421242
&aux_props,
@@ -1334,11 +1334,11 @@ fn make_compile_args<F>(config: &Config,
13341334
};
13351335
args.push(path.to_str().unwrap().to_string());
13361336
if props.force_host {
1337-
args.extend(split_maybe_args(&config.host_rustcflags).into_iter());
1337+
args.extend(split_maybe_args(&config.host_rustcflags));
13381338
} else {
1339-
args.extend(split_maybe_args(&config.target_rustcflags).into_iter());
1339+
args.extend(split_maybe_args(&config.target_rustcflags));
13401340
}
1341-
args.extend(split_maybe_args(&props.compile_flags).into_iter());
1341+
args.extend(split_maybe_args(&props.compile_flags));
13421342
return ProcArgs {
13431343
prog: config.rustc_path.to_str().unwrap().to_string(),
13441344
args: args,
@@ -1373,7 +1373,7 @@ fn make_run_args(config: &Config, props: &TestProps, testfile: &Path)
13731373
args.push(exe_file.to_str().unwrap().to_string());
13741374

13751375
// Add the arguments in the run_flags directive
1376-
args.extend(split_maybe_args(&props.run_flags).into_iter());
1376+
args.extend(split_maybe_args(&props.run_flags));
13771377

13781378
let prog = args.remove(0);
13791379
return ProcArgs {
@@ -1683,7 +1683,7 @@ fn compile_test_and_save_ir(config: &Config, props: &TestProps,
16831683
aux_dir.to_str().unwrap().to_string());
16841684
let llvm_args = vec!("--emit=llvm-ir".to_string(),
16851685
"--crate-type=lib".to_string());
1686-
link_args.extend(llvm_args.into_iter());
1686+
link_args.extend(llvm_args);
16871687
let args = make_compile_args(config,
16881688
props,
16891689
link_args,

src/error-index-generator/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ r##"<!DOCTYPE html>
7373

7474
try!(write!(&mut output_file, "<h1>Rust Compiler Error Index</h1>\n"));
7575

76-
for (err_code, info) in err_map.iter() {
76+
for (err_code, info) in err_map {
7777
// Enclose each error in a div so they can be shown/hidden en masse.
7878
let desc_desc = match info.description {
7979
Some(_) => "error-described",

src/libarena/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl<'longer_than_self> Drop for Arena<'longer_than_self> {
127127
fn drop(&mut self) {
128128
unsafe {
129129
destroy_chunk(&*self.head.borrow());
130-
for chunk in &*self.chunks.borrow() {
130+
for chunk in self.chunks.borrow().iter() {
131131
if !chunk.is_copy.get() {
132132
destroy_chunk(chunk);
133133
}

src/libcollections/binary_heap.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
//!
8686
//! // For each node we can reach, see if we can find a way with
8787
//! // a lower cost going through this node
88-
//! for edge in adj_list[position].iter() {
88+
//! for edge in &adj_list[position] {
8989
//! let next = State { cost: cost + edge.cost, position: edge.node };
9090
//!
9191
//! // If so, add it to the frontier and continue
@@ -450,7 +450,7 @@ impl<T: Ord> BinaryHeap<T> {
450450
/// let vec = heap.into_vec();
451451
///
452452
/// // Will print in some order
453-
/// for x in vec.iter() {
453+
/// for x in vec {
454454
/// println!("{}", x);
455455
/// }
456456
/// ```

src/libcollections/bit.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,9 @@ impl BitVec {
266266
/// # #![feature(collections)]
267267
/// use std::collections::BitVec;
268268
///
269-
/// let mut bv = BitVec::from_elem(10, false);
269+
/// let bv = BitVec::from_elem(10, false);
270270
/// assert_eq!(bv.len(), 10);
271-
/// for x in bv.iter() {
271+
/// for x in &bv {
272272
/// assert_eq!(x, false);
273273
/// }
274274
/// ```
@@ -1245,7 +1245,7 @@ impl<'a> IntoIterator for &'a BitVec {
12451245
/// s.union_with(&other);
12461246
///
12471247
/// // Print 0, 1, 3 in some order
1248-
/// for x in s.iter() {
1248+
/// for x in &s {
12491249
/// println!("{}", x);
12501250
/// }
12511251
///
@@ -1370,7 +1370,7 @@ impl BitSet {
13701370
/// let s = BitSet::from_bit_vec(bv);
13711371
///
13721372
/// // Print 1, 2 in arbitrary order
1373-
/// for x in s.iter() {
1373+
/// for x in &s {
13741374
/// println!("{}", x);
13751375
/// }
13761376
/// ```

src/libcollections/btree/map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ impl<K: Ord, V> Default for BTreeMap<K, V> {
907907
impl<K: PartialEq, V: PartialEq> PartialEq for BTreeMap<K, V> {
908908
fn eq(&self, other: &BTreeMap<K, V>) -> bool {
909909
self.len() == other.len() &&
910-
self.iter().zip(other.iter()).all(|(a, b)| a == b)
910+
self.iter().zip(other).all(|(a, b)| a == b)
911911
}
912912
}
913913

@@ -1544,7 +1544,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
15441544
/// for (_, balance) in map.range_mut(Included(&"B"), Excluded(&"Cheryl")) {
15451545
/// *balance += 100;
15461546
/// }
1547-
/// for (name, balance) in map.iter() {
1547+
/// for (name, balance) in &map {
15481548
/// println!("{} => {}", name, balance);
15491549
/// }
15501550
/// ```

src/libcollections/linked_list.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl<T> LinkedList<T> {
265265
///
266266
/// a.append(&mut b);
267267
///
268-
/// for e in a.iter() {
268+
/// for e in &a {
269269
/// println!("{}", e); // prints 1, then 2, then 3, then 4
270270
/// }
271271
/// println!("{}", b.len()); // prints 0
@@ -1189,7 +1189,7 @@ mod tests {
11891189
check_links(&m);
11901190

11911191
let mut i = 0;
1192-
for (a, &b) in m.into_iter().zip(v.iter()) {
1192+
for (a, &b) in m.into_iter().zip(&v) {
11931193
i += 1;
11941194
assert_eq!(a, b);
11951195
}

src/libcollections/slice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ impl<T> [T] {
971971
reason = "uncertain about this API approach")]
972972
#[inline]
973973
pub fn move_from(&mut self, mut src: Vec<T>, start: usize, end: usize) -> usize {
974-
for (a, b) in self.iter_mut().zip(src[start .. end].iter_mut()) {
974+
for (a, b) in self.iter_mut().zip(&mut src[start .. end]) {
975975
mem::swap(a, b);
976976
}
977977
cmp::min(self.len(), end-start)

src/libcollections/str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1917,7 +1917,7 @@ impl str {
19171917
#[stable(feature = "unicode_case_mapping", since = "1.2.0")]
19181918
pub fn to_uppercase(&self) -> String {
19191919
let mut s = String::with_capacity(self.len());
1920-
s.extend(self[..].chars().flat_map(|c| c.to_uppercase()));
1920+
s.extend(self.chars().flat_map(|c| c.to_uppercase()));
19211921
return s;
19221922
}
19231923

src/libcollections/vec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ impl<T:Clone> Clone for Vec<T> {
13311331
}
13321332

13331333
// reuse the contained values' allocations/resources.
1334-
for (place, thing) in self.iter_mut().zip(other.iter()) {
1334+
for (place, thing) in self.iter_mut().zip(other) {
13351335
place.clone_from(thing)
13361336
}
13371337

@@ -1639,7 +1639,7 @@ impl<T> Drop for Vec<T> {
16391639
// zeroed (when moving out, because of #[unsafe_no_drop_flag]).
16401640
if self.cap != 0 && self.cap != mem::POST_DROP_USIZE {
16411641
unsafe {
1642-
for x in &*self {
1642+
for x in self.iter() {
16431643
ptr::read(x);
16441644
}
16451645
dealloc(*self.ptr, self.cap)

src/libcollections/vec_deque.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ impl<T: Clone> VecDeque<T> {
14431443
/// buf.push_back(15);
14441444
/// buf.resize(2, 0);
14451445
/// buf.resize(6, 20);
1446-
/// for (a, b) in [5, 10, 20, 20, 20, 20].iter().zip(buf.iter()) {
1446+
/// for (a, b) in [5, 10, 20, 20, 20, 20].iter().zip(&buf) {
14471447
/// assert_eq!(a, b);
14481448
/// }
14491449
/// ```
@@ -1681,7 +1681,7 @@ impl<'a, T: 'a> ExactSizeIterator for Drain<'a, T> {}
16811681
impl<A: PartialEq> PartialEq for VecDeque<A> {
16821682
fn eq(&self, other: &VecDeque<A>) -> bool {
16831683
self.len() == other.len() &&
1684-
self.iter().zip(other.iter()).all(|(a, b)| a.eq(b))
1684+
self.iter().zip(other).all(|(a, b)| a.eq(b))
16851685
}
16861686
}
16871687

src/libcollections/vec_map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use vec::Vec;
5454
/// assert_eq!(months.get(&3), Some(&"Venus"));
5555
///
5656
/// // Print out all months
57-
/// for (key, value) in months.iter() {
57+
/// for (key, value) in &months {
5858
/// println!("month {} is {}", key, value);
5959
/// }
6060
///
@@ -287,7 +287,7 @@ impl<V> VecMap<V> {
287287
/// *value = "x";
288288
/// }
289289
///
290-
/// for (key, value) in map.iter() {
290+
/// for (key, value) in &map {
291291
/// assert_eq!(value, &"x");
292292
/// }
293293
/// ```

src/libcollectionstest/bit/vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ fn test_bit_vec_grow() {
625625
fn test_bit_vec_extend() {
626626
let mut bit_vec = BitVec::from_bytes(&[0b10110110, 0b00000000, 0b11111111]);
627627
let ext = BitVec::from_bytes(&[0b01001001, 0b10010010, 0b10111101]);
628-
bit_vec.extend(ext.iter());
628+
bit_vec.extend(&ext);
629629
assert_eq!(bit_vec, BitVec::from_bytes(&[0b10110110, 0b00000000, 0b11111111,
630630
0b01001001, 0b10010010, 0b10111101]));
631631
}

src/libcollectionstest/btree/set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ fn test_zip() {
147147

148148
let x = x;
149149
let y = y;
150-
let mut z = x.iter().zip(y.iter());
150+
let mut z = x.iter().zip(&y);
151151

152152
// FIXME: #5801: this needs a type hint to compile...
153153
let result: Option<(&usize, & &'static str)> = z.next();

src/libcollectionstest/string.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ fn test_from_iterator() {
344344
assert_eq!(s, c);
345345

346346
let mut d = t.to_string();
347-
d.extend(vec![u].into_iter());
347+
d.extend(vec![u]);
348348
assert_eq!(s, d);
349349
}
350350

src/libcollectionstest/vec.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ fn do_bench_from_iter(b: &mut Bencher, src_len: usize) {
699699
b.bytes = src_len as u64;
700700

701701
b.iter(|| {
702-
let dst: Vec<_> = FromIterator::from_iter(src.clone().into_iter());
702+
let dst: Vec<_> = FromIterator::from_iter(src.clone());
703703
assert_eq!(dst.len(), src_len);
704704
assert!(dst.iter().enumerate().all(|(i, x)| i == *x));
705705
});
@@ -733,7 +733,7 @@ fn do_bench_extend(b: &mut Bencher, dst_len: usize, src_len: usize) {
733733

734734
b.iter(|| {
735735
let mut dst = dst.clone();
736-
dst.extend(src.clone().into_iter());
736+
dst.extend(src.clone());
737737
assert_eq!(dst.len(), dst_len + src_len);
738738
assert!(dst.iter().enumerate().all(|(i, x)| i == *x));
739739
});
@@ -831,7 +831,7 @@ fn do_bench_push_all_move(b: &mut Bencher, dst_len: usize, src_len: usize) {
831831

832832
b.iter(|| {
833833
let mut dst = dst.clone();
834-
dst.extend(src.clone().into_iter());
834+
dst.extend(src.clone());
835835
assert_eq!(dst.len(), dst_len + src_len);
836836
assert!(dst.iter().enumerate().all(|(i, x)| i == *x));
837837
});

src/libcore/iter.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ pub trait Iterator {
177177
/// ```
178178
/// let a = [0];
179179
/// let b = [1];
180-
/// let mut it = a.iter().chain(b.iter());
180+
/// let mut it = a.iter().chain(&b);
181181
/// assert_eq!(it.next(), Some(&0));
182182
/// assert_eq!(it.next(), Some(&1));
183183
/// assert!(it.next().is_none());
@@ -200,7 +200,7 @@ pub trait Iterator {
200200
/// ```
201201
/// let a = [0];
202202
/// let b = [1];
203-
/// let mut it = a.iter().zip(b.iter());
203+
/// let mut it = a.iter().zip(&b);
204204
/// assert_eq!(it.next(), Some((&0, &1)));
205205
/// assert!(it.next().is_none());
206206
/// ```
@@ -585,9 +585,9 @@ pub trait Iterator {
585585

586586
for x in self {
587587
if f(&x) {
588-
left.extend(Some(x).into_iter())
588+
left.extend(Some(x))
589589
} else {
590-
right.extend(Some(x).into_iter())
590+
right.extend(Some(x))
591591
}
592592
}
593593

@@ -994,8 +994,8 @@ pub trait Iterator {
994994
us.extend(SizeHint(lo, hi, marker::PhantomData));
995995

996996
for (t, u) in self {
997-
ts.extend(Some(t).into_iter());
998-
us.extend(Some(u).into_iter());
997+
ts.extend(Some(t));
998+
us.extend(Some(u));
999999
}
10001000

10011001
(ts, us)

src/libcore/num/flt2dec/bignum.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ macro_rules! define_bignum {
146146

147147
let mut sz = cmp::max(self.size, other.size);
148148
let mut carry = false;
149-
for (a, b) in self.base[..sz].iter_mut().zip(other.base[..sz].iter()) {
149+
for (a, b) in self.base[..sz].iter_mut().zip(&other.base[..sz]) {
150150
let (c, v) = (*a).full_add(*b, carry);
151151
*a = v;
152152
carry = c;
@@ -166,7 +166,7 @@ macro_rules! define_bignum {
166166

167167
let sz = cmp::max(self.size, other.size);
168168
let mut noborrow = true;
169-
for (a, b) in self.base[..sz].iter_mut().zip(other.base[..sz].iter()) {
169+
for (a, b) in self.base[..sz].iter_mut().zip(&other.base[..sz]) {
170170
let (c, v) = (*a).full_add(!*b, noborrow);
171171
*a = v;
172172
noborrow = c;
@@ -183,7 +183,7 @@ macro_rules! define_bignum {
183183

184184
let mut sz = self.size;
185185
let mut carry = 0;
186-
for a in self.base[..sz].iter_mut() {
186+
for a in &mut self.base[..sz] {
187187
let (c, v) = (*a).full_mul(other, carry);
188188
*a = v;
189189
carry = c;

src/libcore/option.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
//! // but to start with we've just got `None`.
125125
//! let mut name_of_biggest_animal = None;
126126
//! let mut size_of_biggest_animal = 0;
127-
//! for big_thing in all_the_big_things.iter() {
127+
//! for big_thing in &all_the_big_things {
128128
//! match *big_thing {
129129
//! Kingdom::Animal(size, name) if size > size_of_biggest_animal => {
130130
//! // Now we've found the name of some big animal

0 commit comments

Comments
 (0)