@@ -942,20 +942,20 @@ fn fetch_cloned_expr<'tcx>(expr: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> {
942
942
}
943
943
}
944
944
945
- fn get_offset < ' tcx > (
945
+ fn get_details_from_idx < ' tcx > (
946
946
cx : & LateContext < ' tcx > ,
947
947
idx : & Expr < ' _ > ,
948
948
starts : & [ Start < ' tcx > ] ,
949
949
) -> Option < ( StartKind < ' tcx > , Offset ) > {
950
- fn extract_start < ' tcx > (
950
+ fn get_start < ' tcx > (
951
951
cx : & LateContext < ' tcx > ,
952
- expr : & Expr < ' _ > ,
952
+ e : & Expr < ' _ > ,
953
953
starts : & [ Start < ' tcx > ] ,
954
954
) -> Option < StartKind < ' tcx > > {
955
- starts. iter ( ) . find ( |var| same_var ( cx, expr , var. id ) ) . map ( |v| v. kind )
955
+ starts. iter ( ) . find ( |var| same_var ( cx, e , var. id ) ) . map ( |v| v. kind )
956
956
}
957
957
958
- fn extract_offset < ' tcx > (
958
+ fn get_offset < ' tcx > (
959
959
cx : & LateContext < ' tcx > ,
960
960
e : & Expr < ' _ > ,
961
961
starts : & [ Start < ' tcx > ] ,
@@ -965,7 +965,7 @@ fn get_offset<'tcx>(
965
965
ast:: LitKind :: Int ( x, _ty) => Some ( MinifyingSugg :: non_paren ( x. to_string ( ) ) ) ,
966
966
_ => None ,
967
967
} ,
968
- ExprKind :: Path ( ..) if extract_start ( cx, e, starts) . is_none ( ) => {
968
+ ExprKind :: Path ( ..) if get_start ( cx, e, starts) . is_none ( ) => {
969
969
// `e` is always non paren as it's a `Path`
970
970
Some ( MinifyingSugg :: non_paren ( snippet ( cx, e. span , "???" ) ) )
971
971
} ,
@@ -976,21 +976,22 @@ fn get_offset<'tcx>(
976
976
match idx. kind {
977
977
ExprKind :: Binary ( op, lhs, rhs) => match op. node {
978
978
BinOpKind :: Add => {
979
- let offset_opt = if let Some ( s) = extract_start ( cx, lhs, starts) {
980
- extract_offset ( cx, rhs, starts) . map ( |o| ( s, o) )
981
- } else if let Some ( s) = extract_start ( cx, rhs, starts) {
982
- extract_offset ( cx, lhs, starts) . map ( |o| ( s, o) )
979
+ let offset_opt = if let Some ( s) = get_start ( cx, lhs, starts) {
980
+ get_offset ( cx, rhs, starts) . map ( |o| ( s, o) )
981
+ } else if let Some ( s) = get_start ( cx, rhs, starts) {
982
+ get_offset ( cx, lhs, starts) . map ( |o| ( s, o) )
983
983
} else {
984
984
None
985
985
} ;
986
986
987
987
offset_opt. map ( |( s, o) | ( s, Offset :: positive ( o) ) )
988
988
} ,
989
- BinOpKind :: Sub => extract_start ( cx, lhs, starts)
990
- . and_then ( |s| extract_offset ( cx, rhs, starts) . map ( |o| ( s, Offset :: negative ( o) ) ) ) ,
989
+ BinOpKind :: Sub => {
990
+ get_start ( cx, lhs, starts) . and_then ( |s| get_offset ( cx, rhs, starts) . map ( |o| ( s, Offset :: negative ( o) ) ) )
991
+ } ,
991
992
_ => None ,
992
993
} ,
993
- ExprKind :: Path ( ..) => extract_start ( cx, idx, starts) . map ( |s| ( s, Offset :: empty ( ) ) ) ,
994
+ ExprKind :: Path ( ..) => get_start ( cx, idx, starts) . map ( |s| ( s, Offset :: empty ( ) ) ) ,
994
995
_ => None ,
995
996
}
996
997
}
@@ -1196,8 +1197,8 @@ fn detect_manual_memcpy<'tcx>(
1196
1197
if let ExprKind :: Index ( base_right, idx_right) = rhs. kind;
1197
1198
if is_slice_like( cx, cx. typeck_results( ) . expr_ty( base_left) )
1198
1199
&& is_slice_like( cx, cx. typeck_results( ) . expr_ty( base_right) ) ;
1199
- if let Some ( ( start_left, offset_left) ) = get_offset ( cx, & idx_left, & starts) ;
1200
- if let Some ( ( start_right, offset_right) ) = get_offset ( cx, & idx_right, & starts) ;
1200
+ if let Some ( ( start_left, offset_left) ) = get_details_from_idx ( cx, & idx_left, & starts) ;
1201
+ if let Some ( ( start_right, offset_right) ) = get_details_from_idx ( cx, & idx_right, & starts) ;
1201
1202
1202
1203
// Source and destination must be different
1203
1204
if var_def_id( cx, base_left) != var_def_id( cx, base_right) ;
0 commit comments