]> git.lizzy.rs Git - rust.git/commitdiff
Opt for .cloned() over .map(|x| x.clone()) etc.
authorKevin Butler <haqkrs@gmail.com>
Fri, 13 Feb 2015 07:33:44 +0000 (07:33 +0000)
committerKevin Butler <haqkrs@gmail.com>
Wed, 18 Feb 2015 00:56:07 +0000 (00:56 +0000)
39 files changed:
src/compiletest/compiletest.rs
src/compiletest/runtest.rs
src/libcollections/bit.rs
src/libcollections/dlist.rs
src/libcore/iter.rs
src/libcoretest/iter.rs
src/librustc/metadata/cstore.rs
src/librustc/middle/check_match.rs
src/librustc/middle/const_eval.rs
src/librustc/middle/dependency_format.rs
src/librustc/middle/infer/error_reporting.rs
src/librustc/middle/lang_items.rs
src/librustc/middle/region.rs
src/librustc/middle/resolve_lifetime.rs
src/librustc/middle/traits/select.rs
src/librustc/middle/ty.rs
src/librustc/util/common.rs
src/librustc_back/rpath.rs
src/librustc_driver/test.rs
src/librustc_resolve/lib.rs
src/librustc_trans/trans/base.rs
src/librustc_trans/trans/expr.rs
src/librustc_trans/trans/type_of.rs
src/librustc_typeck/check/mod.rs
src/librustdoc/passes.rs
src/librustdoc/visit_ast.rs
src/libstd/env.rs
src/libsyntax/ast_map/mod.rs
src/libsyntax/diagnostics/registry.rs
src/libsyntax/ext/base.rs
src/libsyntax/ext/deriving/generic/mod.rs
src/libsyntax/ext/source_util.rs
src/libsyntax/ext/tt/macro_parser.rs
src/libsyntax/ext/tt/macro_rules.rs
src/libsyntax/parse/lexer/comments.rs
src/libsyntax/parse/parser.rs
src/libsyntax/print/pprust.rs
src/test/bench/shootout-fasta.rs
src/test/bench/shootout-meteor.rs

index 6c1308a01c4a1ca59d698299824bc8372977be71..0cfaaae2009c95bd081b7bf59e32b0ddd5e6b979 100644 (file)
@@ -21,6 +21,7 @@
 #![feature(test)]
 #![feature(unicode)]
 #![feature(env)]
+#![feature(core)]
 
 #![deny(warnings)]
 
