Skip to content

Commit 2f586b9

Browse files
committed
Opt for .cloned() over .map(|x| x.clone()) etc.
1 parent 5705d48 commit 2f586b9

File tree

39 files changed

+68
-82
lines changed

39 files changed

+68
-82
lines changed

src/compiletest/compiletest.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#![feature(test)]
2222
#![feature(unicode)]
2323
#![feature(env)]
24+
#![feature(core)]
2425

2526
#![deny(warnings)]
2627

src/compiletest/runtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ fn compile_test_(config: &Config, props: &TestProps,
11331133
// FIXME (#9639): This needs to handle non-utf8 paths
11341134
let mut link_args = vec!("-L".to_string(),
11351135
aux_dir.as_str().unwrap().to_string());
1136-
link_args.extend(extra_args.iter().map(|s| s.clone()));
1136+
link_args.extend(extra_args.iter().cloned());
11371137
let args = make_compile_args(config,
11381138
props,
11391139
link_args,

src/libcollections/bit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,7 +2306,7 @@ mod tests {
23062306
#[test]
23072307
fn test_from_bools() {
23082308
let bools = vec![true, false, true, true];
2309-
let bitv: Bitv = bools.iter().map(|n| *n).collect();
2309+
let bitv: Bitv = bools.iter().cloned().collect();
23102310
assert_eq!(format!("{:?}", bitv), "1011");
23112311
}
23122312

@@ -2319,12 +2319,12 @@ mod tests {
23192319
#[test]
23202320
fn test_bitv_iterator() {
23212321
let bools = vec![true, false, true, true];
2322-
let bitv: Bitv = bools.iter().map(|n| *n).collect();
2322+
let bitv: Bitv = bools.iter().cloned().collect();
23232323

23242324
assert_eq!(bitv.iter().collect::<Vec<bool>>(), bools);
23252325

23262326
let long: Vec<_> = (0i32..10000).map(|i| i % 2 == 0).collect();
2327-
let bitv: Bitv = long.iter().map(|n| *n).collect();
2327+
let bitv: Bitv = long.iter().cloned().collect();
23282328
assert_eq!(bitv.iter().collect::<Vec<bool>>(), long)
23292329
}
23302330

src/libcollections/dlist.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ impl<A: Ord> Ord for DList<A> {
938938
#[stable(feature = "rust1", since = "1.0.0")]
939939
impl<A: Clone> Clone for DList<A> {
940940
fn clone(&self) -> DList<A> {
941-
self.iter().map(|x| x.clone()).collect()
941+
self.iter().cloned().collect()
942942
}
943943
}
944944

@@ -1056,7 +1056,7 @@ mod tests {
10561056

10571057
#[cfg(test)]
10581058
fn list_from<T: Clone>(v: &[T]) -> DList<T> {
1059-
v.iter().map(|x| (*x).clone()).collect()
1059+
v.iter().cloned().collect()
10601060
}
10611061

10621062
#[test]

src/libcore/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ pub trait IteratorExt: Iterator + Sized {
350350
///
351351
/// ```
352352
/// let xs = [100, 200, 300];
353-
/// let mut it = xs.iter().map(|x| *x).peekable();
353+
/// let mut it = xs.iter().cloned().peekable();
354354
/// assert_eq!(*it.peek().unwrap(), 100);
355355
/// assert_eq!(it.next().unwrap(), 100);
356356
/// assert_eq!(it.next().unwrap(), 200);

src/libcoretest/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ fn test_random_access_inspect() {
713713
fn test_random_access_map() {
714714
let xs = [1, 2, 3, 4, 5];
715715

716-
let mut it = xs.iter().map(|x| *x);
716+
let mut it = xs.iter().cloned();
717717
assert_eq!(xs.len(), it.indexable());
718718
for (i, elt) in xs.iter().enumerate() {
719719
assert_eq!(Some(*elt), it.idx(i));

src/librustc/metadata/cstore.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ impl CStore {
139139
pub fn get_used_crate_source(&self, cnum: ast::CrateNum)
140140
-> Option<CrateSource> {
141141
self.used_crate_sources.borrow_mut()
142-
.iter().find(|source| source.cnum == cnum)
143-
.map(|source| source.clone())
142+
.iter().find(|source| source.cnum == cnum).cloned()
144143
}
145144

146145
pub fn reset(&self) {
@@ -218,7 +217,7 @@ impl CStore {
218217

219218
pub fn find_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId)
220219
-> Option<ast::CrateNum> {
221-
self.extern_mod_crate_map.borrow().get(&emod_id).map(|x| *x)
220+
self.extern_mod_crate_map.borrow().get(&emod_id).cloned()
222221
}
223222
}
224223

src/librustc/middle/check_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<'a> fmt::Debug for Matrix<'a> {
7676
pretty_printed_matrix.iter().map(|row| row[col].len()).max().unwrap_or(0)
7777
}).collect();
7878

79-
let total_width = column_widths.iter().map(|n| *n).sum() + column_count * 3 + 1;
79+
let total_width = column_widths.iter().cloned().sum() + column_count * 3 + 1;
8080
let br = repeat('+').take(total_width).collect::<String>();
8181
try!(write!(f, "{}\n", br));
8282
for row in pretty_printed_matrix {

src/librustc/middle/const_eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ fn lit_to_const(lit: &ast::Lit, ty_hint: Option<Ty>) -> const_val {
501501
match lit.node {
502502
ast::LitStr(ref s, _) => const_str((*s).clone()),
503503
ast::LitBinary(ref data) => {
504-
const_binary(Rc::new(data.iter().map(|x| *x).collect()))
504+
const_binary(data.clone())
505505
}
506506
ast::LitByte(n) => const_uint(n as u64),
507507
ast::LitChar(n) => const_uint(n as u64),

src/librustc/middle/dependency_format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ fn calculate_type(sess: &session::Session,
158158

159159
// Collect what we've got so far in the return vector.
160160
let mut ret = (1..sess.cstore.next_crate_num()).map(|i| {
161-
match formats.get(&i).map(|v| *v) {
161+
match formats.get(&i).cloned() {
162162
v @ Some(cstore::RequireDynamic) => v,
163163
_ => None,
164164
}

0 commit comments

Comments
 (0)