]> git.lizzy.rs Git - rust.git/commitdiff
avoid temporary vectors
authorMatthias Krüger <matthias.krueger@famsik.de>
Fri, 16 Jul 2021 23:20:10 +0000 (01:20 +0200)
committerMatthias Krüger <matthias.krueger@famsik.de>
Fri, 16 Jul 2021 23:20:10 +0000 (01:20 +0200)
Avoid collecting an interator just to re-iterate immediately.
Rather reuse the previous iterator. (clippy::needless_collect)

compiler/rustc_builtin_macros/src/deriving/generic/ty.rs
compiler/rustc_infer/src/infer/error_reporting/mod.rs

index 6b7d0e1f204b5f0a9712db0f32bc9efa547725ac..00d75be4399649987e9b491aa19fb81cf36e7838 100644 (file)
@@ -72,13 +72,9 @@ pub fn to_path(
     ) -> ast::Path {
         let mut idents = self.path.iter().map(|s| Ident::new(*s, span)).collect();
         let lt = mk_lifetimes(cx, span, &self.lifetime);
-        let tys: Vec<P<ast::Ty>> =
-            self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics)).collect();
-        let params = lt
-            .into_iter()
-            .map(GenericArg::Lifetime)
-            .chain(tys.into_iter().map(GenericArg::Type))
-            .collect();
+        let tys = self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics));
+        let params =
+            lt.into_iter().map(GenericArg::Lifetime).chain(tys.map(GenericArg::Type)).collect();
 
         match self.kind {
             PathKind::Global => cx.path_all(span, true, idents, params),
index e3a79fe2653305da6414187b0301b48d9f660ad0..a5a804a29164320ed2f08ee2f26b6126525e8e88 100644 (file)
@@ -2134,7 +2134,7 @@ pub fn construct_generic_bound_failure(
         let new_lt = generics
             .as_ref()
             .and_then(|(parent_g, g)| {
-                let possible: Vec<_> = (b'a'..=b'z').map(|c| format!("'{}", c as char)).collect();
+                let mut possible = (b'a'..=b'z').map(|c| format!("'{}", c as char));
                 let mut lts_names = g
                     .params
                     .iter()
@@ -2150,7 +2150,7 @@ pub fn construct_generic_bound_failure(
                     );
                 }
                 let lts = lts_names.iter().map(|s| -> &str { &*s }).collect::<Vec<_>>();
-                possible.into_iter().find(|candidate| !lts.contains(&candidate.as_str()))
+                possible.find(|candidate| !lts.contains(&candidate.as_str()))
             })
             .unwrap_or("'lt".to_string());
         let add_lt_sugg = generics