From c6a647af6aa42db4737c16bec2a8cd2db91da443 Mon Sep 17 00:00:00 2001 From: Ruud van Asseldonk Date: Fri, 13 Feb 2015 13:50:53 +0100 Subject: [PATCH 1/4] Replace map(|x| *x) with cloned(). This partially resolves #22243. --- src/libcollections/bit.rs | 6 +++--- src/libcore/iter.rs | 2 +- src/libcoretest/iter.rs | 2 +- src/librustc/metadata/cstore.rs | 2 +- src/librustc/middle/check_match.rs | 2 +- src/librustc/middle/const_eval.rs | 2 +- src/librustc/middle/dependency_format.rs | 2 +- src/librustc/middle/lang_items.rs | 2 +- src/librustc/middle/region.rs | 2 +- src/librustc/middle/ty.rs | 2 +- src/librustc_typeck/check/mod.rs | 4 ++-- src/libstd/env.rs | 8 ++++---- src/libstd/sys/windows/thread_local.rs | 2 +- src/libsyntax/ast_map/mod.rs | 2 +- src/libsyntax/ext/base.rs | 2 +- src/libsyntax/ext/source_util.rs | 2 +- src/libtest/lib.rs | 2 +- src/test/bench/shootout-fasta.rs | 2 +- src/test/bench/shootout-meteor.rs | 2 +- 19 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index 6d15a264172a1..2488973565b9d 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -2282,7 +2282,7 @@ mod tests { #[test] fn test_from_bools() { let bools = vec![true, false, true, true]; - let bitv: Bitv = bools.iter().map(|n| *n).collect(); + let bitv: Bitv = bools.iter().cloned().collect(); assert_eq!(format!("{:?}", bitv), "1011"); } @@ -2295,12 +2295,12 @@ mod tests { #[test] fn test_bitv_iterator() { let bools = vec![true, false, true, true]; - let bitv: Bitv = bools.iter().map(|n| *n).collect(); + let bitv: Bitv = bools.iter().cloned().collect(); assert_eq!(bitv.iter().collect::>(), bools); let long: Vec<_> = (0i32..10000).map(|i| i % 2 == 0).collect(); - let bitv: Bitv = long.iter().map(|n| *n).collect(); + let bitv: Bitv = long.iter().cloned().collect(); assert_eq!(bitv.iter().collect::>(), long) } diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 7740cd6867cbd..ac2db815fceb1 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -325,7 +325,7 @@ pub trait IteratorExt: Iterator + Sized { /// /// ``` /// let xs = [100, 200, 300]; - /// let mut it = xs.iter().map(|x| *x).peekable(); + /// let mut it = xs.iter().cloned().peekable(); /// assert_eq!(*it.peek().unwrap(), 100); /// assert_eq!(it.next().unwrap(), 100); /// assert_eq!(it.next().unwrap(), 200); diff --git a/src/libcoretest/iter.rs b/src/libcoretest/iter.rs index 7eb0fb97bed2a..88777da0bcd35 100644 --- a/src/libcoretest/iter.rs +++ b/src/libcoretest/iter.rs @@ -713,7 +713,7 @@ fn test_random_access_inspect() { fn test_random_access_map() { let xs = [1, 2, 3, 4, 5]; - let mut it = xs.iter().map(|x| *x); + let mut it = xs.iter().cloned(); assert_eq!(xs.len(), it.indexable()); for (i, elt) in xs.iter().enumerate() { assert_eq!(Some(*elt), it.idx(i)); diff --git a/src/librustc/metadata/cstore.rs b/src/librustc/metadata/cstore.rs index 0a3e173b35ee5..8673aec552dcb 100644 --- a/src/librustc/metadata/cstore.rs +++ b/src/librustc/metadata/cstore.rs @@ -218,7 +218,7 @@ impl CStore { pub fn find_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option { - self.extern_mod_crate_map.borrow().get(&emod_id).map(|x| *x) + self.extern_mod_crate_map.borrow().get(&emod_id).cloned() } } diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 7ac690f02e1b5..ba40798af3f0b 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -75,7 +75,7 @@ impl<'a> fmt::Debug for Matrix<'a> { pretty_printed_matrix.iter().map(|row| row[col].len()).max().unwrap_or(0) }).collect(); - let total_width = column_widths.iter().map(|n| *n).sum() + column_count * 3 + 1; + let total_width = column_widths.iter().cloned().sum() + column_count * 3 + 1; let br = repeat('+').take(total_width).collect::(); try!(write!(f, "{}\n", br)); for row in pretty_printed_matrix { diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index a6a647173faa7..c4e1d9a64bd96 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -600,7 +600,7 @@ pub fn lit_to_const(lit: &ast::Lit) -> const_val { match lit.node { ast::LitStr(ref s, _) => const_str((*s).clone()), ast::LitBinary(ref data) => { - const_binary(Rc::new(data.iter().map(|x| *x).collect())) + const_binary(Rc::new(data.iter().cloned().collect())) } ast::LitByte(n) => const_uint(n as u64), ast::LitChar(n) => const_uint(n as u64), diff --git a/src/librustc/middle/dependency_format.rs b/src/librustc/middle/dependency_format.rs index 6d35a82d153cd..ad9f4eade5c90 100644 --- a/src/librustc/middle/dependency_format.rs +++ b/src/librustc/middle/dependency_format.rs @@ -158,7 +158,7 @@ fn calculate_type(sess: &session::Session, // Collect what we've got so far in the return vector. let mut ret = (1..sess.cstore.next_crate_num()).map(|i| { - match formats.get(&i).map(|v| *v) { + match formats.get(&i).cloned() { v @ Some(cstore::RequireDynamic) => v, _ => None, } diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index ef72c2242c1e7..b9255f75ed613 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -149,7 +149,7 @@ impl<'a, 'v> Visitor<'v> for LanguageItemCollector<'a> { fn visit_item(&mut self, item: &ast::Item) { match extract(&item.attrs) { Some(value) => { - let item_index = self.item_refs.get(&value[]).map(|x| *x); + let item_index = self.item_refs.get(&value[]).cloned(); match item_index { Some(item_index) => { diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 2f0462ab8c338..e539f6ae6cb93 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -407,7 +407,7 @@ impl RegionMaps { pub fn opt_encl_scope(&self, id: CodeExtent) -> Option { //! Returns the narrowest scope that encloses `id`, if any. - self.scope_map.borrow().get(&id).map(|x| *x) + self.scope_map.borrow().get(&id).cloned() } #[allow(dead_code)] // used in middle::cfg diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 6026359ddace0..2a1dd1ba16e32 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -4944,7 +4944,7 @@ pub fn note_and_explain_type_err(cx: &ctxt, err: &type_err) { } pub fn provided_source(cx: &ctxt, id: ast::DefId) -> Option { - cx.provided_method_sources.borrow().get(&id).map(|x| *x) + cx.provided_method_sources.borrow().get(&id).cloned() } pub fn provided_trait_methods<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index d12b23187b80b..5b75e06c88706 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3223,7 +3223,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>, for field in ast_fields { let mut expected_field_type = tcx.types.err; - let pair = class_field_map.get(&field.ident.node.name).map(|x| *x); + let pair = class_field_map.get(&field.ident.node.name).cloned(); match pair { None => { fcx.type_error_message( @@ -3871,7 +3871,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>, } ast::ExprStruct(ref path, ref fields, ref base_expr) => { // Resolve the path. - let def = tcx.def_map.borrow().get(&id).map(|i| *i); + let def = tcx.def_map.borrow().get(&id).cloned(); let struct_id = match def { Some(def::DefVariant(enum_id, variant_id, true)) => { check_struct_enum_variant(fcx, id, expr.span, enum_id, diff --git a/src/libstd/env.rs b/src/libstd/env.rs index ea18838211f26..bfc1afc6eb4f2 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -918,7 +918,7 @@ mod tests { #[cfg(unix)] fn join_paths_unix() { fn test_eq(input: &[&str], output: &str) -> bool { - &*join_paths(input.iter().map(|s| *s)).unwrap() == + &*join_paths(input.iter().cloned()).unwrap() == OsStr::from_str(output) } @@ -927,14 +927,14 @@ mod tests { "/bin:/usr/bin:/usr/local/bin")); assert!(test_eq(&["", "/bin", "", "", "/usr/bin", ""], ":/bin:::/usr/bin:")); - assert!(join_paths(["/te:st"].iter().map(|s| *s)).is_err()); + assert!(join_paths(["/te:st"].iter().cloned()).is_err()); } #[test] #[cfg(windows)] fn join_paths_windows() { fn test_eq(input: &[&str], output: &str) -> bool { - &*join_paths(input.iter().map(|s| *s)).unwrap() == + &*join_paths(input.iter().cloned()).unwrap() == OsStr::from_str(output) } @@ -945,6 +945,6 @@ mod tests { r";c:\windows;;;c:\;")); assert!(test_eq(&[r"c:\te;st", r"c:\"], r#""c:\te;st";c:\"#)); - assert!(join_paths([r#"c:\te"st"#].iter().map(|s| *s)).is_err()); + assert!(join_paths([r#"c:\te"st"#].iter().cloned()).is_err()); } } diff --git a/src/libstd/sys/windows/thread_local.rs b/src/libstd/sys/windows/thread_local.rs index 0c24ab1fa09b4..c11d16df61564 100644 --- a/src/libstd/sys/windows/thread_local.rs +++ b/src/libstd/sys/windows/thread_local.rs @@ -244,7 +244,7 @@ unsafe fn run_dtors() { let ret = if DTORS.is_null() { Vec::new() } else { - (*DTORS).iter().map(|s| *s).collect() + (*DTORS).iter().cloned().collect() }; DTOR_LOCK.unlock(); ret diff --git a/src/libsyntax/ast_map/mod.rs b/src/libsyntax/ast_map/mod.rs index 5535e5911e0c2..6535705388d01 100644 --- a/src/libsyntax/ast_map/mod.rs +++ b/src/libsyntax/ast_map/mod.rs @@ -251,7 +251,7 @@ impl<'ast> Map<'ast> { } fn find_entry(&self, id: NodeId) -> Option> { - self.map.borrow().get(id as usize).map(|e| *e) + self.map.borrow().get(id as usize).cloned() } pub fn krate(&self) -> &'ast Crate { diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 64ae6162ef4e5..26e291a4c693a 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -639,7 +639,7 @@ impl<'a> ExtCtxt<'a> { pub fn mod_path(&self) -> Vec { let mut v = Vec::new(); v.push(token::str_to_ident(&self.ecfg.crate_name[])); - v.extend(self.mod_path.iter().map(|a| *a)); + v.extend(self.mod_path.iter().cloned()); return v; } pub fn bt_push(&mut self, ei: ExpnInfo) { diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 7a3a3562bdfdc..d1dee115b6bcd 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -179,7 +179,7 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) return DummyResult::expr(sp); } Ok(bytes) => { - let bytes = bytes.iter().map(|x| *x).collect(); + let bytes = bytes.iter().cloned().collect(); base::MacExpr::new(cx.expr_lit(sp, ast::LitBinary(Rc::new(bytes)))) } } diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index cc468df87f383..be22a76a7671a 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -938,7 +938,7 @@ fn calc_result(desc: &TestDesc, task_result: Result<(), Box>) -> TestR (&ShouldFail::Yes(Some(msg)), Err(ref err)) if err.downcast_ref::() .map(|e| &**e) - .or_else(|| err.downcast_ref::<&'static str>().map(|e| *e)) + .or_else(|| err.downcast_ref::<&'static str>().cloned()) .map(|e| e.contains(msg)) .unwrap_or(false) => TrOk, _ => TrFailed, diff --git a/src/test/bench/shootout-fasta.rs b/src/test/bench/shootout-fasta.rs index 141e098745e7b..0d28dd481a63b 100644 --- a/src/test/bench/shootout-fasta.rs +++ b/src/test/bench/shootout-fasta.rs @@ -133,7 +133,7 @@ fn run(writer: &mut W) -> std::old_io::IoResult<()> { ('t', 0.3015094502008)]; try!(make_fasta(writer, ">ONE Homo sapiens alu\n", - alu.as_bytes().iter().cycle().map(|c| *c), n * 2)); + alu.as_bytes().iter().cycle().cloned(), n * 2)); try!(make_fasta(writer, ">TWO IUB ambiguity codes\n", AAGen::new(rng, iub), n * 3)); try!(make_fasta(writer, ">THREE Homo sapiens frequency\n", diff --git a/src/test/bench/shootout-meteor.rs b/src/test/bench/shootout-meteor.rs index d061403d5901d..59abd63e12d59 100644 --- a/src/test/bench/shootout-meteor.rs +++ b/src/test/bench/shootout-meteor.rs @@ -270,7 +270,7 @@ fn handle_sol(raw_sol: &List, data: &mut Data) { // reverse order, i.e. the board rotated by half a turn. data.nb += 2; let sol1 = to_vec(raw_sol); - let sol2: Vec = sol1.iter().rev().map(|x| *x).collect(); + let sol2: Vec = sol1.iter().rev().cloned().collect(); if data.nb == 2 { data.min = sol1.clone(); From 1c7cb8b745bdbd51fe4ba156c159ab4152fd191c Mon Sep 17 00:00:00 2001 From: Ruud van Asseldonk Date: Fri, 13 Feb 2015 14:06:31 +0100 Subject: [PATCH 2/4] Relpace map(|x| x.clone()) with cloned(). --- src/libcollections/dlist.rs | 2 +- src/librustc/middle/infer/error_reporting.rs | 2 +- src/librustc_back/rpath.rs | 2 +- src/librustc_trans/trans/base.rs | 2 +- src/librustdoc/passes.rs | 2 +- src/libsyntax/ext/deriving/generic/mod.rs | 8 ++++---- src/libsyntax/parse/parser.rs | 6 +++--- src/libsyntax/print/pprust.rs | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index a080146e0ec50..f33d7155a5daf 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -895,7 +895,7 @@ impl Ord for DList { #[stable(feature = "rust1", since = "1.0.0")] impl Clone for DList { fn clone(&self) -> DList { - self.iter().map(|x| x.clone()).collect() + self.iter().cloned().collect() } } diff --git a/src/librustc/middle/infer/error_reporting.rs b/src/librustc/middle/infer/error_reporting.rs index 5d7a56ef0e6c6..4bb7f03655fee 100644 --- a/src/librustc/middle/infer/error_reporting.rs +++ b/src/librustc/middle/infer/error_reporting.rs @@ -924,7 +924,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { fn rebuild(&self) -> (ast::FnDecl, Option, ast::Generics) { - let mut expl_self_opt = self.expl_self_opt.map(|x| x.clone()); + let mut expl_self_opt = self.expl_self_opt.cloned(); let mut inputs = self.fn_decl.inputs.clone(); let mut output = self.fn_decl.output.clone(); let mut ty_params = self.generics.ty_params.clone(); diff --git a/src/librustc_back/rpath.rs b/src/librustc_back/rpath.rs index 36bbd4b987297..7756f87162e6b 100644 --- a/src/librustc_back/rpath.rs +++ b/src/librustc_back/rpath.rs @@ -41,7 +41,7 @@ pub fn get_rpath_flags(config: RPathConfig) -> Vec where let libs = config.used_crates.clone(); let libs = libs.into_iter().filter_map(|(_, l)| { - l.map(|p| p.clone()) + l.cloned() }).collect::>(); let rpaths = get_rpaths(config, &libs[]); diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index 52ef2b75f9571..6934cd9aa3a93 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -3228,7 +3228,7 @@ pub fn trans_crate<'tcx>(analysis: ty::CrateAnalysis<'tcx>) reachable.push("rust_eh_personality_catch".to_string()); if codegen_units > 1 { - internalize_symbols(&shared_ccx, &reachable.iter().map(|x| x.clone()).collect()); + internalize_symbols(&shared_ccx, &reachable.iter().cloned().collect()); } let metadata_module = ModuleTranslation { diff --git a/src/librustdoc/passes.rs b/src/librustdoc/passes.rs index abd73fcfb7028..722f14fa6d4c7 100644 --- a/src/librustdoc/passes.rs +++ b/src/librustdoc/passes.rs @@ -293,7 +293,7 @@ pub fn collapse_docs(krate: clean::Crate) -> plugins::PluginResult { let mut a: Vec = i.attrs.iter().filter(|&a| match a { &clean::NameValue(ref x, _) if "doc" == *x => false, _ => true - }).map(|x| x.clone()).collect(); + }).cloned().collect(); if docstr.len() > 0 { a.push(clean::NameValue("doc".to_string(), docstr)); } diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index d9242417e0475..c7dd41722ff6f 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -367,7 +367,7 @@ impl<'a> TraitDef<'a> { "allow" | "warn" | "deny" | "forbid" => true, _ => false, } - }).map(|a| a.clone())); + }).cloned()); push(P(ast::Item { attrs: attrs, ..(*newitem).clone() @@ -445,14 +445,14 @@ impl<'a> TraitDef<'a> { span: self.span, bound_lifetimes: wb.bound_lifetimes.clone(), bounded_ty: wb.bounded_ty.clone(), - bounds: OwnedSlice::from_vec(wb.bounds.iter().map(|b| b.clone()).collect()) + bounds: OwnedSlice::from_vec(wb.bounds.iter().cloned().collect()) }) } ast::WherePredicate::RegionPredicate(ref rb) => { ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate { span: self.span, lifetime: rb.lifetime, - bounds: rb.bounds.iter().map(|b| b.clone()).collect() + bounds: rb.bounds.iter().cloned().collect() }) } ast::WherePredicate::EqPredicate(ref we) => { @@ -500,7 +500,7 @@ impl<'a> TraitDef<'a> { let opt_trait_ref = Some(trait_ref); let ident = ast_util::impl_pretty_name(&opt_trait_ref, &*self_type); let mut a = vec![attr]; - a.extend(self.attributes.iter().map(|a| a.clone())); + a.extend(self.attributes.iter().cloned()); cx.item( self.span, ident, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index fd2f0685cab83..adbb22786f922 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -241,7 +241,7 @@ macro_rules! maybe_whole { fn maybe_append(mut lhs: Vec, rhs: Option>) -> Vec { match rhs { - Some(ref attrs) => lhs.extend(attrs.iter().map(|a| a.clone())), + Some(ref attrs) => lhs.extend(attrs.iter().cloned()), None => {} } lhs @@ -467,7 +467,7 @@ impl<'a> Parser<'a> { debug!("commit_expr {:?}", e); if let ExprPath(..) = e.node { // might be unit-struct construction; check for recoverableinput error. - let mut expected = edible.iter().map(|x| x.clone()).collect::>(); + let mut expected = edible.iter().cloned().collect::>(); expected.push_all(inedible); self.check_for_erroneous_unit_struct_expecting(&expected[]); } @@ -485,7 +485,7 @@ impl<'a> Parser<'a> { if self.last_token .as_ref() .map_or(false, |t| t.is_ident() || t.is_path()) { - let mut expected = edible.iter().map(|x| x.clone()).collect::>(); + let mut expected = edible.iter().cloned().collect::>(); expected.push_all(&inedible[]); self.check_for_erroneous_unit_struct_expecting( &expected[]); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 583095e157427..78bfc0b3de706 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -983,7 +983,7 @@ impl<'a> State<'a> { try!(self.word_nbsp("trait")); try!(self.print_ident(item.ident)); try!(self.print_generics(generics)); - let bounds: Vec<_> = bounds.iter().map(|b| b.clone()).collect(); + let bounds: Vec<_> = bounds.iter().cloned().collect(); let mut real_bounds = Vec::with_capacity(bounds.len()); for b in bounds { if let TraitTyParamBound(ref ptr, ast::TraitBoundModifier::Maybe) = b { From 539866bef5eadbb6c9e41ce0ba8d488949160e0d Mon Sep 17 00:00:00 2001 From: Ruud van Asseldonk Date: Fri, 13 Feb 2015 14:47:59 +0100 Subject: [PATCH 3/4] Replace map(|x| (*x).clone()) with cloned(). This resolves #22243, at least for one-letter variable names. --- src/libcollections/dlist.rs | 2 +- src/librustc/middle/resolve_lifetime.rs | 2 +- src/librustc/middle/traits/select.rs | 2 +- src/librustc_trans/trans/expr.rs | 2 +- src/librustc_trans/trans/type_of.rs | 2 +- src/librustdoc/visit_ast.rs | 2 +- src/libsyntax/ext/deriving/generic/mod.rs | 2 +- src/libsyntax/ext/tt/macro_parser.rs | 4 +--- src/libsyntax/ext/tt/macro_rules.rs | 2 +- src/libsyntax/parse/lexer/comments.rs | 2 +- 10 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index f33d7155a5daf..9159e92a21640 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -1013,7 +1013,7 @@ mod tests { #[cfg(test)] fn list_from(v: &[T]) -> DList { - v.iter().map(|x| (*x).clone()).collect() + v.iter().cloned().collect() } #[test] diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index e91d7d8c52cde..3ba08c1032031 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -562,7 +562,7 @@ pub fn early_bound_lifetimes<'a>(generics: &'a ast::Generics) -> Vec SelectionContext<'cx, 'tcx> { { let cache = self.pick_candidate_cache(); let hashmap = cache.hashmap.borrow(); - hashmap.get(&cache_fresh_trait_pred.0.trait_ref).map(|c| (*c).clone()) + hashmap.get(&cache_fresh_trait_pred.0.trait_ref).cloned() } fn insert_candidate_cache(&mut self, diff --git a/src/librustc_trans/trans/expr.rs b/src/librustc_trans/trans/expr.rs index 9ea7a276d97c6..9b64e87202b26 100644 --- a/src/librustc_trans/trans/expr.rs +++ b/src/librustc_trans/trans/expr.rs @@ -1153,7 +1153,7 @@ fn trans_rvalue_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, let trait_ref = bcx.tcx().object_cast_map.borrow() .get(&expr.id) - .map(|t| (*t).clone()) + .cloned() .unwrap(); let trait_ref = bcx.monomorphize(&trait_ref); let datum = unpack_datum!(bcx, trans(bcx, &**val)); diff --git a/src/librustc_trans/trans/type_of.rs b/src/librustc_trans/trans/type_of.rs index 9d1c0fadefcd2..546c62e5dd247 100644 --- a/src/librustc_trans/trans/type_of.rs +++ b/src/librustc_trans/trans/type_of.rs @@ -67,7 +67,7 @@ pub fn untuple_arguments_if_necessary<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, abi: abi::Abi) -> Vec> { if abi != abi::RustCall { - return inputs.iter().map(|x| (*x).clone()).collect() + return inputs.iter().cloned().collect() } if inputs.len() == 0 { diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index ac1a02854124a..c52b0bab1fa8b 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -333,7 +333,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { name: name, items: items.clone(), generics: gen.clone(), - bounds: b.iter().map(|x| (*x).clone()).collect(), + bounds: b.iter().cloned().collect(), id: item.id, attrs: item.attrs.clone(), whence: item.span, diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index c7dd41722ff6f..dba92009a962d 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -410,7 +410,7 @@ impl<'a> TraitDef<'a> { let mut ty_params = ty_params.into_vec(); // Copy the lifetimes - lifetimes.extend(generics.lifetimes.iter().map(|l| (*l).clone())); + lifetimes.extend(generics.lifetimes.iter().cloned()); // Create the type parameters. ty_params.extend(generics.ty_params.iter().map(|ty_param| { diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index d752e34c11253..7e996f46c4b07 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -282,9 +282,7 @@ pub fn parse(sess: &ParseSess, ms: &[TokenTree]) -> ParseResult { let mut cur_eis = Vec::new(); - cur_eis.push(initial_matcher_pos(Rc::new(ms.iter() - .map(|x| (*x).clone()) - .collect()), + cur_eis.push(initial_matcher_pos(Rc::new(ms.iter().cloned().collect()), None, rdr.peek().sp.lo)); diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index de61bdefa5de3..e899b46c009d1 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -160,7 +160,7 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt, None, None, arg.iter() - .map(|x| (*x).clone()) + .cloned() .collect(), true); match parse(cx.parse_sess(), cx.cfg(), arg_rdr, lhs_tt) { diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index b17fc7fe82e6c..6f5da94f21059 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -82,7 +82,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String { while j > i && lines[j - 1].trim().is_empty() { j -= 1; } - return lines[i..j].iter().map(|x| (*x).clone()).collect(); + return lines[i..j].iter().cloned().collect(); } /// remove a "[ \t]*\*" block from each line, if possible From c9ad0d13a376f8a88408be221c2117a9c9568141 Mon Sep 17 00:00:00 2001 From: Ruud van Asseldonk Date: Fri, 13 Feb 2015 16:29:31 +0100 Subject: [PATCH 4/4] Revert incorrect map(|x| *x) -> cloned() substitutions. --- src/librustc_back/rpath.rs | 2 +- src/libtest/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_back/rpath.rs b/src/librustc_back/rpath.rs index 7756f87162e6b..36bbd4b987297 100644 --- a/src/librustc_back/rpath.rs +++ b/src/librustc_back/rpath.rs @@ -41,7 +41,7 @@ pub fn get_rpath_flags(config: RPathConfig) -> Vec where let libs = config.used_crates.clone(); let libs = libs.into_iter().filter_map(|(_, l)| { - l.cloned() + l.map(|p| p.clone()) }).collect::>(); let rpaths = get_rpaths(config, &libs[]); diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index be22a76a7671a..cc468df87f383 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -938,7 +938,7 @@ fn calc_result(desc: &TestDesc, task_result: Result<(), Box>) -> TestR (&ShouldFail::Yes(Some(msg)), Err(ref err)) if err.downcast_ref::() .map(|e| &**e) - .or_else(|| err.downcast_ref::<&'static str>().cloned()) + .or_else(|| err.downcast_ref::<&'static str>().map(|e| *e)) .map(|e| e.contains(msg)) .unwrap_or(false) => TrOk, _ => TrFailed,