Rollup merge of #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.
This commit is contained in:
commit
fcf81b8cc3
3 changed files with 13 additions and 16 deletions
|
@ -2680,22 +2680,19 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut sugg = vec![];
|
|
||||||
let sm = self.infcx.tcx.sess.source_map();
|
let sm = self.infcx.tcx.sess.source_map();
|
||||||
|
let sugg = finder
|
||||||
if let Some(span) = finder.closure_arg_span {
|
.closure_arg_span
|
||||||
sugg.push((sm.next_point(span.shrink_to_lo()).shrink_to_hi(), finder.suggest_arg));
|
.map(|span| (sm.next_point(span.shrink_to_lo()).shrink_to_hi(), finder.suggest_arg))
|
||||||
}
|
.into_iter()
|
||||||
for span in finder.closure_change_spans {
|
.chain(
|
||||||
sugg.push((span, "this".to_string()));
|
finder.closure_change_spans.into_iter().map(|span| (span, "this".to_string())),
|
||||||
}
|
)
|
||||||
|
.chain(finder.closure_call_changes)
|
||||||
for (span, suggest) in finder.closure_call_changes {
|
.collect();
|
||||||
sugg.push((span, suggest));
|
|
||||||
}
|
|
||||||
|
|
||||||
err.multipart_suggestion_verbose(
|
err.multipart_suggestion_verbose(
|
||||||
"try explicitly pass `&Self` into the Closure as an argument",
|
"try explicitly passing `&Self` into the closure as an argument",
|
||||||
sugg,
|
sugg,
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
|
|
|
@ -880,7 +880,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
|
||||||
)
|
)
|
||||||
} }
|
} }
|
||||||
|
|
||||||
/// Show a suggestion that has multiple parts to it, always as it's own subdiagnostic.
|
/// Show a suggestion that has multiple parts to it, always as its own subdiagnostic.
|
||||||
/// In other words, multiple changes need to be applied as part of this suggestion.
|
/// In other words, multiple changes need to be applied as part of this suggestion.
|
||||||
#[rustc_lint_diagnostics]
|
#[rustc_lint_diagnostics]
|
||||||
pub fn multipart_suggestion_verbose(
|
pub fn multipart_suggestion_verbose(
|
||||||
|
|
|
@ -11,7 +11,7 @@ LL | self.qux();
|
||||||
LL | x(1);
|
LL | x(1);
|
||||||
| - immutable borrow later used here
|
| - immutable borrow later used here
|
||||||
|
|
|
|
||||||
help: try explicitly pass `&Self` into the Closure as an argument
|
help: try explicitly passing `&Self` into the closure as an argument
|
||||||
|
|
|
|
||||||
LL ~ let x = |this: &Self, v: i32| {
|
LL ~ let x = |this: &Self, v: i32| {
|
||||||
LL ~ this.bar();
|
LL ~ this.bar();
|
||||||
|
@ -35,7 +35,7 @@ LL | self.qux();
|
||||||
LL | y();
|
LL | y();
|
||||||
| - immutable borrow later used here
|
| - immutable borrow later used here
|
||||||
|
|
|
|
||||||
help: try explicitly pass `&Self` into the Closure as an argument
|
help: try explicitly passing `&Self` into the closure as an argument
|
||||||
|
|
|
|
||||||
LL ~ let y = |this: &Self| {
|
LL ~ let y = |this: &Self| {
|
||||||
LL ~ this.bar();
|
LL ~ this.bar();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue