Remove usage of .map(|&foo| foo)

This commit is contained in:
Kevin Butler 2015-02-15 05:19:50 +00:00
parent 2f586b9687
commit 061206b9c7
17 changed files with 44 additions and 44 deletions

View file

@ -540,7 +540,7 @@ pub trait IteratorExt: Iterator + Sized {
///
/// let a = [1, 4, 2, 3, 8, 9, 6];
/// let sum = a.iter()
/// .map(|&x| x)
/// .cloned()
/// .inspect(|&x| println!("filtering {}", x))
/// .filter(|&x| x % 2 == 0)
/// .inspect(|&x| println!("{} made it through", x))
@ -579,7 +579,7 @@ pub trait IteratorExt: Iterator + Sized {
///
/// ```
/// let a = [1, 2, 3, 4, 5];
/// let b: Vec<_> = a.iter().map(|&x| x).collect();
/// let b: Vec<_> = a.iter().cloned().collect();
/// assert_eq!(a, b);
/// ```
#[inline]
@ -955,7 +955,7 @@ pub trait IteratorExt: Iterator + Sized {
///
/// ```
/// let a = [(1, 2), (3, 4)];
/// let (left, right): (Vec<_>, Vec<_>) = a.iter().map(|&x| x).unzip();
/// let (left, right): (Vec<_>, Vec<_>) = a.iter().cloned().unzip();
/// assert_eq!([1, 3], left);
/// assert_eq!([2, 4], right);
/// ```
@ -1160,7 +1160,7 @@ pub trait AdditiveIterator<A> {
/// use std::iter::AdditiveIterator;
///
/// let a = [1i32, 2, 3, 4, 5];
/// let mut it = a.iter().map(|&x| x);
/// let mut it = a.iter().cloned();
/// assert!(it.sum() == 15);
/// ```
fn sum(self) -> A;

View file

@ -91,7 +91,7 @@ fn test_iterator_chain() {
assert_eq!(i, expected.len());
let ys = count(30, 10).take(4);
let mut it = xs.iter().map(|&x| x).chain(ys);
let mut it = xs.iter().cloned().chain(ys);
let mut i = 0;
for x in it {
assert_eq!(x, expected[i]);
@ -119,7 +119,7 @@ fn test_iterator_enumerate() {
#[test]
fn test_iterator_peekable() {
let xs = vec![0, 1, 2, 3, 4, 5];
let mut it = xs.iter().map(|&x|x).peekable();
let mut it = xs.iter().cloned().peekable();
assert_eq!(it.len(), 6);
assert_eq!(it.peek().unwrap(), &0);
@ -259,7 +259,7 @@ fn test_inspect() {
let mut n = 0;
let ys = xs.iter()
.map(|&x| x)
.cloned()
.inspect(|_| n += 1)
.collect::<Vec<uint>>();
@ -329,33 +329,33 @@ fn test_iterator_len() {
#[test]
fn test_iterator_sum() {
let v: &[i32] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
assert_eq!(v[..4].iter().map(|&x| x).sum(), 6);
assert_eq!(v.iter().map(|&x| x).sum(), 55);
assert_eq!(v[..0].iter().map(|&x| x).sum(), 0);
assert_eq!(v[..4].iter().cloned().sum(), 6);
assert_eq!(v.iter().cloned().sum(), 55);
assert_eq!(v[..0].iter().cloned().sum(), 0);
}
#[test]
fn test_iterator_product() {
let v: &[i32] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
assert_eq!(v[..4].iter().map(|&x| x).product(), 0);
assert_eq!(v[1..5].iter().map(|&x| x).product(), 24);
assert_eq!(v[..0].iter().map(|&x| x).product(), 1);
assert_eq!(v[..4].iter().cloned().product(), 0);
assert_eq!(v[1..5].iter().cloned().product(), 24);
assert_eq!(v[..0].iter().cloned().product(), 1);
}
#[test]
fn test_iterator_max() {
let v: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
assert_eq!(v[..4].iter().map(|&x| x).max(), Some(3));
assert_eq!(v.iter().map(|&x| x).max(), Some(10));
assert_eq!(v[..0].iter().map(|&x| x).max(), None);
assert_eq!(v[..4].iter().cloned().max(), Some(3));
assert_eq!(v.iter().cloned().max(), Some(10));
assert_eq!(v[..0].iter().cloned().max(), None);
}
#[test]
fn test_iterator_min() {
let v: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
assert_eq!(v[..4].iter().map(|&x| x).min(), Some(0));
assert_eq!(v.iter().map(|&x| x).min(), Some(0));
assert_eq!(v[..0].iter().map(|&x| x).min(), None);
assert_eq!(v[..4].iter().cloned().min(), Some(0));
assert_eq!(v.iter().cloned().min(), Some(0));
assert_eq!(v[..0].iter().cloned().min(), None);
}
#[test]
@ -373,7 +373,7 @@ fn test_iterator_size_hint() {
assert_eq!(c.clone().take_while(|_| false).size_hint(), (0, None));
assert_eq!(c.clone().skip_while(|_| false).size_hint(), (0, None));
assert_eq!(c.clone().enumerate().size_hint(), (uint::MAX, None));
assert_eq!(c.clone().chain(vi.clone().map(|&i| i)).size_hint(), (uint::MAX, None));
assert_eq!(c.clone().chain(vi.clone().cloned()).size_hint(), (uint::MAX, None));
assert_eq!(c.clone().zip(vi.clone()).size_hint(), (10, Some(10)));
assert_eq!(c.clone().scan(0, |_,_| Some(0)).size_hint(), (0, None));
assert_eq!(c.clone().filter(|_| false).size_hint(), (0, None));
@ -398,7 +398,7 @@ fn test_iterator_size_hint() {
#[test]
fn test_collect() {
let a = vec![1, 2, 3, 4, 5];
let b: Vec<int> = a.iter().map(|&x| x).collect();
let b: Vec<int> = a.iter().cloned().collect();
assert!(a == b);
}
@ -471,7 +471,7 @@ fn test_rev() {
let mut it = xs.iter();
it.next();
it.next();
assert!(it.rev().map(|&x| x).collect::<Vec<int>>() ==
assert!(it.rev().cloned().collect::<Vec<int>>() ==
vec![16, 14, 12, 10, 8, 6]);
}
@ -508,7 +508,7 @@ fn test_double_ended_map() {
#[test]
fn test_double_ended_enumerate() {
let xs = [1, 2, 3, 4, 5, 6];
let mut it = xs.iter().map(|&x| x).enumerate();
let mut it = xs.iter().cloned().enumerate();
assert_eq!(it.next(), Some((0, 1)));
assert_eq!(it.next(), Some((1, 2)));
assert_eq!(it.next_back(), Some((5, 6)));
@ -522,8 +522,8 @@ fn test_double_ended_enumerate() {
fn test_double_ended_zip() {
let xs = [1, 2, 3, 4, 5, 6];
let ys = [1, 2, 3, 7];
let a = xs.iter().map(|&x| x);
let b = ys.iter().map(|&x| x);
let a = xs.iter().cloned();
let b = ys.iter().cloned();
let mut it = a.zip(b);
assert_eq!(it.next(), Some((1, 1)));
assert_eq!(it.next(), Some((2, 2)));

View file

@ -215,7 +215,7 @@ impl<'a> SeedableRng<&'a [u32]> for IsaacRng {
fn reseed(&mut self, seed: &'a [u32]) {
// make the seed into [seed[0], seed[1], ..., seed[seed.len()
// - 1], 0, 0, ...], to fill rng.rsl.
let seed_iter = seed.iter().map(|&x| x).chain(repeat(0u32));
let seed_iter = seed.iter().cloned().chain(repeat(0u32));
for (rsl_elem, seed_elem) in self.rsl.iter_mut().zip(seed_iter) {
*rsl_elem = seed_elem;
@ -458,7 +458,7 @@ impl<'a> SeedableRng<&'a [u64]> for Isaac64Rng {
fn reseed(&mut self, seed: &'a [u64]) {
// make the seed into [seed[0], seed[1], ..., seed[seed.len()
// - 1], 0, 0, ...], to fill rng.rsl.
let seed_iter = seed.iter().map(|&x| x).chain(repeat(0u64));
let seed_iter = seed.iter().cloned().chain(repeat(0u64));
for (rsl_elem, seed_elem) in self.rsl.iter_mut().zip(seed_iter) {
*rsl_elem = seed_elem;

View file

@ -89,7 +89,7 @@ struct PropagationContext<'a, 'b: 'a, 'tcx: 'b, O: 'a> {
}
fn to_cfgidx_or_die(id: ast::NodeId, index: &NodeMap<CFGIndex>) -> CFGIndex {
let opt_cfgindex = index.get(&id).map(|&i|i);
let opt_cfgindex = index.get(&id).cloned();
opt_cfgindex.unwrap_or_else(|| {
panic!("nodeid_to_index does not have entry for NodeId {}", id);
})
@ -400,7 +400,7 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
let mut changed = false;
for &node_id in &edge.data.exiting_scopes {
let opt_cfg_idx = self.nodeid_to_index.get(&node_id).map(|&i|i);
let opt_cfg_idx = self.nodeid_to_index.get(&node_id).cloned();
match opt_cfg_idx {
Some(cfg_idx) => {
let (start, end) = self.compute_id_range(cfg_idx);

View file

@ -113,7 +113,7 @@ impl<'tcx> Substs<'tcx> {
}
pub fn self_ty(&self) -> Option<Ty<'tcx>> {
self.types.get_self().map(|&t| t)
self.types.get_self().cloned()
}
pub fn with_self_ty(&self, self_ty: Ty<'tcx>) -> Substs<'tcx> {

View file

@ -57,7 +57,7 @@ pub fn is_object_safe<'tcx>(tcx: &ty::ctxt<'tcx>,
{
// Because we query yes/no results frequently, we keep a cache:
let cached_result =
tcx.object_safety_cache.borrow().get(&trait_ref.def_id()).map(|&r| r);
tcx.object_safety_cache.borrow().get(&trait_ref.def_id()).cloned();
let result =
cached_result.unwrap_or_else(|| {

View file

@ -1581,7 +1581,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ty::substd_enum_variants(self.tcx(), def_id, substs)
.iter()
.flat_map(|variant| variant.args.iter())
.map(|&ty| ty)
.cloned()
.collect();
nominal(self, bound, def_id, types)
}

View file

@ -4144,7 +4144,7 @@ pub fn positional_element_ty<'tcx>(cx: &ctxt<'tcx>,
variant: Option<ast::DefId>) -> Option<Ty<'tcx>> {
match (&ty.sty, variant) {
(&ty_tup(ref v), None) => v.get(i).map(|&t| t),
(&ty_tup(ref v), None) => v.get(i).cloned(),
(&ty_struct(def_id, substs), None) => lookup_struct_fields(cx, def_id)

View file

@ -208,7 +208,7 @@ pub fn trans_closure_expr<'a, 'tcx>(dest: Dest<'a, 'tcx>,
let function_type = typer.closure_type(closure_id, param_substs);
let freevars: Vec<ty::Freevar> =
ty::with_freevars(tcx, id, |fv| fv.iter().map(|&fv| fv).collect());
ty::with_freevars(tcx, id, |fv| fv.iter().cloned().collect());
let sig = ty::erase_late_bound_regions(tcx, &function_type.sig);

View file

@ -640,7 +640,7 @@ fn check_fn<'a, 'tcx>(ccx: &'a CrateCtxt<'a, 'tcx>,
// Remember return type so that regionck can access it later.
let mut fn_sig_tys: Vec<Ty> =
arg_tys.iter()
.map(|&ty| ty)
.cloned()
.collect();
if let ty::FnConverging(ret_ty) = ret_ty {

View file

@ -1172,7 +1172,7 @@ mod tests {
let exp: &[&[u8]] = &[$($exp),*];
assert_eq!(comps, exp);
let comps = path.components().rev().collect::<Vec<&[u8]>>();
let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&[u8]>>();
let exp = exp.iter().rev().cloned().collect::<Vec<&[u8]>>();
assert_eq!(comps, exp)
}
)
@ -1204,7 +1204,7 @@ mod tests {
let exp: &[Option<&str>] = &$exp;
assert_eq!(comps, exp);
let comps = path.str_components().rev().collect::<Vec<Option<&str>>>();
let exp = exp.iter().rev().map(|&x|x).collect::<Vec<Option<&str>>>();
let exp = exp.iter().rev().cloned().collect::<Vec<Option<&str>>>();
assert_eq!(comps, exp);
}
)

View file

@ -2226,7 +2226,7 @@ mod tests {
assert_eq!(comps, exp);
let comps = path.str_components().rev().map(|x|x.unwrap())
.collect::<Vec<&str>>();
let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&str>>();
let exp = exp.iter().rev().cloned().collect::<Vec<&str>>();
assert_eq!(comps, exp);
}
);
@ -2282,7 +2282,7 @@ mod tests {
let exp: &[&[u8]] = &$exp;
assert_eq!(comps, exp);
let comps = path.components().rev().collect::<Vec<&[u8]>>();
let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&[u8]>>();
let exp = exp.iter().rev().cloned().collect::<Vec<&[u8]>>();
assert_eq!(comps, exp);
}
)

View file

@ -547,7 +547,7 @@ mod test {
#[test]
fn test_choose() {
let mut r = thread_rng();
assert_eq!(r.choose(&[1, 1, 1]).map(|&x|x), Some(1));
assert_eq!(r.choose(&[1, 1, 1]).cloned(), Some(1));
let v: &[int] = &[];
assert_eq!(r.choose(v), None);

View file

@ -17,7 +17,7 @@ pub struct Registry {
impl Registry {
pub fn new(descriptions: &[(&'static str, &'static str)]) -> Registry {
Registry { descriptions: descriptions.iter().map(|&tuple| tuple).collect() }
Registry { descriptions: descriptions.iter().cloned().collect() }
}
pub fn find_description(&self, code: &str) -> Option<&'static str> {

View file

@ -1705,7 +1705,7 @@ impl<'a> Parser<'a> {
(true, LitBinary(parse::binary_lit(i.as_str()))),
token::BinaryRaw(i, _) =>
(true,
LitBinary(Rc::new(i.as_str().as_bytes().iter().map(|&x| x).collect()))),
LitBinary(Rc::new(i.as_str().as_bytes().iter().cloned().collect()))),
};
if suffix_illegal {

View file

@ -608,7 +608,7 @@ mod test {
Result<Vec<u8>, String>
{
let mut u8v: Vec<_> = fmt.bytes().collect();
u8v.extend(cap.as_bytes().iter().map(|&b| b));
u8v.extend(cap.bytes());
expand(&u8v, params, vars)
}

View file

@ -202,7 +202,7 @@ fn filter_masks(masks: &mut Vec<Vec<Vec<u64>>>) {
for i in 0..masks.len() {
for j in 0..(*masks)[i].len() {
masks[i][j] =
(*masks)[i][j].iter().map(|&m| m)
(*masks)[i][j].iter().cloned()
.filter(|&m| !is_board_unfeasible(m, masks))
.collect();
}