Skip to content

Commit 061206b

Browse files
committed
Remove usage of .map(|&foo| foo)
1 parent 2f586b9 commit 061206b

File tree

17 files changed

+44
-44
lines changed

17 files changed

+44
-44
lines changed

src/libcore/iter.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ pub trait IteratorExt: Iterator + Sized {
540540
///
541541
/// let a = [1, 4, 2, 3, 8, 9, 6];
542542
/// let sum = a.iter()
543-
/// .map(|&x| x)
543+
/// .cloned()
544544
/// .inspect(|&x| println!("filtering {}", x))
545545
/// .filter(|&x| x % 2 == 0)
546546
/// .inspect(|&x| println!("{} made it through", x))
@@ -579,7 +579,7 @@ pub trait IteratorExt: Iterator + Sized {
579579
///
580580
/// ```
581581
/// let a = [1, 2, 3, 4, 5];
582-
/// let b: Vec<_> = a.iter().map(|&x| x).collect();
582+
/// let b: Vec<_> = a.iter().cloned().collect();
583583
/// assert_eq!(a, b);
584584
/// ```
585585
#[inline]
@@ -955,7 +955,7 @@ pub trait IteratorExt: Iterator + Sized {
955955
///
956956
/// ```
957957
/// let a = [(1, 2), (3, 4)];
958-
/// let (left, right): (Vec<_>, Vec<_>) = a.iter().map(|&x| x).unzip();
958+
/// let (left, right): (Vec<_>, Vec<_>) = a.iter().cloned().unzip();
959959
/// assert_eq!([1, 3], left);
960960
/// assert_eq!([2, 4], right);
961961
/// ```
@@ -1160,7 +1160,7 @@ pub trait AdditiveIterator<A> {
11601160
/// use std::iter::AdditiveIterator;
11611161
///
11621162
/// let a = [1i32, 2, 3, 4, 5];
1163-
/// let mut it = a.iter().map(|&x| x);
1163+
/// let mut it = a.iter().cloned();
11641164
/// assert!(it.sum() == 15);
11651165
/// ```
11661166
fn sum(self) -> A;

src/libcoretest/iter.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ fn test_iterator_chain() {
9191
assert_eq!(i, expected.len());
9292

9393
let ys = count(30, 10).take(4);
94-
let mut it = xs.iter().map(|&x| x).chain(ys);
94+
let mut it = xs.iter().cloned().chain(ys);
9595
let mut i = 0;
9696
for x in it {
9797
assert_eq!(x, expected[i]);
@@ -119,7 +119,7 @@ fn test_iterator_enumerate() {
119119
#[test]
120120
fn test_iterator_peekable() {
121121
let xs = vec![0, 1, 2, 3, 4, 5];
122-
let mut it = xs.iter().map(|&x|x).peekable();
122+
let mut it = xs.iter().cloned().peekable();
123123

124124
assert_eq!(it.len(), 6);
125125
assert_eq!(it.peek().unwrap(), &0);
@@ -259,7 +259,7 @@ fn test_inspect() {
259259
let mut n = 0;
260260

261261
let ys = xs.iter()
262-
.map(|&x| x)
262+
.cloned()
263263
.inspect(|_| n += 1)
264264
.collect::<Vec<uint>>();
265265

@@ -329,33 +329,33 @@ fn test_iterator_len() {
329329
#[test]
330330
fn test_iterator_sum() {
331331
let v: &[i32] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
332-
assert_eq!(v[..4].iter().map(|&x| x).sum(), 6);
333-
assert_eq!(v.iter().map(|&x| x).sum(), 55);
334-
assert_eq!(v[..0].iter().map(|&x| x).sum(), 0);
332+
assert_eq!(v[..4].iter().cloned().sum(), 6);
333+
assert_eq!(v.iter().cloned().sum(), 55);
334+
assert_eq!(v[..0].iter().cloned().sum(), 0);
335335
}
336336

337337
#[test]
338338
fn test_iterator_product() {
339339
let v: &[i32] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
340-
assert_eq!(v[..4].iter().map(|&x| x).product(), 0);
341-
assert_eq!(v[1..5].iter().map(|&x| x).product(), 24);
342-
assert_eq!(v[..0].iter().map(|&x| x).product(), 1);
340+
assert_eq!(v[..4].iter().cloned().product(), 0);
341+
assert_eq!(v[1..5].iter().cloned().product(), 24);
342+
assert_eq!(v[..0].iter().cloned().product(), 1);
343343
}
344344

345345
#[test]
346346
fn test_iterator_max() {
347347
let v: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
348-
assert_eq!(v[..4].iter().map(|&x| x).max(), Some(3));
349-
assert_eq!(v.iter().map(|&x| x).max(), Some(10));
350-
assert_eq!(v[..0].iter().map(|&x| x).max(), None);
348+
assert_eq!(v[..4].iter().cloned().max(), Some(3));
349+
assert_eq!(v.iter().cloned().max(), Some(10));
350+
assert_eq!(v[..0].iter().cloned().max(), None);
351351
}
352352

353353
#[test]
354354
fn test_iterator_min() {
355355
let v: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
356-
assert_eq!(v[..4].iter().map(|&x| x).min(), Some(0));
357-
assert_eq!(v.iter().map(|&x| x).min(), Some(0));
358-
assert_eq!(v[..0].iter().map(|&x| x).min(), None);
356+
assert_eq!(v[..4].iter().cloned().min(), Some(0));
357+
assert_eq!(v.iter().cloned().min(), Some(0));
358+
assert_eq!(v[..0].iter().cloned().min(), None);
359359
}
360360

361361
#[test]
@@ -373,7 +373,7 @@ fn test_iterator_size_hint() {
373373
assert_eq!(c.clone().take_while(|_| false).size_hint(), (0, None));
374374
assert_eq!(c.clone().skip_while(|_| false).size_hint(), (0, None));
375375
assert_eq!(c.clone().enumerate().size_hint(), (uint::MAX, None));
376-
assert_eq!(c.clone().chain(vi.clone().map(|&i| i)).size_hint(), (uint::MAX, None));
376+
assert_eq!(c.clone().chain(vi.clone().cloned()).size_hint(), (uint::MAX, None));
377377
assert_eq!(c.clone().zip(vi.clone()).size_hint(), (10, Some(10)));
378378
assert_eq!(c.clone().scan(0, |_,_| Some(0)).size_hint(), (0, None));
379379
assert_eq!(c.clone().filter(|_| false).size_hint(), (0, None));
@@ -398,7 +398,7 @@ fn test_iterator_size_hint() {
398398
#[test]
399399
fn test_collect() {
400400
let a = vec![1, 2, 3, 4, 5];
401-
let b: Vec<int> = a.iter().map(|&x| x).collect();
401+
let b: Vec<int> = a.iter().cloned().collect();
402402
assert!(a == b);
403403
}
404404

@@ -471,7 +471,7 @@ fn test_rev() {
471471
let mut it = xs.iter();
472472
it.next();
473473
it.next();
474-
assert!(it.rev().map(|&x| x).collect::<Vec<int>>() ==
474+
assert!(it.rev().cloned().collect::<Vec<int>>() ==
475475
vec![16, 14, 12, 10, 8, 6]);
476476
}
477477

@@ -508,7 +508,7 @@ fn test_double_ended_map() {
508508
#[test]
509509
fn test_double_ended_enumerate() {
510510
let xs = [1, 2, 3, 4, 5, 6];
511-
let mut it = xs.iter().map(|&x| x).enumerate();
511+
let mut it = xs.iter().cloned().enumerate();
512512
assert_eq!(it.next(), Some((0, 1)));
513513
assert_eq!(it.next(), Some((1, 2)));
514514
assert_eq!(it.next_back(), Some((5, 6)));
@@ -522,8 +522,8 @@ fn test_double_ended_enumerate() {
522522
fn test_double_ended_zip() {
523523
let xs = [1, 2, 3, 4, 5, 6];
524524
let ys = [1, 2, 3, 7];
525-
let a = xs.iter().map(|&x| x);
526-
let b = ys.iter().map(|&x| x);
525+
let a = xs.iter().cloned();
526+
let b = ys.iter().cloned();
527527
let mut it = a.zip(b);
528528
assert_eq!(it.next(), Some((1, 1)));
529529
assert_eq!(it.next(), Some((2, 2)));

src/librand/isaac.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ impl<'a> SeedableRng<&'a [u32]> for IsaacRng {
215215
fn reseed(&mut self, seed: &'a [u32]) {
216216
// make the seed into [seed[0], seed[1], ..., seed[seed.len()
217217
// - 1], 0, 0, ...], to fill rng.rsl.
218-
let seed_iter = seed.iter().map(|&x| x).chain(repeat(0u32));
218+
let seed_iter = seed.iter().cloned().chain(repeat(0u32));
219219

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

463463
for (rsl_elem, seed_elem) in self.rsl.iter_mut().zip(seed_iter) {
464464
*rsl_elem = seed_elem;

src/librustc/middle/dataflow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ struct PropagationContext<'a, 'b: 'a, 'tcx: 'b, O: 'a> {
8989
}
9090

9191
fn to_cfgidx_or_die(id: ast::NodeId, index: &NodeMap<CFGIndex>) -> CFGIndex {
92-
let opt_cfgindex = index.get(&id).map(|&i|i);
92+
let opt_cfgindex = index.get(&id).cloned();
9393
opt_cfgindex.unwrap_or_else(|| {
9494
panic!("nodeid_to_index does not have entry for NodeId {}", id);
9595
})
@@ -400,7 +400,7 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
400400

401401
let mut changed = false;
402402
for &node_id in &edge.data.exiting_scopes {
403-
let opt_cfg_idx = self.nodeid_to_index.get(&node_id).map(|&i|i);
403+
let opt_cfg_idx = self.nodeid_to_index.get(&node_id).cloned();
404404
match opt_cfg_idx {
405405
Some(cfg_idx) => {
406406
let (start, end) = self.compute_id_range(cfg_idx);

src/librustc/middle/subst.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl<'tcx> Substs<'tcx> {
113113
}
114114

115115
pub fn self_ty(&self) -> Option<Ty<'tcx>> {
116-
self.types.get_self().map(|&t| t)
116+
self.types.get_self().cloned()
117117
}
118118

119119
pub fn with_self_ty(&self, self_ty: Ty<'tcx>) -> Substs<'tcx> {

src/librustc/middle/traits/object_safety.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn is_object_safe<'tcx>(tcx: &ty::ctxt<'tcx>,
5757
{
5858
// Because we query yes/no results frequently, we keep a cache:
5959
let cached_result =
60-
tcx.object_safety_cache.borrow().get(&trait_ref.def_id()).map(|&r| r);
60+
tcx.object_safety_cache.borrow().get(&trait_ref.def_id()).cloned();
6161

6262
let result =
6363
cached_result.unwrap_or_else(|| {

src/librustc/middle/traits/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15811581
ty::substd_enum_variants(self.tcx(), def_id, substs)
15821582
.iter()
15831583
.flat_map(|variant| variant.args.iter())
1584-
.map(|&ty| ty)
1584+
.cloned()
15851585
.collect();
15861586
nominal(self, bound, def_id, types)
15871587
}

src/librustc/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4144,7 +4144,7 @@ pub fn positional_element_ty<'tcx>(cx: &ctxt<'tcx>,
41444144
variant: Option<ast::DefId>) -> Option<Ty<'tcx>> {
41454145

41464146
match (&ty.sty, variant) {
4147-
(&ty_tup(ref v), None) => v.get(i).map(|&t| t),
4147+
(&ty_tup(ref v), None) => v.get(i).cloned(),
41484148

41494149

41504150
(&ty_struct(def_id, substs), None) => lookup_struct_fields(cx, def_id)

src/librustc_trans/trans/closure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ pub fn trans_closure_expr<'a, 'tcx>(dest: Dest<'a, 'tcx>,
208208
let function_type = typer.closure_type(closure_id, param_substs);
209209

210210
let freevars: Vec<ty::Freevar> =
211-
ty::with_freevars(tcx, id, |fv| fv.iter().map(|&fv| fv).collect());
211+
ty::with_freevars(tcx, id, |fv| fv.iter().cloned().collect());
212212

213213
let sig = ty::erase_late_bound_regions(tcx, &function_type.sig);
214214

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ fn check_fn<'a, 'tcx>(ccx: &'a CrateCtxt<'a, 'tcx>,
640640
// Remember return type so that regionck can access it later.
641641
let mut fn_sig_tys: Vec<Ty> =
642642
arg_tys.iter()
643-
.map(|&ty| ty)
643+
.cloned()
644644
.collect();
645645

646646
if let ty::FnConverging(ret_ty) = ret_ty {

src/libstd/old_path/posix.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ mod tests {
11721172
let exp: &[&[u8]] = &[$($exp),*];
11731173
assert_eq!(comps, exp);
11741174
let comps = path.components().rev().collect::<Vec<&[u8]>>();
1175-
let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&[u8]>>();
1175+
let exp = exp.iter().rev().cloned().collect::<Vec<&[u8]>>();
11761176
assert_eq!(comps, exp)
11771177
}
11781178
)
@@ -1204,7 +1204,7 @@ mod tests {
12041204
let exp: &[Option<&str>] = &$exp;
12051205
assert_eq!(comps, exp);
12061206
let comps = path.str_components().rev().collect::<Vec<Option<&str>>>();
1207-
let exp = exp.iter().rev().map(|&x|x).collect::<Vec<Option<&str>>>();
1207+
let exp = exp.iter().rev().cloned().collect::<Vec<Option<&str>>>();
12081208
assert_eq!(comps, exp);
12091209
}
12101210
)

src/libstd/old_path/windows.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,7 +2226,7 @@ mod tests {
22262226
assert_eq!(comps, exp);
22272227
let comps = path.str_components().rev().map(|x|x.unwrap())
22282228
.collect::<Vec<&str>>();
2229-
let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&str>>();
2229+
let exp = exp.iter().rev().cloned().collect::<Vec<&str>>();
22302230
assert_eq!(comps, exp);
22312231
}
22322232
);
@@ -2282,7 +2282,7 @@ mod tests {
22822282
let exp: &[&[u8]] = &$exp;
22832283
assert_eq!(comps, exp);
22842284
let comps = path.components().rev().collect::<Vec<&[u8]>>();
2285-
let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&[u8]>>();
2285+
let exp = exp.iter().rev().cloned().collect::<Vec<&[u8]>>();
22862286
assert_eq!(comps, exp);
22872287
}
22882288
)

src/libstd/rand/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ mod test {
547547
#[test]
548548
fn test_choose() {
549549
let mut r = thread_rng();
550-
assert_eq!(r.choose(&[1, 1, 1]).map(|&x|x), Some(1));
550+
assert_eq!(r.choose(&[1, 1, 1]).cloned(), Some(1));
551551

552552
let v: &[int] = &[];
553553
assert_eq!(r.choose(v), None);

src/libsyntax/diagnostics/registry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub struct Registry {
1717

1818
impl Registry {
1919
pub fn new(descriptions: &[(&'static str, &'static str)]) -> Registry {
20-
Registry { descriptions: descriptions.iter().map(|&tuple| tuple).collect() }
20+
Registry { descriptions: descriptions.iter().cloned().collect() }
2121
}
2222

2323
pub fn find_description(&self, code: &str) -> Option<&'static str> {

src/libsyntax/parse/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,7 @@ impl<'a> Parser<'a> {
17051705
(true, LitBinary(parse::binary_lit(i.as_str()))),
17061706
token::BinaryRaw(i, _) =>
17071707
(true,
1708-
LitBinary(Rc::new(i.as_str().as_bytes().iter().map(|&x| x).collect()))),
1708+
LitBinary(Rc::new(i.as_str().as_bytes().iter().cloned().collect()))),
17091709
};
17101710

17111711
if suffix_illegal {

src/libterm/terminfo/parm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ mod test {
608608
Result<Vec<u8>, String>
609609
{
610610
let mut u8v: Vec<_> = fmt.bytes().collect();
611-
u8v.extend(cap.as_bytes().iter().map(|&b| b));
611+
u8v.extend(cap.bytes());
612612
expand(&u8v, params, vars)
613613
}
614614

src/test/bench/shootout-meteor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ fn filter_masks(masks: &mut Vec<Vec<Vec<u64>>>) {
202202
for i in 0..masks.len() {
203203
for j in 0..(*masks)[i].len() {
204204
masks[i][j] =
205-
(*masks)[i][j].iter().map(|&m| m)
205+
(*masks)[i][j].iter().cloned()
206206
.filter(|&m| !is_board_unfeasible(m, masks))
207207
.collect();
208208
}

0 commit comments

Comments
 (0)