Skip to content

Commit fcf81b8

Browse files
authored
Rollup merge of rust-lang#135364 - yotamofek:borrowck-diag-fix, r=compiler-errors
Cleanup `suggest_binding_for_closure_capture_self` diag in borrowck Mostly grammar fix/improvement, but also a small cleanup to use iterators instead of for loops for collecting into a vector.
2 parents a18a71b + 27b0693 commit fcf81b8

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -2680,22 +2680,19 @@ 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(
2698-
"try explicitly pass `&Self` into the Closure as an argument",
2695+
"try explicitly passing `&Self` into the closure as an argument",
26992696
sugg,
27002697
Applicability::MachineApplicable,
27012698
);

compiler/rustc_errors/src/diagnostic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
880880
)
881881
} }
882882

883-
/// Show a suggestion that has multiple parts to it, always as it's own subdiagnostic.
883+
/// Show a suggestion that has multiple parts to it, always as its own subdiagnostic.
884884
/// In other words, multiple changes need to be applied as part of this suggestion.
885885
#[rustc_lint_diagnostics]
886886
pub fn multipart_suggestion_verbose(

tests/ui/suggestions/issue-105761-suggest-self-for-closure.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | self.qux();
1111
LL | x(1);
1212
| - immutable borrow later used here
1313
|
14-
help: try explicitly pass `&Self` into the Closure as an argument
14+
help: try explicitly passing `&Self` into the closure as an argument
1515
|
1616
LL ~ let x = |this: &Self, v: i32| {
1717
LL ~ this.bar();
@@ -35,7 +35,7 @@ LL | self.qux();
3535
LL | y();
3636
| - immutable borrow later used here
3737
|
38-
help: try explicitly pass `&Self` into the Closure as an argument
38+
help: try explicitly passing `&Self` into the closure as an argument
3939
|
4040
LL ~ let y = |this: &Self| {
4141
LL ~ this.bar();

0 commit comments

Comments
 (0)