index 54c011832d1dc93d5d5266c7f48b64bd17c5bf7c..8da11a9a50d449e1c5c07351e8a6a38cdcbd7eee 100644 (file)
@@ -1133,7 +1133,7 @@ fn compile_test_(config: &Config, props: &TestProps,
     // FIXME (#9639): This needs to handle non-utf8 paths
     let mut link_args = vec!("-L".to_string(),
                              aux_dir.as_str().unwrap().to_string());
-    link_args.extend(extra_args.iter().map(|s| s.clone()));
+    link_args.extend(extra_args.iter().cloned());
     let args = make_compile_args(config,
                                  props,
                                  link_args,
index ca598a8d4d29255145f51abefe7056be6fb50109..d6e5b3fe464a621bb017b389872e9aa5092183f4 100644 (file)
@@ -2306,7 +2306,7 @@ fn test_to_bytes() {
     #[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");
     }
 
@@ -2319,12 +2319,12 @@ fn test_to_bools() {
     #[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::<Vec<bool>>(), 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::<Vec<bool>>(), long)
     }
 
index 27b282ee9a9c1a04ee344d21ef2450180623d7b2..4da6f96300679223f26bfa0712b753222a82c9b5 100644 (file)
@@ -938,7 +938,7 @@ fn cmp(&self, other: &DList<A>) -> Ordering {
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<A: Clone> Clone for DList<A> {
     fn clone(&self) -> DList<A> {
-        self.iter().map(|x| x.clone()).collect()
+        self.iter().cloned().collect()
     }
 }
 
@@ -1056,7 +1056,7 @@ fn generate_test() -> DList<i32> {
 
     #[cfg(test)]
     fn list_from<T: Clone>(v: &[T]) -> DList<T> {
-        v.iter().map(|x| (*x).clone()).collect()
+        v.iter().cloned().collect()
     }
 
     #[test]
index 299864e3b3d7dfa39fde74e4b517a2cfe9d2f46a..c5e0966720fd27ae643de6a13ebbf96f2af596c4 100644 (file)
@@ -350,7 +350,7 @@ fn enumerate(self) -> Enumerate<Self> {
     ///
     /// ```
     /// 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);
index 7eb0fb97bed2a54f48efce97d6b65f759c55da5c..88777da0bcd35a660f7d0334b716308ce0e60b91 100644 (file)
@@ -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));
index 0a3e173b35ee517cde4025249d01381356729d71..a3f7d57da67486b39a976a8289743612960ef5b4 100644 (file)
@@ -139,8 +139,7 @@ pub fn add_used_crate_source(&self, src: CrateSource) {
     pub fn get_used_crate_source(&self, cnum: ast::CrateNum)
                                      -> Option<CrateSource> {
         self.used_crate_sources.borrow_mut()
-            .iter().find(|source| source.cnum == cnum)
-            .map(|source| source.clone())
+            .iter().find(|source| source.cnum == cnum).cloned()
     }
 
     pub fn reset(&self) {
@@ -218,7 +217,7 @@ pub fn add_extern_mod_stmt_cnum(&self,
 
     pub fn find_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId)
                                      -> Option<ast::CrateNum> {
-        self.extern_mod_crate_map.borrow().get(&emod_id).map(|x| *x)
+        self.extern_mod_crate_map.borrow().get(&emod_id).cloned()
     }
 }
 
index 03456f8529028a36a8527a3f00cc3a5e8e99548a..4544f283e1cc2ccfceaedc2f27c114890fe9f0f1 100644 (file)
@@ -76,7 +76,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
             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::<String>();
         try!(write!(f, "{}\n", br));
         for row in pretty_printed_matrix {
index 3d03cd946c48fadf517ca238ab75d540e63dd313..456d4a3a86e39336f57bad24ba88dcbdd6fba1bd 100644 (file)
@@ -501,7 +501,7 @@ fn lit_to_const(lit: &ast::Lit, ty_hint: Option<Ty>) -> 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(data.clone())
         }
         ast::LitByte(n) => const_uint(n as u64),
         ast::LitChar(n) => const_uint(n as u64),
index 6d35a82d153cd6c5151e9fedd428c0ae963364e6..ad9f4eade5c90d25538240080640f300aace049a 100644 (file)
@@ -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,
         }
index 72b33613c66aab63e81c562e53237821decd3058..49bd2e67a19181dfd45115e341488c7c58f45573 100644 (file)
@@ -924,7 +924,7 @@ fn new(tcx: &'a ty::ctxt<'tcx>,
 
     fn rebuild(&self)
                -> (ast::FnDecl, Option<ast::ExplicitSelf_>, 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();
index e13a5672778e24da1a4a88980b21fc01eacff0ce..ce8f0d87e564c24511c7a3a7cddbf0a8e7231a96 100644 (file)
@@ -147,18 +147,12 @@ struct LanguageItemCollector<'a> {
 
 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);
-
-                match item_index {
-                    Some(item_index) => {
-                        self.collect_item(item_index, local_def(item.id), item.span)
-                    }
-                    None => {}
-                }
+        if let Some(value) = extract(&item.attrs) {
+            let item_index = self.item_refs.get(&value[]).cloned();
+
+            if let Some(item_index) = item_index {
+                self.collect_item(item_index, local_def(item.id), item.span)
             }
-            None => {}
         }
 
         visit::walk_item(self, item);
index 2f0462ab8c338177692ca3314e247c5c3e467e71..e539f6ae6cb9382898b2167093e91fe5b288e3db 100644 (file)
@@ -407,7 +407,7 @@ pub fn mark_as_terminating_scope(&self, scope_id: CodeExtent) {
 
     pub fn opt_encl_scope(&self, id: CodeExtent) -> Option<CodeExtent> {
         //! 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
index e91d7d8c52cde8fcbe52af0d0ce6b4797dde80c3..3ba08c1032031075224aaa0dddcd1ac67902f5d4 100644 (file)
@@ -562,7 +562,7 @@ pub fn early_bound_lifetimes<'a>(generics: &'a ast::Generics) -> Vec<ast::Lifeti
 
     generics.lifetimes.iter()
         .filter(|l| referenced_idents.iter().any(|&i| i == l.lifetime.name))
-        .map(|l| (*l).clone())
+        .cloned()
         .collect()
 }
 
index 6f58f4655fed1ed944805e58485c9525a98b1e8d..b21b42fdbfccebc7aef3b107a79af9a93e0c6de6 100644 (file)
@@ -738,7 +738,7 @@ fn check_candidate_cache(&mut self,
     {
         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,
index 107715a8261574858a6233678264466652accab0..8ca54cce8e3630aa77eceac6c3bee0dfd12bd06e 100644 (file)
@@ -2868,7 +2868,7 @@ pub fn mk_ctor_fn<'tcx>(cx: &ctxt<'tcx>,
                         def_id: ast::DefId,
                         input_tys: &[Ty<'tcx>],
                         output: Ty<'tcx>) -> Ty<'tcx> {
-    let input_args = input_tys.iter().map(|ty| *ty).collect();
+    let input_args = input_tys.iter().cloned().collect();
     mk_bare_fn(cx,
                Some(def_id),
                cx.mk_bare_fn(BareFnTy {
@@ -3837,7 +3837,7 @@ fn are_inner_types_recursive<'tcx>(cx: &ctxt<'tcx>, sp: Span,
                                        -> Representability {
         match ty.sty {
             ty_tup(ref ts) => {
-                find_nonrepresentable(cx, sp, seen, ts.iter().map(|ty| *ty))
+                find_nonrepresentable(cx, sp, seen, ts.iter().cloned())
             }
             // Fixed-length vectors.
             // FIXME(#11924) Behavior undecided for zero-length vectors.
@@ -4965,7 +4965,7 @@ pub fn note_and_explain_type_err(cx: &ctxt, err: &type_err) {
 }
 
 pub fn provided_source(cx: &ctxt, id: ast::DefId) -> Option<ast::DefId> {
-    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)
index d3d0f56c3ce904b7836f4f51ea80c4d4e39d2267..a6d8bc24da76f501eac9e2cd2a63ecaa35cd12a4 100644 (file)
@@ -214,7 +214,7 @@ pub fn memoized<T, U, S, F>(cache: &RefCell<HashMap<T, U, S>>, arg: T, f: F) ->
           F: FnOnce(T) -> U,
 {
     let key = arg.clone();
-    let result = cache.borrow().get(&key).map(|result| result.clone());
+    let result = cache.borrow().get(&key).cloned();
     match result {
         Some(result) => result,
         None => {
index 36bbd4b987297d020e5fe867d36b604bfbf9211f..3de69bd72e1e43d87bfc55e6a0558ab2f8cb99f1 100644 (file)
@@ -40,10 +40,7 @@ pub fn get_rpath_flags<F, G>(config: RPathConfig<F, G>) -> Vec<String> where
     debug!("preparing the RPATH!");
 
     let libs = config.used_crates.clone();
-    let libs = libs.into_iter().filter_map(|(_, l)| {
-        l.map(|p| p.clone())
-    }).collect::<Vec<_>>();
-
+    let libs = libs.into_iter().filter_map(|(_, l)| l).collect::<Vec<_>>();
     let rpaths = get_rpaths(config, &libs[]);
     flags.push_all(&rpaths_to_flags(&rpaths[])[]);
     flags
index 7105a6cc488821e0e30460cdcc7c83329a69a0e6..e614f87c9809997afcb6d3f667f975f0e6ee8a4f 100644 (file)
@@ -254,7 +254,7 @@ pub fn t_fn(&self,
                 output_ty: Ty<'tcx>)
                 -> Ty<'tcx>
     {
-        let input_args = input_tys.iter().map(|ty| *ty).collect();
+        let input_args = input_tys.iter().cloned().collect();
         ty::mk_bare_fn(self.infcx.tcx,
                        None,
                        self.infcx.tcx.mk_bare_fn(ty::BareFnTy {
index 874c8f2a9402df38653c04fcf0d7389fdb48ca46..337ba77fe7fbb9a31c18755e5036f7c483a1ee1e 100644 (file)
@@ -1920,18 +1920,15 @@ fn resolve_module_path_from_root(&mut self,
                                 -> ResolveResult<(Rc<Module>, LastPrivate)> {
         fn search_parent_externals(needle: Name, module: &Rc<Module>)
                                 -> Option<Rc<Module>> {
-            module.external_module_children.borrow()
-                                            .get(&needle).cloned()
-                                            .map(|_| module.clone())
-                                            .or_else(|| {
-                match module.parent_link.clone() {
-                    ModuleParentLink(parent, _) => {
-                        search_parent_externals(needle,
-                                                &parent.upgrade().unwrap())
+            match module.external_module_children.borrow().get(&needle) {
+                Some(_) => Some(module.clone()),
+                None => match module.parent_link {
+                    ModuleParentLink(ref parent, _) => {
+                        search_parent_externals(needle, &parent.upgrade().unwrap())
                     }
                    _ => None
                 }
-            })
+            }
         }
 
         let mut search_module = module_;
index 7f7b5cd800660abd835bd50e5b458d674cbab961..62d4dbeb0ad0c94c659206b6b05f48657667724e 100644 (file)
@@ -3211,7 +3211,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 {
index 480679f43cb767567481f4593343aeddae89cc28..306d0f610c6577dd3156ef8159d19052365920e5 100644 (file)
@@ -1197,7 +1197,7 @@ fn make_field(field_name: &str, expr: P<ast::Expr>) -> ast::Field {
                 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));
index 9d1c0fadefcd22718ca1dac09debc1fb7cb9e3fc..546c62e5dd24743b3f6b108a6dec3eba67512096 100644 (file)
@@ -67,7 +67,7 @@ pub fn untuple_arguments_if_necessary<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
                                                 abi: abi::Abi)
                                                 -> Vec<Ty<'tcx>> {
     if abi != abi::RustCall {
-        return inputs.iter().map(|x| (*x).clone()).collect()
+        return inputs.iter().cloned().collect()
     }
 
     if inputs.len() == 0 {
index 30896c1607a88140be22fdfafda6d698051fe42e..1ba2e38201c6320b315e69b629f30271e5df8f61 100644 (file)
@@ -3220,7 +3220,7 @@ fn check_struct_or_variant_fields<'a, 'tcx>(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(
@@ -3852,7 +3852,7 @@ fn check_struct_fields_on_error<'a,'tcx>(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,
index abd73fcfb70289981213f7ef579fc4f657ab7268..722f14fa6d4c7b0dcff44ad75f8d7f7bfa8686c2 100644 (file)
@@ -293,7 +293,7 @@ fn fold_item(&mut self, i: Item) -> Option<Item> {
             let mut a: Vec<clean::Attribute> = 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));
             }
index ac1a02854124afda82d3183550ebd9e7c63a6933..c52b0bab1fa8b800129e3688e7423bca40dba82d 100644 (file)
@@ -333,7 +333,7 @@ pub fn visit_item(&mut self, item: &ast::Item,
                     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,
index ea18838211f26b37b84f87ab94bc1695e57feda8..bfc1afc6eb4f2b4d45c37519dc762d09a64c7b95 100644 (file)
@@ -918,7 +918,7 @@ fn check_parse(unparsed: &str, parsed: &[&str]) -> bool {
     #[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 @@ fn test_eq(input: &[&str], output: &str) -> bool {
                          "/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 @@ fn test_eq(input: &[&str], output: &str) -> bool {
                         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());
     }
     }
index 5535e5911e0c2fd5e85ae763a14dcaef7e18915a..6535705388d0104437377181a351bd19ac87660a 100644 (file)
@@ -251,7 +251,7 @@ fn entry_count(&self) -> usize {
     }
 
     fn find_entry(&self, id: NodeId) -> Option<MapEntry<'ast>> {
-        self.map.borrow().get(id as usize).map(|e| *e)
+        self.map.borrow().get(id as usize).cloned()
     }
 
     pub fn krate(&self) -> &'ast Crate {
index 62d48189c43475149b013f223bb2079af97e0199..968fceb6f6fd02f2d7c523fa6cefa34c58b4766f 100644 (file)
@@ -21,6 +21,6 @@ pub fn new(descriptions: &[(&'static str, &'static str)]) -> Registry {
     }
 
     pub fn find_description(&self, code: &str) -> Option<&'static str> {
-        self.descriptions.get(code).map(|desc| *desc)
+        self.descriptions.get(code).cloned()
     }
 }
index 083039995ee955ce5366292ceff367578e6b0a6e..8fdc3c8447a32d227b596831eff589260bd84d38 100644 (file)
@@ -639,7 +639,7 @@ pub fn original_span_in_file(&self) -> Span {
     pub fn mod_path(&self) -> Vec<ast::Ident> {
         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) {
index f878cb5ca8b78ff74377b6817bf6311a392b7885..8b4eaab386d007c867f57ee4e6014d765df44f6e 100644 (file)
@@ -367,7 +367,7 @@ pub fn expand<F>(&self,
                 "allow" | "warn" | "deny" | "forbid" => true,
                 _ => false,
             }
-        }).map(|a| a.clone()));
+        }).cloned());
         push(P(ast::Item {
             attrs: attrs,
             ..(*newitem).clone()
@@ -410,7 +410,7 @@ fn create_derived_impl(&self,
         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| {
@@ -445,14 +445,14 @@ fn create_derived_impl(&self,
                         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 @@ fn create_derived_impl(&self,
         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,
index 7a3a3562bdfdcbd9ede0d2597241449c74371470..d1dee115b6bcdf247054cb829dc21459c72b3246 100644 (file)
@@ -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))))
         }
     }
index d752e34c11253c149318013f13e1c02269a205f9..a3224c25d09579752e78d2642acb941d64fc1f60 100644 (file)
@@ -283,7 +283,7 @@ pub fn parse(sess: &ParseSess,
              -> ParseResult {
     let mut cur_eis = Vec::new();
     cur_eis.push(initial_matcher_pos(Rc::new(ms.iter()
-                                                .map(|x| (*x).clone())
+                                                .cloned()
                                                 .collect()),
                                      None,
                                      rdr.peek().sp.lo));
index f322cf8bad09cc103cdf627353b297be0dddd0d6..1a6cf7d07f19da2820520a4b40334d33071c7e51 100644 (file)
@@ -159,7 +159,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) {
index b17fc7fe82e6c66b09da7c36c0b9cd80b239fb34..c0823e04288e31bb078dd6e66607bdd1fc00831b 100644 (file)
@@ -61,7 +61,7 @@ pub fn doc_comment_style(comment: &str) -> ast::AttrStyle {
 
 pub fn strip_doc_comment_decoration(comment: &str) -> String {
     /// remove whitespace-only lines from the start/end of lines
-    fn vertical_trim(lines: Vec<String> ) -> Vec<String> {
+    fn vertical_trim(lines: Vec<String>) -> Vec<String> {
         let mut i = 0;
         let mut j = lines.len();
         // first line of all-stars should be omitted
@@ -82,7 +82,7 @@ fn vertical_trim(lines: Vec<String> ) -> Vec<String> {
         while j > i && lines[j - 1].trim().is_empty() {
             j -= 1;
         }
-        return lines[i..j].iter().map(|x| (*x).clone()).collect();
+        lines[i..j].iter().cloned().collect()
     }
 
     /// remove a "[ \t]*\*" block from each line, if possible
index 407740e580d2e30eff0e5d720d78dfc7490ee62a..f14cd5247769d1ff420c7ac3749080ebbe87b947 100644 (file)
@@ -240,9 +240,8 @@ macro_rules! maybe_whole {
 
 fn maybe_append(mut lhs: Vec<Attribute>, rhs: Option<Vec<Attribute>>)
                 -> Vec<Attribute> {
-    match rhs {
-        Some(ref attrs) => lhs.extend(attrs.iter().map(|a| a.clone())),
-        None => {}
+    if let Some(ref attrs) = rhs {
+        lhs.extend(attrs.iter().cloned())
     }
     lhs
 }
@@ -467,7 +466,7 @@ pub fn commit_expr(&mut self, e: &Expr, edible: &[token::Token], inedible: &[tok
         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::<Vec<_>>();
+            let mut expected = edible.iter().cloned().collect::<Vec<_>>();
             expected.push_all(inedible);
             self.check_for_erroneous_unit_struct_expecting(&expected[]);
         }
@@ -485,7 +484,7 @@ pub fn commit_stmt(&mut self, edible: &[token::Token], inedible: &[token::Token]
         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::<Vec<_>>();
+            let mut expected = edible.iter().cloned().collect::<Vec<_>>();
             expected.push_all(&inedible[]);
             self.check_for_erroneous_unit_struct_expecting(
                 &expected[]);
index 583095e15742738d5fdf2eeb1a42bae3462336a4..8f1acde15460cea4d771cfaf312a24c6d9cc3153 100644 (file)
@@ -983,15 +983,14 @@ pub fn print_item(&mut self, item: &ast::Item) -> IoResult<()> {
                 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 mut real_bounds = Vec::with_capacity(bounds.len());
-                for b in bounds {
-                    if let TraitTyParamBound(ref ptr, ast::TraitBoundModifier::Maybe) = b {
+                for b in bounds.iter() {
+                    if let TraitTyParamBound(ref ptr, ast::TraitBoundModifier::Maybe) = *b {
                         try!(space(&mut self.s));
                         try!(self.word_space("for ?"));
                         try!(self.print_trait_ref(&ptr.trait_ref));
                     } else {
-                        real_bounds.push(b);
+                        real_bounds.push(b.clone());
                     }
                 }
                 try!(self.print_bounds(":", &real_bounds[]));
index 5bf0862e0a1d6b8d809ca254bee45dd3c56d8a9d..273b014011f055f063118b0bc45b80e278d6cf6d 100644 (file)
@@ -134,7 +134,7 @@ fn run<W: Writer>(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",
index d061403d5901d175828fb86ad8b82c180020b14a..59abd63e12d59ec4789204b3b5fef9e70fe2d728 100644 (file)
@@ -270,7 +270,7 @@ fn handle_sol(raw_sol: &List<u64>, 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<u8> = sol1.iter().rev().map(|x| *x).collect();
+    let sol2: Vec<u8> = sol1.iter().rev().cloned().collect();
 
     if data.nb == 2 {
         data.min = sol1.clone();