Skip to content

Commit 27b0693

Browse files
committed
collect diag suggestions instead of pushing into vector repeatedly
1 parent 6680bc5 commit 27b0693

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -2680,19 +2680,16 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
26802680
return;
26812681
}
26822682

2683-
let mut sugg = vec![];
26842683
let sm = self.infcx.tcx.sess.source_map();
2685-
2686-
if let Some(span) = finder.closure_arg_span {
2687-
sugg.push((sm.next_point(span.shrink_to_lo()).shrink_to_hi(), finder.suggest_arg));
2688-
}
2689-
for span in finder.closure_change_spans {
2690-
sugg.push((span, "this".to_string()));
2691-
}
2692-
2693-
for (span, suggest) in finder.closure_call_changes {
2694-
sugg.push((span, suggest));
2695-
}
2684+
let sugg = finder
2685+
.closure_arg_span
2686+
.map(|span| (sm.next_point(span.shrink_to_lo()).shrink_to_hi(), finder.suggest_arg))
2687+
.into_iter()
2688+
.chain(
2689+
finder.closure_change_spans.into_iter().map(|span| (span, "this".to_string())),
2690+
)
2691+
.chain(finder.closure_call_changes)
2692+
.collect();
26962693

26972694
err.multipart_suggestion_verbose(
26982695
"try explicitly passing `&Self` into the closure as an argument",

0 commit comments

Comments
 (0)