@@ -828,6 +828,16 @@ fn is_slice_like<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'_>) -> bool {
828
828
is_slice || is_type_diagnostic_item ( cx, ty, sym ! ( vec_type) ) || is_type_diagnostic_item ( cx, ty, sym ! ( vecdeque_type) )
829
829
}
830
830
831
+ fn fetch_cloned_expr < ' tcx > ( expr : & ' tcx Expr < ' tcx > ) -> & ' tcx Expr < ' tcx > {
832
+ if_chain ! {
833
+ if let ExprKind :: MethodCall ( method, _, args) = expr. kind;
834
+ if method. ident. name == sym!( clone) ;
835
+ if args. len( ) == 1 ;
836
+ if let Some ( arg) = args. get( 0 ) ;
837
+ then { arg } else { expr }
838
+ }
839
+ }
840
+
831
841
fn get_fixed_offset_var < ' a , ' tcx > ( cx : & LateContext < ' a , ' tcx > , expr : & Expr < ' _ > , var : HirId ) -> Option < FixedOffsetVar > {
832
842
fn extract_offset < ' a , ' tcx > ( cx : & LateContext < ' a , ' tcx > , e : & Expr < ' _ > , var : HirId ) -> Option < String > {
833
843
match & e. kind {
@@ -875,24 +885,6 @@ fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>, v
875
885
}
876
886
}
877
887
878
- fn fetch_cloned_fixed_offset_var < ' a , ' tcx > (
879
- cx : & LateContext < ' a , ' tcx > ,
880
- expr : & Expr < ' _ > ,
881
- var : HirId ,
882
- ) -> Option < FixedOffsetVar > {
883
- if_chain ! {
884
- if let ExprKind :: MethodCall ( method, _, args) = expr. kind;
885
- if method. ident. name == sym!( clone) ;
886
- if args. len( ) == 1 ;
887
- if let Some ( arg) = args. get( 0 ) ;
888
- then {
889
- get_fixed_offset_var( cx, arg, var)
890
- } else {
891
- get_fixed_offset_var( cx, expr, var)
892
- }
893
- }
894
- }
895
-
896
888
fn get_indexed_assignments < ' a , ' tcx > (
897
889
cx : & LateContext < ' a , ' tcx > ,
898
890
body : & Expr < ' _ > ,
@@ -906,7 +898,7 @@ fn get_indexed_assignments<'a, 'tcx>(
906
898
if let ExprKind :: Assign ( lhs, rhs, _) = e. kind {
907
899
match (
908
900
get_fixed_offset_var ( cx, lhs, var) ,
909
- fetch_cloned_fixed_offset_var ( cx, rhs, var) ,
901
+ get_fixed_offset_var ( cx, fetch_cloned_expr ( rhs) , var) ,
910
902
) {
911
903
( Some ( offset_left) , Some ( offset_right) ) => {
912
904
// Source and destination must be different
0 commit comments