Skip to content

Commit fcf5805

Browse files
authored
Rollup merge of #121895 - matthiaskrgr:devec, r=fee1-dead
avoid collecting into vecs in some places
2 parents 7bacfce + 7a48987 commit fcf5805

File tree

5 files changed

+20
-33
lines changed

5 files changed

+20
-33
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+16-20
Original file line numberDiff line numberDiff line change
@@ -357,31 +357,27 @@ fn add_unused_functions(cx: &CodegenCx<'_, '_>) {
357357

358358
let ignore_unused_generics = tcx.sess.instrument_coverage_except_unused_generics();
359359

360-
let eligible_def_ids: Vec<DefId> = tcx
361-
.mir_keys(())
362-
.iter()
363-
.filter_map(|local_def_id| {
364-
let def_id = local_def_id.to_def_id();
365-
let kind = tcx.def_kind(def_id);
366-
// `mir_keys` will give us `DefId`s for all kinds of things, not
367-
// just "functions", like consts, statics, etc. Filter those out.
368-
// If `ignore_unused_generics` was specified, filter out any
369-
// generic functions from consideration as well.
370-
if !matches!(kind, DefKind::Fn | DefKind::AssocFn | DefKind::Closure) {
371-
return None;
372-
}
373-
if ignore_unused_generics && tcx.generics_of(def_id).requires_monomorphization(tcx) {
374-
return None;
375-
}
376-
Some(local_def_id.to_def_id())
377-
})
378-
.collect();
360+
let eligible_def_ids = tcx.mir_keys(()).iter().filter_map(|local_def_id| {
361+
let def_id = local_def_id.to_def_id();
362+
let kind = tcx.def_kind(def_id);
363+
// `mir_keys` will give us `DefId`s for all kinds of things, not
364+
// just "functions", like consts, statics, etc. Filter those out.
365+
// If `ignore_unused_generics` was specified, filter out any
366+
// generic functions from consideration as well.
367+
if !matches!(kind, DefKind::Fn | DefKind::AssocFn | DefKind::Closure) {
368+
return None;
369+
}
370+
if ignore_unused_generics && tcx.generics_of(def_id).requires_monomorphization(tcx) {
371+
return None;
372+
}
373+
Some(local_def_id.to_def_id())
374+
});
379375

380376
let codegenned_def_ids = codegenned_and_inlined_items(tcx);
381377

382378
// For each `DefId` that should have coverage instrumentation but wasn't
383379
// codegenned, add it to the function coverage map as an unused function.
384-
for def_id in eligible_def_ids.into_iter().filter(|id| !codegenned_def_ids.contains(id)) {
380+
for def_id in eligible_def_ids.filter(|id| !codegenned_def_ids.contains(id)) {
385381
// Skip any function that didn't have coverage data added to it by the
386382
// coverage instrumentor.
387383
let body = tcx.instance_mir(ty::InstanceDef::Item(def_id));

compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -860,10 +860,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
860860
traits with associated type `{name}`, you could use the \
861861
fully-qualified path",
862862
),
863-
traits
864-
.iter()
865-
.map(|trait_str| format!("<Example as {trait_str}>::{name}"))
866-
.collect::<Vec<_>>(),
863+
traits.iter().map(|trait_str| format!("<Example as {trait_str}>::{name}")),
867864
Applicability::HasPlaceholders,
868865
);
869866
}

compiler/rustc_hir_typeck/src/expr.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -2156,10 +2156,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21562156
err.span_suggestions(
21572157
span.shrink_to_hi().with_hi(expr_span.hi()),
21582158
"you might have meant to use an associated function to build this type",
2159-
items
2160-
.iter()
2161-
.map(|(_, name, args)| suggestion(name, *args))
2162-
.collect::<Vec<String>>(),
2159+
items.iter().map(|(_, name, args)| suggestion(name, *args)),
21632160
Applicability::MaybeIncorrect,
21642161
);
21652162
}

compiler/rustc_resolve/src/late/diagnostics.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1884,10 +1884,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
18841884
err.span_suggestions_with_style(
18851885
path_span.shrink_to_hi().with_hi(call_span.hi()),
18861886
"you might have meant to use an associated function to build this type",
1887-
items
1888-
.iter()
1889-
.map(|(_, name, len)| suggestion(name, *len))
1890-
.collect::<Vec<String>>(),
1887+
items.iter().map(|(_, name, len)| suggestion(name, *len)),
18911888
Applicability::MaybeIncorrect,
18921889
SuggestionStyle::ShowAlways,
18931890
);

compiler/rustc_trait_selection/src/solve/fulfill.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<'tcx> ObligationStorage<'tcx> {
5757

5858
fn take_pending(&mut self) -> Vec<PredicateObligation<'tcx>> {
5959
let mut obligations = mem::take(&mut self.pending);
60-
obligations.extend(self.overflowed.drain(..));
60+
obligations.append(&mut self.overflowed);
6161
obligations
6262
}
6363

0 commit comments

Comments
 (0)