From 7a48987006c1d69cb59fc253bbe2ad097af82645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 2 Mar 2024 14:18:47 +0100 Subject: [PATCH] avoid collecting into vecs in some places --- .../src/coverageinfo/mapgen.rs | 36 +++++++++---------- .../rustc_hir_analysis/src/astconv/mod.rs | 5 +-- compiler/rustc_hir_typeck/src/expr.rs | 5 +-- .../rustc_resolve/src/late/diagnostics.rs | 5 +-- .../src/solve/fulfill.rs | 2 +- 5 files changed, 20 insertions(+), 33 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs index 6116a6fd222..c45787f35aa 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs @@ -357,31 +357,27 @@ fn add_unused_functions(cx: &CodegenCx<'_, '_>) { let ignore_unused_generics = tcx.sess.instrument_coverage_except_unused_generics(); - let eligible_def_ids: Vec = tcx - .mir_keys(()) - .iter() - .filter_map(|local_def_id| { - let def_id = local_def_id.to_def_id(); - let kind = tcx.def_kind(def_id); - // `mir_keys` will give us `DefId`s for all kinds of things, not - // just "functions", like consts, statics, etc. Filter those out. - // If `ignore_unused_generics` was specified, filter out any - // generic functions from consideration as well. - if !matches!(kind, DefKind::Fn | DefKind::AssocFn | DefKind::Closure) { - return None; - } - if ignore_unused_generics && tcx.generics_of(def_id).requires_monomorphization(tcx) { - return None; - } - Some(local_def_id.to_def_id()) - }) - .collect(); + let eligible_def_ids = tcx.mir_keys(()).iter().filter_map(|local_def_id| { + let def_id = local_def_id.to_def_id(); + let kind = tcx.def_kind(def_id); + // `mir_keys` will give us `DefId`s for all kinds of things, not + // just "functions", like consts, statics, etc. Filter those out. + // If `ignore_unused_generics` was specified, filter out any + // generic functions from consideration as well. + if !matches!(kind, DefKind::Fn | DefKind::AssocFn | DefKind::Closure) { + return None; + } + if ignore_unused_generics && tcx.generics_of(def_id).requires_monomorphization(tcx) { + return None; + } + Some(local_def_id.to_def_id()) + }); let codegenned_def_ids = codegenned_and_inlined_items(tcx); // For each `DefId` that should have coverage instrumentation but wasn't // codegenned, add it to the function coverage map as an unused function. - for def_id in eligible_def_ids.into_iter().filter(|id| !codegenned_def_ids.contains(id)) { + for def_id in eligible_def_ids.filter(|id| !codegenned_def_ids.contains(id)) { // Skip any function that didn't have coverage data added to it by the // coverage instrumentor. let body = tcx.instance_mir(ty::InstanceDef::Item(def_id)); diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 218891a7c67..b8cf72c2c73 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -860,10 +860,7 @@ fn report_ambiguous_associated_type( traits with associated type `{name}`, you could use the \ fully-qualified path", ), - traits - .iter() - .map(|trait_str| format!("::{name}")) - .collect::>(), + traits.iter().map(|trait_str| format!("::{name}")), Applicability::HasPlaceholders, ); } diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 054be89a7c4..b8cceebe103 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -2156,10 +2156,7 @@ fn report_private_fields( err.span_suggestions( span.shrink_to_hi().with_hi(expr_span.hi()), "you might have meant to use an associated function to build this type", - items - .iter() - .map(|(_, name, args)| suggestion(name, *args)) - .collect::>(), + items.iter().map(|(_, name, args)| suggestion(name, *args)), Applicability::MaybeIncorrect, ); } diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 327884c8414..d008346af69 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1884,10 +1884,7 @@ fn suggest_alternative_construction_methods( err.span_suggestions_with_style( path_span.shrink_to_hi().with_hi(call_span.hi()), "you might have meant to use an associated function to build this type", - items - .iter() - .map(|(_, name, len)| suggestion(name, *len)) - .collect::>(), + items.iter().map(|(_, name, len)| suggestion(name, *len)), Applicability::MaybeIncorrect, SuggestionStyle::ShowAlways, ); diff --git a/compiler/rustc_trait_selection/src/solve/fulfill.rs b/compiler/rustc_trait_selection/src/solve/fulfill.rs index bc2bae9da61..3fa409eefff 100644 --- a/compiler/rustc_trait_selection/src/solve/fulfill.rs +++ b/compiler/rustc_trait_selection/src/solve/fulfill.rs @@ -57,7 +57,7 @@ fn clone_pending(&self) -> Vec> { fn take_pending(&mut self) -> Vec> { let mut obligations = mem::take(&mut self.pending); - obligations.extend(self.overflowed.drain(..)); + obligations.append(&mut self.overflowed); obligations }