Skip to content

Commit 883d0a7

Browse files
committed
Use Vec extend instead of repeated pushes in several places
1 parent e6b883c commit 883d0a7

File tree

5 files changed

+6
-16
lines changed

5 files changed

+6
-16
lines changed

compiler/rustc_mir_transform/src/coverage/spans.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,7 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
329329
fn mir_to_initial_sorted_coverage_spans(&self) -> Vec<CoverageSpan> {
330330
let mut initial_spans = Vec::<CoverageSpan>::with_capacity(self.mir_body.num_nodes() * 2);
331331
for (bcb, bcb_data) in self.basic_coverage_blocks.iter_enumerated() {
332-
for coverage_span in self.bcb_to_initial_coverage_spans(bcb, bcb_data) {
333-
initial_spans.push(coverage_span);
334-
}
332+
initial_spans.extend(self.bcb_to_initial_coverage_spans(bcb, bcb_data));
335333
}
336334

337335
if initial_spans.is_empty() {

compiler/rustc_trait_selection/src/traits/coherence.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,7 @@ fn orphan_check_trait_ref<'tcx>(
498498
return Err(OrphanCheckErr::UncoveredTy(input_ty, local_type));
499499
}
500500

501-
for input_ty in non_local_tys {
502-
non_local_spans.push((input_ty, i == 0));
503-
}
501+
non_local_spans.extend(non_local_tys.into_iter().map(|input_ty| (input_ty, i == 0)));
504502
}
505503
// If we exit above loop, never found a local type.
506504
debug!("orphan_check_trait_ref: no local type");

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
362362
.infcx
363363
.probe(|_| self.match_projection_obligation_against_definition_bounds(obligation));
364364

365-
for predicate_index in result {
366-
candidates.vec.push(ProjectionCandidate(predicate_index));
367-
}
365+
candidates.vec.extend(result.into_iter().map(ProjectionCandidate));
368366
}
369367

370368
/// Given an obligation like `<SomeTrait for T>`, searches the obligations that the caller

compiler/rustc_typeck/src/check/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -686,9 +686,8 @@ fn bounds_from_generic_predicates<'tcx>(
686686
};
687687
let mut where_clauses = vec![];
688688
for (ty, bounds) in types {
689-
for bound in &bounds {
690-
where_clauses.push(format!("{}: {}", ty, tcx.def_path_str(*bound)));
691-
}
689+
where_clauses
690+
.extend(bounds.into_iter().map(|bound| format!("{}: {}", ty, tcx.def_path_str(bound))));
692691
}
693692
for projection in &projections {
694693
let p = projection.skip_binder();

compiler/rustc_typeck/src/check/upvar.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -904,10 +904,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
904904
) -> MigrationWarningReason {
905905
let mut reasons = MigrationWarningReason::default();
906906

907-
for auto_trait in auto_trait_reasons {
908-
reasons.auto_traits.push(auto_trait);
909-
}
910-
907+
reasons.auto_traits.extend(auto_trait_reasons);
911908
reasons.drop_order = drop_order;
912909

913910
reasons

0 commit comments

Comments
 (0)