Skip to content

Commit 358b2cc

Browse files
Rollup merge of #87206 - matthiaskrgr:clippy_collect, r=davidtwco
avoid temporary vectors/reuse iterators Avoid collecting an interator just to re-iterate immediately. Rather reuse the previous iterator. (clippy::needless_collect)
2 parents 2861265 + 8462a37 commit 358b2cc

File tree

2 files changed

+5
-9
lines changed
  • compiler
    • rustc_builtin_macros/src/deriving/generic
    • rustc_infer/src/infer/error_reporting

2 files changed

+5
-9
lines changed

compiler/rustc_builtin_macros/src/deriving/generic/ty.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,9 @@ impl Path {
7272
) -> ast::Path {
7373
let mut idents = self.path.iter().map(|s| Ident::new(*s, span)).collect();
7474
let lt = mk_lifetimes(cx, span, &self.lifetime);
75-
let tys: Vec<P<ast::Ty>> =
76-
self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics)).collect();
77-
let params = lt
78-
.into_iter()
79-
.map(GenericArg::Lifetime)
80-
.chain(tys.into_iter().map(GenericArg::Type))
81-
.collect();
75+
let tys = self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics));
76+
let params =
77+
lt.into_iter().map(GenericArg::Lifetime).chain(tys.map(GenericArg::Type)).collect();
8278

8379
match self.kind {
8480
PathKind::Global => cx.path_all(span, true, idents, params),

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,7 +2130,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
21302130
let new_lt = generics
21312131
.as_ref()
21322132
.and_then(|(parent_g, g)| {
2133-
let possible: Vec<_> = (b'a'..=b'z').map(|c| format!("'{}", c as char)).collect();
2133+
let mut possible = (b'a'..=b'z').map(|c| format!("'{}", c as char));
21342134
let mut lts_names = g
21352135
.params
21362136
.iter()
@@ -2146,7 +2146,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
21462146
);
21472147
}
21482148
let lts = lts_names.iter().map(|s| -> &str { &*s }).collect::<Vec<_>>();
2149-
possible.into_iter().find(|candidate| !lts.contains(&candidate.as_str()))
2149+
possible.find(|candidate| !lts.contains(&candidate.as_str()))
21502150
})
21512151
.unwrap_or("'lt".to_string());
21522152
let add_lt_sugg = generics

0 commit comments

Comments
 (0)