@@ -75,18 +75,7 @@ pub(super) fn check<'tcx>(
7575 if let Some ( ( start_left, offset_left) ) = get_details_from_idx( cx, idx_left, starts) ;
7676 if let Some ( ( start_right, offset_right) ) = get_details_from_idx( cx, idx_right, starts) ;
7777
78- // in order to be a memmove-type loop, read indices must be iterated
79- // over at a later point than written indices. we currently enforce
80- // this by ensuring that:
81- //
82- // - rhs is `path + offset` with offset >= 0
83- // - lhs is just `path` (same path as rhs)
84- if let ExprKind :: Binary ( idx_right_op, idx_right_lhs, idx_right_rhs) = idx_right. kind;
85- if let Some ( idx_right_local) = path_to_local( idx_right_lhs) ;
86- if let Some ( idx_left_local) = path_to_local( idx_left) ;
87- if idx_right_local == idx_left_local;
88- if let BinOpKind :: Add = idx_right_op. node;
89- if is_positive_offset( cx, idx_right_rhs) ;
78+ if left_is_smaller_than_right( cx, idx_left, idx_right) ;
9079
9180 if let StartKind :: Range = start_left;
9281 if let StartKind :: Range = start_right;
@@ -217,7 +206,28 @@ fn build_manual_memmove_suggestion<'tcx>(
217206 )
218207}
219208
220- fn is_positive_offset < ' tcx > ( cx : & LateContext < ' tcx > , offset : & ' tcx Expr < ' _ > ) -> bool {
221- // the variable/item referred to has an uint type, therefore offset is positive
222- matches ! ( cx. typeck_results( ) . expr_ty( offset) . kind( ) , ty:: Uint ( _) )
209+ fn left_is_smaller_than_right < ' tcx > (
210+ cx : & LateContext < ' tcx > ,
211+ idx_left : & ' tcx Expr < ' _ > ,
212+ idx_right : & ' tcx Expr < ' _ > ,
213+ ) -> bool {
214+ // in order to be a memmove-type loop, read indices must be iterated
215+ // over at a later point than written indices. we currently enforce
216+ // this by ensuring that:
217+ //
218+ // - rhs is `path + offset` with offset >= 0
219+ // - lhs is just `path` (same path as rhs)
220+ if_chain ! {
221+ if let ExprKind :: Binary ( idx_right_op, idx_right_lhs, idx_right_rhs) = idx_right. kind;
222+ if idx_right_op. node == BinOpKind :: Add ;
223+ if let Some ( idx_left_local) = path_to_local( idx_left) ;
224+ if let Some ( idx_right_local) = path_to_local( idx_right_lhs) ;
225+ if idx_right_local == idx_left_local;
226+ if let ty:: Uint ( _) = cx. typeck_results( ) . expr_ty( idx_right_rhs) . kind( ) ;
227+ then {
228+ true
229+ } else {
230+ false
231+ }
232+ }
223233}
0 commit comments