From 679c5be4057597bf6265663d740dbf14210c3291 Mon Sep 17 00:00:00 2001 From: y21 <30553356+y21@users.noreply.github.com> Date: Tue, 9 May 2023 21:36:43 +0200 Subject: [PATCH] add `slice::swap` suggestion --- compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs | 7 ++++--- tests/ui/suggestions/suggest-split-at-mut.stderr | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 04b8174079a..da74b8d8bca 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -972,7 +972,7 @@ pub(crate) fn report_conflicting_borrow( &msg_borrow, None, ); - self.suggest_split_at_mut_if_applicable( + self.suggest_slice_method_if_applicable( &mut err, place, issued_borrow.borrowed_place, @@ -1252,7 +1252,7 @@ fn suggest_using_local_if_applicable( ); } - fn suggest_split_at_mut_if_applicable( + fn suggest_slice_method_if_applicable( &self, err: &mut Diagnostic, place: Place<'tcx>, @@ -1264,7 +1264,8 @@ fn suggest_split_at_mut_if_applicable( err.help( "consider using `.split_at_mut(position)` or similar method to obtain \ two mutable non-overlapping sub-slices", - ); + ) + .help("consider using `.swap(index_1, index_2)` to swap elements at the specified indices"); } } diff --git a/tests/ui/suggestions/suggest-split-at-mut.stderr b/tests/ui/suggestions/suggest-split-at-mut.stderr index 330f012b2a9..bb185138383 100644 --- a/tests/ui/suggestions/suggest-split-at-mut.stderr +++ b/tests/ui/suggestions/suggest-split-at-mut.stderr @@ -9,6 +9,7 @@ LL | *a = 5; | ------ first borrow later used here | = help: consider using `.split_at_mut(position)` or similar method to obtain two mutable non-overlapping sub-slices + = help: consider using `.swap(index_1, index_2)` to swap elements at the specified indices error: aborting due to previous error