Skip to content

Commit c6a647a

Browse files
committed
Replace map(|x| *x) with cloned().
This partially resolves rust-lang#22243.
1 parent cf636c2 commit c6a647a

File tree

19 files changed

+25
-25
lines changed

19 files changed

+25
-25
lines changed

src/libcollections/bit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,7 +2282,7 @@ mod tests {
22822282
#[test]
22832283
fn test_from_bools() {
22842284
let bools = vec![true, false, true, true];
2285-
let bitv: Bitv = bools.iter().map(|n| *n).collect();
2285+
let bitv: Bitv = bools.iter().cloned().collect();
22862286
assert_eq!(format!("{:?}", bitv), "1011");
22872287
}
22882288

@@ -2295,12 +2295,12 @@ mod tests {
22952295
#[test]
22962296
fn test_bitv_iterator() {
22972297
let bools = vec![true, false, true, true];
2298-
let bitv: Bitv = bools.iter().map(|n| *n).collect();
2298+
let bitv: Bitv = bools.iter().cloned().collect();
22992299

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

23022302
let long: Vec<_> = (0i32..10000).map(|i| i % 2 == 0).collect();
2303-
let bitv: Bitv = long.iter().map(|n| *n).collect();
2303+
let bitv: Bitv = long.iter().cloned().collect();
23042304
assert_eq!(bitv.iter().collect::<Vec<bool>>(), long)
23052305
}
23062306

src/libcore/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ pub trait IteratorExt: Iterator + Sized {
325325
///
326326
/// ```
327327
/// let xs = [100, 200, 300];
328-
/// let mut it = xs.iter().map(|x| *x).peekable();
328+
/// let mut it = xs.iter().cloned().peekable();
329329
/// assert_eq!(*it.peek().unwrap(), 100);
330330
/// assert_eq!(it.next().unwrap(), 100);
331331
/// 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl CStore {
218218

219219
pub fn find_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId)
220220
-> Option<ast::CrateNum> {
221-
self.extern_mod_crate_map.borrow().get(&emod_id).map(|x| *x)
221+
self.extern_mod_crate_map.borrow().get(&emod_id).cloned()
222222
}
223223
}
224224

src/librustc/middle/check_match.rs

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

78-
let total_width = column_widths.iter().map(|n| *n).sum() + column_count * 3 + 1;
78+
let total_width = column_widths.iter().cloned().sum() + column_count * 3 + 1;
7979
let br = repeat('+').take(total_width).collect::<String>();
8080
try!(write!(f, "{}\n", br));
8181
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
@@ -600,7 +600,7 @@ pub fn lit_to_const(lit: &ast::Lit) -> const_val {
600600
match lit.node {
601601
ast::LitStr(ref s, _) => const_str((*s).clone()),
602602
ast::LitBinary(ref data) => {
603-
const_binary(Rc::new(data.iter().map(|x| *x).collect()))
603+
const_binary(Rc::new(data.iter().cloned().collect()))
604604
}
605605
ast::LitByte(n) => const_uint(n as u64),
606606
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
}

src/librustc/middle/lang_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'a, 'v> Visitor<'v> for LanguageItemCollector<'a> {
149149
fn visit_item(&mut self, item: &ast::Item) {
150150
match extract(&item.attrs) {
151151
Some(value) => {
152-
let item_index = self.item_refs.get(&value[]).map(|x| *x);
152+
let item_index = self.item_refs.get(&value[]).cloned();
153153

154154
match item_index {
155155
Some(item_index) => {

src/librustc/middle/region.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ impl RegionMaps {
407407

408408
pub fn opt_encl_scope(&self, id: CodeExtent) -> Option<CodeExtent> {
409409
//! Returns the narrowest scope that encloses `id`, if any.
410-
self.scope_map.borrow().get(&id).map(|x| *x)
410+
self.scope_map.borrow().get(&id).cloned()
411411
}
412412

413413
#[allow(dead_code)] // used in middle::cfg

src/librustc/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4944,7 +4944,7 @@ pub fn note_and_explain_type_err(cx: &ctxt, err: &type_err) {
49444944
}
49454945

49464946
pub fn provided_source(cx: &ctxt, id: ast::DefId) -> Option<ast::DefId> {
4947-
cx.provided_method_sources.borrow().get(&id).map(|x| *x)
4947+
cx.provided_method_sources.borrow().get(&id).cloned()
49484948
}
49494949

49504950
pub fn provided_trait_methods<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId)

src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3223,7 +3223,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
32233223
for field in ast_fields {
32243224
let mut expected_field_type = tcx.types.err;
32253225

3226-
let pair = class_field_map.get(&field.ident.node.name).map(|x| *x);
3226+
let pair = class_field_map.get(&field.ident.node.name).cloned();
32273227
match pair {
32283228
None => {
32293229
fcx.type_error_message(
@@ -3871,7 +3871,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
38713871
}
38723872
ast::ExprStruct(ref path, ref fields, ref base_expr) => {
38733873
// Resolve the path.
3874-
let def = tcx.def_map.borrow().get(&id).map(|i| *i);
3874+
let def = tcx.def_map.borrow().get(&id).cloned();
38753875
let struct_id = match def {
38763876
Some(def::DefVariant(enum_id, variant_id, true)) => {
38773877
check_struct_enum_variant(fcx, id, expr.span, enum_id,

src/libstd/env.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ mod tests {
918918
#[cfg(unix)]
919919
fn join_paths_unix() {
920920
fn test_eq(input: &[&str], output: &str) -> bool {
921-
&*join_paths(input.iter().map(|s| *s)).unwrap() ==
921+
&*join_paths(input.iter().cloned()).unwrap() ==
922922
OsStr::from_str(output)
923923
}
924924

@@ -927,14 +927,14 @@ mod tests {
927927
"/bin:/usr/bin:/usr/local/bin"));
928928
assert!(test_eq(&["", "/bin", "", "", "/usr/bin", ""],
929929
":/bin:::/usr/bin:"));
930-
assert!(join_paths(["/te:st"].iter().map(|s| *s)).is_err());
930+
assert!(join_paths(["/te:st"].iter().cloned()).is_err());
931931
}
932932

933933
#[test]
934934
#[cfg(windows)]
935935
fn join_paths_windows() {
936936
fn test_eq(input: &[&str], output: &str) -> bool {
937-
&*join_paths(input.iter().map(|s| *s)).unwrap() ==
937+
&*join_paths(input.iter().cloned()).unwrap() ==
938938
OsStr::from_str(output)
939939
}
940940

@@ -945,6 +945,6 @@ mod tests {
945945
r";c:\windows;;;c:\;"));
946946
assert!(test_eq(&[r"c:\te;st", r"c:\"],
947947
r#""c:\te;st";c:\"#));
948-
assert!(join_paths([r#"c:\te"st"#].iter().map(|s| *s)).is_err());
948+
assert!(join_paths([r#"c:\te"st"#].iter().cloned()).is_err());
949949
}
950950
}

src/libstd/sys/windows/thread_local.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ unsafe fn run_dtors() {
244244
let ret = if DTORS.is_null() {
245245
Vec::new()
246246
} else {
247-
(*DTORS).iter().map(|s| *s).collect()
247+
(*DTORS).iter().cloned().collect()
248248
};
249249
DTOR_LOCK.unlock();
250250
ret

src/libsyntax/ast_map/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl<'ast> Map<'ast> {
251251
}
252252

253253
fn find_entry(&self, id: NodeId) -> Option<MapEntry<'ast>> {
254-
self.map.borrow().get(id as usize).map(|e| *e)
254+
self.map.borrow().get(id as usize).cloned()
255255
}
256256

257257
pub fn krate(&self) -> &'ast Crate {

src/libsyntax/ext/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ impl<'a> ExtCtxt<'a> {
639639
pub fn mod_path(&self) -> Vec<ast::Ident> {
640640
let mut v = Vec::new();
641641
v.push(token::str_to_ident(&self.ecfg.crate_name[]));
642-
v.extend(self.mod_path.iter().map(|a| *a));
642+
v.extend(self.mod_path.iter().cloned());
643643
return v;
644644
}
645645
pub fn bt_push(&mut self, ei: ExpnInfo) {

src/libsyntax/ext/source_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
179179
return DummyResult::expr(sp);
180180
}
181181
Ok(bytes) => {
182-
let bytes = bytes.iter().map(|x| *x).collect();
182+
let bytes = bytes.iter().cloned().collect();
183183
base::MacExpr::new(cx.expr_lit(sp, ast::LitBinary(Rc::new(bytes))))
184184
}
185185
}

src/libtest/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ fn calc_result(desc: &TestDesc, task_result: Result<(), Box<Any+Send>>) -> TestR
938938
(&ShouldFail::Yes(Some(msg)), Err(ref err))
939939
if err.downcast_ref::<String>()
940940
.map(|e| &**e)
941-
.or_else(|| err.downcast_ref::<&'static str>().map(|e| *e))
941+
.or_else(|| err.downcast_ref::<&'static str>().cloned())
942942
.map(|e| e.contains(msg))
943943
.unwrap_or(false) => TrOk,
944944
_ => TrFailed,

src/test/bench/shootout-fasta.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fn run<W: Writer>(writer: &mut W) -> std::old_io::IoResult<()> {
133133
('t', 0.3015094502008)];
134134

135135
try!(make_fasta(writer, ">ONE Homo sapiens alu\n",
136-
alu.as_bytes().iter().cycle().map(|c| *c), n * 2));
136+
alu.as_bytes().iter().cycle().cloned(), n * 2));
137137
try!(make_fasta(writer, ">TWO IUB ambiguity codes\n",
138138
AAGen::new(rng, iub), n * 3));
139139
try!(make_fasta(writer, ">THREE Homo sapiens frequency\n",

src/test/bench/shootout-meteor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ fn handle_sol(raw_sol: &List<u64>, data: &mut Data) {
270270
// reverse order, i.e. the board rotated by half a turn.
271271
data.nb += 2;
272272
let sol1 = to_vec(raw_sol);
273-
let sol2: Vec<u8> = sol1.iter().rev().map(|x| *x).collect();
273+
let sol2: Vec<u8> = sol1.iter().rev().cloned().collect();
274274

275275
if data.nb == 2 {
276276
data.min = sol1.clone();

0 commit comments

Comments
 (0)