Skip to content

Commit 8462a37

Browse files
committed
avoid temporary vectors
Avoid collecting an interator just to re-iterate immediately. Rather reuse the previous iterator. (clippy::needless_collect)
1 parent 74ef0c3 commit 8462a37

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

+3-7
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2134,7 +2134,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
21342134
let new_lt = generics
21352135
.as_ref()
21362136
.and_then(|(parent_g, g)| {
2137-
let possible: Vec<_> = (b'a'..=b'z').map(|c| format!("'{}", c as char)).collect();
2137+
let mut possible = (b'a'..=b'z').map(|c| format!("'{}", c as char));
21382138
let mut lts_names = g
21392139
.params
21402140
.iter()
@@ -2150,7 +2150,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
21502150
);
21512151
}
21522152
let lts = lts_names.iter().map(|s| -> &str { &*s }).collect::<Vec<_>>();
2153-
possible.into_iter().find(|candidate| !lts.contains(&candidate.as_str()))
2153+
possible.find(|candidate| !lts.contains(&candidate.as_str()))
21542154
})
21552155
.unwrap_or("'lt".to_string());
21562156
let add_lt_sugg = generics

0 commit comments

Comments
 (0)