@@ -1981,12 +1981,25 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1981
1981
) {
1982
1982
let tcx = self . infcx . tcx ;
1983
1983
let hir = tcx. hir ( ) ;
1984
+
1985
+ let has_split_at_mut = |ty : Ty < ' tcx > | {
1986
+ let ty = ty. peel_refs ( ) ;
1987
+ match ty. kind ( ) {
1988
+ ty:: Array ( ..) | ty:: Slice ( ..) => true ,
1989
+ ty:: Adt ( def, _) if tcx. get_diagnostic_item ( sym:: Vec ) == Some ( def. did ( ) ) => true ,
1990
+ _ if ty == tcx. types . str_ => true ,
1991
+ _ => false ,
1992
+ }
1993
+ } ;
1984
1994
if let ( [ ProjectionElem :: Index ( index1) ] , [ ProjectionElem :: Index ( index2) ] )
1985
1995
| (
1986
1996
[ ProjectionElem :: Deref , ProjectionElem :: Index ( index1) ] ,
1987
1997
[ ProjectionElem :: Deref , ProjectionElem :: Index ( index2) ] ,
1988
1998
) = ( & place. projection [ ..] , & borrowed_place. projection [ ..] )
1989
1999
{
2000
+ let decl1 = & self . body . local_decls [ * index1] ;
2001
+ let decl2 = & self . body . local_decls [ * index2] ;
2002
+
1990
2003
let mut note_default_suggestion = || {
1991
2004
err. help (
1992
2005
"consider using `.split_at_mut(position)` or similar method to obtain two \
@@ -1998,14 +2011,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1998
2011
) ;
1999
2012
} ;
2000
2013
2001
- let Some ( index1) = self . find_expr ( self . body . local_decls [ * index1] . source_info . span )
2002
- else {
2014
+ let Some ( index1) = self . find_expr ( decl1. source_info . span ) else {
2003
2015
note_default_suggestion ( ) ;
2004
2016
return ;
2005
2017
} ;
2006
2018
2007
- let Some ( index2) = self . find_expr ( self . body . local_decls [ * index2] . source_info . span )
2008
- else {
2019
+ let Some ( index2) = self . find_expr ( decl2. source_info . span ) else {
2009
2020
note_default_suggestion ( ) ;
2010
2021
return ;
2011
2022
} ;
@@ -2065,16 +2076,19 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
2065
2076
) ;
2066
2077
return ;
2067
2078
}
2079
+ let place_ty = PlaceRef :: ty ( & place. as_ref ( ) , self . body , tcx) . ty ;
2080
+ let borrowed_place_ty = PlaceRef :: ty ( & borrowed_place. as_ref ( ) , self . body , tcx) . ty ;
2081
+ if !has_split_at_mut ( place_ty) && !has_split_at_mut ( borrowed_place_ty) {
2082
+ // Only mention `split_at_mut` on `Vec`, array and slices.
2083
+ return ;
2084
+ }
2068
2085
let Some ( index1) = self . find_expr ( span) else { return } ;
2069
2086
let hir:: Node :: Expr ( parent) = tcx. parent_hir_node ( index1. hir_id ) else { return } ;
2070
2087
let hir:: ExprKind :: Index ( ..) = parent. kind else { return } ;
2071
2088
let Some ( index2) = self . find_expr ( issued_span) else { return } ;
2072
2089
let hir:: Node :: Expr ( parent) = tcx. parent_hir_node ( index2. hir_id ) else { return } ;
2073
2090
let hir:: ExprKind :: Index ( ..) = parent. kind else { return } ;
2074
- err. help (
2075
- "use `.split_at_mut(position)` or similar method to obtain two mutable non-overlapping \
2076
- sub-slices",
2077
- ) ;
2091
+ err. help ( "use `.split_at_mut(position)` to obtain two mutable non-overlapping sub-slices" ) ;
2078
2092
}
2079
2093
2080
2094
/// Suggest using `while let` for call `next` on an iterator in a for loop.
0 commit comments