Skip to content

Commit 679c5be

Browse files
committed
add slice::swap suggestion
1 parent a0111af commit 679c5be

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
972972
&msg_borrow,
973973
None,
974974
);
975-
self.suggest_split_at_mut_if_applicable(
975+
self.suggest_slice_method_if_applicable(
976976
&mut err,
977977
place,
978978
issued_borrow.borrowed_place,
@@ -1252,7 +1252,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12521252
);
12531253
}
12541254

1255-
fn suggest_split_at_mut_if_applicable(
1255+
fn suggest_slice_method_if_applicable(
12561256
&self,
12571257
err: &mut Diagnostic,
12581258
place: Place<'tcx>,
@@ -1264,7 +1264,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12641264
err.help(
12651265
"consider using `.split_at_mut(position)` or similar method to obtain \
12661266
two mutable non-overlapping sub-slices",
1267-
);
1267+
)
1268+
.help("consider using `.swap(index_1, index_2)` to swap elements at the specified indices");
12681269
}
12691270
}
12701271

tests/ui/suggestions/suggest-split-at-mut.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ LL | *a = 5;
99
| ------ first borrow later used here
1010
|
1111
= help: consider using `.split_at_mut(position)` or similar method to obtain two mutable non-overlapping sub-slices
12+
= help: consider using `.swap(index_1, index_2)` to swap elements at the specified indices
1213

1314
error: aborting due to previous error
1415

0 commit comments

Comments
 (0)