From 86d2129a780233ab0162ce00a29ea8e95c5e8bbb Mon Sep 17 00:00:00 2001 From: Yotam Ofek Date: Sat, 11 Jan 2025 13:16:56 +0000 Subject: [PATCH 1/3] fix `it's` -> `its` in doc comment --- compiler/rustc_errors/src/diagnostic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index afce877547f3e..797dcd7b4d1df 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -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. #[rustc_lint_diagnostics] pub fn multipart_suggestion_verbose( From 6680bc555413841c81921553af01e2bf70a9244c Mon Sep 17 00:00:00 2001 From: Yotam Ofek Date: Sat, 11 Jan 2025 13:20:17 +0000 Subject: [PATCH 2/3] improve clunky grammar in borrowck diagnostic --- compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs | 2 +- .../suggestions/issue-105761-suggest-self-for-closure.stderr | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 2d993a3fd16f7..69afc1995e73c 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -2695,7 +2695,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { } 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, Applicability::MachineApplicable, ); diff --git a/tests/ui/suggestions/issue-105761-suggest-self-for-closure.stderr b/tests/ui/suggestions/issue-105761-suggest-self-for-closure.stderr index bc97d32ebb6e5..8ddea4b222e98 100644 --- a/tests/ui/suggestions/issue-105761-suggest-self-for-closure.stderr +++ b/tests/ui/suggestions/issue-105761-suggest-self-for-closure.stderr @@ -11,7 +11,7 @@ LL | self.qux(); LL | x(1); | - 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 ~ this.bar(); @@ -35,7 +35,7 @@ LL | self.qux(); LL | y(); | - 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 ~ this.bar(); From 27b069346404eea510e71e3bb3f649b4413c0b3d Mon Sep 17 00:00:00 2001 From: Yotam Ofek Date: Sat, 11 Jan 2025 13:21:15 +0000 Subject: [PATCH 3/3] collect diag suggestions instead of pushing into vector repeatedly --- .../src/diagnostics/conflict_errors.rs | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 69afc1995e73c..4d19d89b3ce24 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -2680,19 +2680,16 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { return; } - let mut sugg = vec![]; let sm = self.infcx.tcx.sess.source_map(); - - if let Some(span) = finder.closure_arg_span { - sugg.push((sm.next_point(span.shrink_to_lo()).shrink_to_hi(), finder.suggest_arg)); - } - for span in finder.closure_change_spans { - sugg.push((span, "this".to_string())); - } - - for (span, suggest) in finder.closure_call_changes { - sugg.push((span, suggest)); - } + let sugg = finder + .closure_arg_span + .map(|span| (sm.next_point(span.shrink_to_lo()).shrink_to_hi(), finder.suggest_arg)) + .into_iter() + .chain( + finder.closure_change_spans.into_iter().map(|span| (span, "this".to_string())), + ) + .chain(finder.closure_call_changes) + .collect(); err.multipart_suggestion_verbose( "try explicitly passing `&Self` into the closure as an argument",