Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove pointless calls to *iter() and iter_mut() #26190

Merged
merged 2 commits into from
Jun 11, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ fn run_pretty_test(config: &Config, props: &TestProps, testfile: &Path) {
format!("--target={}", config.target),
"-L".to_string(),
aux_dir.to_str().unwrap().to_string());
args.extend(split_maybe_args(&config.target_rustcflags).into_iter());
args.extend(split_maybe_args(&props.compile_flags).into_iter());
args.extend(split_maybe_args(&config.target_rustcflags));
args.extend(split_maybe_args(&props.compile_flags));
return ProcArgs {
prog: config.rustc_path.to_str().unwrap().to_string(),
args: args,
Expand Down Expand Up @@ -333,8 +333,8 @@ actual:\n\
config.build_base.to_str().unwrap().to_string(),
"-L".to_string(),
aux_dir.to_str().unwrap().to_string());
args.extend(split_maybe_args(&config.target_rustcflags).into_iter());
args.extend(split_maybe_args(&props.compile_flags).into_iter());
args.extend(split_maybe_args(&config.target_rustcflags));
args.extend(split_maybe_args(&props.compile_flags));
// FIXME (#9639): This needs to handle non-utf8 paths
return ProcArgs {
prog: config.rustc_path.to_str().unwrap().to_string(),
Expand Down Expand Up @@ -380,7 +380,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
script_str.push_str(&format!("set solib-search-path \
./{}/stage2/lib/rustlib/{}/lib/\n",
config.host, config.target));
for line in breakpoint_lines.iter() {
for line in &breakpoint_lines {
script_str.push_str(&format!("break {:?}:{}\n",
testfile.file_name().unwrap()
.to_string_lossy(),
Expand Down Expand Up @@ -1171,7 +1171,7 @@ fn document(config: &Config, props: &TestProps,
out_dir.to_str().unwrap().to_string(),
testfile.to_str().unwrap().to_string()];
args.extend(extra_args.iter().cloned());
args.extend(split_maybe_args(&props.compile_flags).into_iter());
args.extend(split_maybe_args(&props.compile_flags));
let args = ProcArgs {
prog: config.rustdoc_path.to_str().unwrap().to_string(),
args: args,
Expand Down Expand Up @@ -1236,7 +1236,7 @@ fn compose_and_run_compiler(config: &Config, props: &TestProps,
vec!("--crate-type=dylib".to_string())
}
};
crate_type.extend(extra_link_args.clone().into_iter());
crate_type.extend(extra_link_args.clone());
let aux_args =
make_compile_args(config,
&aux_props,
Expand Down Expand Up @@ -1334,11 +1334,11 @@ fn make_compile_args<F>(config: &Config,
};
args.push(path.to_str().unwrap().to_string());
if props.force_host {
args.extend(split_maybe_args(&config.host_rustcflags).into_iter());
args.extend(split_maybe_args(&config.host_rustcflags));
} else {
args.extend(split_maybe_args(&config.target_rustcflags).into_iter());
args.extend(split_maybe_args(&config.target_rustcflags));
}
args.extend(split_maybe_args(&props.compile_flags).into_iter());
args.extend(split_maybe_args(&props.compile_flags));
return ProcArgs {
prog: config.rustc_path.to_str().unwrap().to_string(),
args: args,
Expand Down Expand Up @@ -1373,7 +1373,7 @@ fn make_run_args(config: &Config, props: &TestProps, testfile: &Path)
args.push(exe_file.to_str().unwrap().to_string());

// Add the arguments in the run_flags directive
args.extend(split_maybe_args(&props.run_flags).into_iter());
args.extend(split_maybe_args(&props.run_flags));

let prog = args.remove(0);
return ProcArgs {
Expand Down Expand Up @@ -1683,7 +1683,7 @@ fn compile_test_and_save_ir(config: &Config, props: &TestProps,
aux_dir.to_str().unwrap().to_string());
let llvm_args = vec!("--emit=llvm-ir".to_string(),
"--crate-type=lib".to_string());
link_args.extend(llvm_args.into_iter());
link_args.extend(llvm_args);
let args = make_compile_args(config,
props,
link_args,
Expand Down
2 changes: 1 addition & 1 deletion src/error-index-generator/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ r##"<!DOCTYPE html>

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

for (err_code, info) in err_map.iter() {
for (err_code, info) in err_map {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of thing is extra interesting, because this looks like a change in semantics, but since err_map is a reference, it's not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, this isn't particularly worrisome because the default - move if it's a value or take references if it's a reference - is always either the right thing or a compiler error. YMMV.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I don't think it's a problem at all, just an interesting side-effect of looking at the diff.

// Enclose each error in a div so they can be shown/hidden en masse.
let desc_desc = match info.description {
Some(_) => "error-described",
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
//! gadget_owner.gadgets.borrow_mut().push(gadget2.clone().downgrade());
//!
//! // Iterate over our Gadgets, printing their details out
//! for gadget_opt in gadget_owner.gadgets.borrow().iter() {
//! for gadget_opt in &*gadget_owner.gadgets.borrow() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not strictly sure that doing a reborrow is clearer than calling .iter() in cases like these... hm

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @steveklabnik that the .iter() is preferrable in this case.

//!
//! // gadget_opt is a Weak<Gadget>. Since weak pointers can't guarantee
//! // that their object is still allocated, we need to call upgrade()
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
//!
//! // For each node we can reach, see if we can find a way with
//! // a lower cost going through this node
//! for edge in adj_list[position].iter() {
//! for edge in &adj_list[position] {
//! let next = State { cost: cost + edge.cost, position: edge.node };
//!
//! // If so, add it to the frontier and continue
Expand Down Expand Up @@ -450,7 +450,7 @@ impl<T: Ord> BinaryHeap<T> {
/// let vec = heap.into_vec();
///
/// // Will print in some order
/// for x in vec.iter() {
/// for x in vec {
/// println!("{}", x);
/// }
/// ```
Expand Down
8 changes: 4 additions & 4 deletions src/libcollections/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ impl BitVec {
/// # #![feature(collections)]
/// use std::collections::BitVec;
///
/// let mut bv = BitVec::from_elem(10, false);
/// let bv = BitVec::from_elem(10, false);
/// assert_eq!(bv.len(), 10);
/// for x in bv.iter() {
/// for x in &bv {
/// assert_eq!(x, false);
/// }
/// ```
Expand Down Expand Up @@ -1245,7 +1245,7 @@ impl<'a> IntoIterator for &'a BitVec {
/// s.union_with(&other);
///
/// // Print 0, 1, 3 in some order
/// for x in s.iter() {
/// for x in &s {
/// println!("{}", x);
/// }
///
Expand Down Expand Up @@ -1370,7 +1370,7 @@ impl BitSet {
/// let s = BitSet::from_bit_vec(bv);
///
/// // Print 1, 2 in arbitrary order
/// for x in s.iter() {
/// for x in &s {
/// println!("{}", x);
/// }
/// ```
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ impl<K: Ord, V> Default for BTreeMap<K, V> {
impl<K: PartialEq, V: PartialEq> PartialEq for BTreeMap<K, V> {
fn eq(&self, other: &BTreeMap<K, V>) -> bool {
self.len() == other.len() &&
self.iter().zip(other.iter()).all(|(a, b)| a == b)
self.iter().zip(other).all(|(a, b)| a == b)
}
}

Expand Down Expand Up @@ -1544,7 +1544,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// for (_, balance) in map.range_mut(Included(&"B"), Excluded(&"Cheryl")) {
/// *balance += 100;
/// }
/// for (name, balance) in map.iter() {
/// for (name, balance) in &map {
/// println!("{} => {}", name, balance);
/// }
/// ```
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl<T> LinkedList<T> {
///
/// a.append(&mut b);
///
/// for e in a.iter() {
/// for e in &a {
/// println!("{}", e); // prints 1, then 2, then 3, then 4
/// }
/// println!("{}", b.len()); // prints 0
Expand Down Expand Up @@ -1189,7 +1189,7 @@ mod tests {
check_links(&m);

let mut i = 0;
for (a, &b) in m.into_iter().zip(v.iter()) {
for (a, &b) in m.into_iter().zip(&v) {
i += 1;
assert_eq!(a, b);
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ impl<T> [T] {
reason = "uncertain about this API approach")]
#[inline]
pub fn move_from(&mut self, mut src: Vec<T>, start: usize, end: usize) -> usize {
for (a, b) in self.iter_mut().zip(src[start .. end].iter_mut()) {
for (a, b) in self.iter_mut().zip(&mut src[start .. end]) {
mem::swap(a, b);
}
cmp::min(self.len(), end-start)
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1890,7 +1890,7 @@ impl str {
#[stable(feature = "unicode_case_mapping", since = "1.2.0")]
pub fn to_uppercase(&self) -> String {
let mut s = String::with_capacity(self.len());
s.extend(self[..].chars().flat_map(|c| c.to_uppercase()));
s.extend(self.chars().flat_map(|c| c.to_uppercase()));
return s;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,7 @@ impl<T:Clone> Clone for Vec<T> {
}

// reuse the contained values' allocations/resources.
for (place, thing) in self.iter_mut().zip(other.iter()) {
for (place, thing) in self.iter_mut().zip(other) {
place.clone_from(thing)
}

Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,7 @@ impl<T: Clone> VecDeque<T> {
/// buf.push_back(15);
/// buf.resize(2, 0);
/// buf.resize(6, 20);
/// for (a, b) in [5, 10, 20, 20, 20, 20].iter().zip(buf.iter()) {
/// for (a, b) in [5, 10, 20, 20, 20, 20].iter().zip(&buf) {
/// assert_eq!(a, b);
/// }
/// ```
Expand Down Expand Up @@ -1681,7 +1681,7 @@ impl<'a, T: 'a> ExactSizeIterator for Drain<'a, T> {}
impl<A: PartialEq> PartialEq for VecDeque<A> {
fn eq(&self, other: &VecDeque<A>) -> bool {
self.len() == other.len() &&
self.iter().zip(other.iter()).all(|(a, b)| a.eq(b))
self.iter().zip(other).all(|(a, b)| a.eq(b))
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/vec_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use vec::Vec;
/// assert_eq!(months.get(&3), Some(&"Venus"));
///
/// // Print out all months
/// for (key, value) in months.iter() {
/// for (key, value) in &months {
/// println!("month {} is {}", key, value);
/// }
///
Expand Down Expand Up @@ -287,7 +287,7 @@ impl<V> VecMap<V> {
/// *value = "x";
/// }
///
/// for (key, value) in map.iter() {
/// for (key, value) in &map {
/// assert_eq!(value, &"x");
/// }
/// ```
Expand Down
2 changes: 1 addition & 1 deletion src/libcollectionstest/bit/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ fn test_bit_vec_grow() {
fn test_bit_vec_extend() {
let mut bit_vec = BitVec::from_bytes(&[0b10110110, 0b00000000, 0b11111111]);
let ext = BitVec::from_bytes(&[0b01001001, 0b10010010, 0b10111101]);
bit_vec.extend(ext.iter());
bit_vec.extend(&ext);
assert_eq!(bit_vec, BitVec::from_bytes(&[0b10110110, 0b00000000, 0b11111111,
0b01001001, 0b10010010, 0b10111101]));
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcollectionstest/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ fn test_zip() {

let x = x;
let y = y;
let mut z = x.iter().zip(y.iter());
let mut z = x.iter().zip(&y);

// FIXME: #5801: this needs a type hint to compile...
let result: Option<(&usize, & &'static str)> = z.next();
Expand Down
2 changes: 1 addition & 1 deletion src/libcollectionstest/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ fn test_from_iterator() {
assert_eq!(s, c);

let mut d = t.to_string();
d.extend(vec![u].into_iter());
d.extend(vec![u]);
assert_eq!(s, d);
}

Expand Down
6 changes: 3 additions & 3 deletions src/libcollectionstest/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ fn do_bench_from_iter(b: &mut Bencher, src_len: usize) {
b.bytes = src_len as u64;

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

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

b.iter(|| {
let mut dst = dst.clone();
dst.extend(src.clone().into_iter());
dst.extend(src.clone());
assert_eq!(dst.len(), dst_len + src_len);
assert!(dst.iter().enumerate().all(|(i, x)| i == *x));
});
Expand Down
12 changes: 6 additions & 6 deletions src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ pub trait Iterator {
/// ```
/// let a = [0];
/// let b = [1];
/// let mut it = a.iter().chain(b.iter());
/// let mut it = a.iter().chain(&b);
/// assert_eq!(it.next(), Some(&0));
/// assert_eq!(it.next(), Some(&1));
/// assert!(it.next().is_none());
Expand All @@ -200,7 +200,7 @@ pub trait Iterator {
/// ```
/// let a = [0];
/// let b = [1];
/// let mut it = a.iter().zip(b.iter());
/// let mut it = a.iter().zip(&b);
/// assert_eq!(it.next(), Some((&0, &1)));
/// assert!(it.next().is_none());
/// ```
Expand Down Expand Up @@ -585,9 +585,9 @@ pub trait Iterator {

for x in self {
if f(&x) {
left.extend(Some(x).into_iter())
left.extend(Some(x))
} else {
right.extend(Some(x).into_iter())
right.extend(Some(x))
}
}

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

for (t, u) in self {
ts.extend(Some(t).into_iter());
us.extend(Some(u).into_iter());
ts.extend(Some(t));
us.extend(Some(u));
}

(ts, us)
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/num/flt2dec/bignum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ macro_rules! define_bignum {

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

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

let mut sz = self.size;
let mut carry = 0;
for a in self.base[..sz].iter_mut() {
for a in &mut self.base[..sz] {
let (c, v) = (*a).full_mul(other, carry);
*a = v;
carry = c;
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
//! // but to start with we've just got `None`.
//! let mut name_of_biggest_animal = None;
//! let mut size_of_biggest_animal = 0;
//! for big_thing in all_the_big_things.iter() {
//! for big_thing in &all_the_big_things {
//! match *big_thing {
//! Kingdom::Animal(size, name) if size > size_of_biggest_animal => {
//! // Now we've found the name of some big animal
Expand Down
Loading