@@ -2018,12 +2018,25 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
2018
2018
) {
2019
2019
let tcx = self . infcx . tcx ;
2020
2020
let hir = tcx. hir ( ) ;
2021
+
2022
+ let has_split_at_mut = |ty : Ty < ' tcx > | {
2023
+ let ty = ty. peel_refs ( ) ;
2024
+ match ty. kind ( ) {
2025
+ ty:: Array ( ..) | ty:: Slice ( ..) => true ,
2026
+ ty:: Adt ( def, _) if tcx. get_diagnostic_item ( sym:: Vec ) == Some ( def. did ( ) ) => true ,
2027
+ _ if ty == tcx. types . str_ => true ,
2028
+ _ => false ,
2029
+ }
2030
+ } ;
2021
2031
if let ( [ ProjectionElem :: Index ( index1) ] , [ ProjectionElem :: Index ( index2) ] )
2022
2032
| (
2023
2033
[ ProjectionElem :: Deref , ProjectionElem :: Index ( index1) ] ,
2024
2034
[ ProjectionElem :: Deref , ProjectionElem :: Index ( index2) ] ,
2025
2035
) = ( & place. projection [ ..] , & borrowed_place. projection [ ..] )
2026
2036
{
2037
+ let decl1 = & self . body . local_decls [ * index1] ;
2038
+ let decl2 = & self . body . local_decls [ * index2] ;
2039
+
2027
2040
let mut note_default_suggestion = || {
2028
2041
err. help (
2029
2042
"consider using `.split_at_mut(position)` or similar method to obtain two \
@@ -2035,14 +2048,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
2035
2048
) ;
2036
2049
} ;
2037
2050
2038
- let Some ( index1) = self . find_expr ( self . body . local_decls [ * index1] . source_info . span )
2039
- else {
2051
+ let Some ( index1) = self . find_expr ( decl1. source_info . span ) else {
2040
2052
note_default_suggestion ( ) ;
2041
2053
return ;
2042
2054
} ;
2043
2055
2044
- let Some ( index2) = self . find_expr ( self . body . local_decls [ * index2] . source_info . span )
2045
- else {
2056
+ let Some ( index2) = self . find_expr ( decl2. source_info . span ) else {
2046
2057
note_default_suggestion ( ) ;
2047
2058
return ;
2048
2059
} ;
@@ -2102,16 +2113,19 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
2102
2113
) ;
2103
2114
return ;
2104
2115
}
2116
+ let place_ty = PlaceRef :: ty ( & place. as_ref ( ) , self . body , tcx) . ty ;
2117
+ let borrowed_place_ty = PlaceRef :: ty ( & borrowed_place. as_ref ( ) , self . body , tcx) . ty ;
2118
+ if !has_split_at_mut ( place_ty) && !has_split_at_mut ( borrowed_place_ty) {
2119
+ // Only mention `split_at_mut` on `Vec`, array and slices.
2120
+ return ;
2121
+ }
2105
2122
let Some ( index1) = self . find_expr ( span) else { return } ;
2106
2123
let hir:: Node :: Expr ( parent) = tcx. parent_hir_node ( index1. hir_id ) else { return } ;
2107
2124
let hir:: ExprKind :: Index ( ..) = parent. kind else { return } ;
2108
2125
let Some ( index2) = self . find_expr ( issued_span) else { return } ;
2109
2126
let hir:: Node :: Expr ( parent) = tcx. parent_hir_node ( index2. hir_id ) else { return } ;
2110
2127
let hir:: ExprKind :: Index ( ..) = parent. kind else { return } ;
2111
- err. help (
2112
- "use `.split_at_mut(position)` or similar method to obtain two mutable non-overlapping \
2113
- sub-slices",
2114
- ) ;
2128
+ err. help ( "use `.split_at_mut(position)` to obtain two mutable non-overlapping sub-slices" ) ;
2115
2129
}
2116
2130
2117
2131
/// Suggest using `while let` for call `next` on an iterator in a for loop.
0 commit comments