@@ -812,8 +812,8 @@ impl Offset {
812812 }
813813}
814814
815- struct FixedOffsetVar {
816- var_name : String ,
815+ struct FixedOffsetVar < ' hir > {
816+ var : & ' hir Expr < ' hir > ,
817817 offset : Offset ,
818818}
819819
@@ -947,13 +947,13 @@ fn detect_manual_memcpy<'a, 'tcx>(
947947 }
948948 }
949949
950- let print_limit = |end : & Expr < ' _ > , offset : Offset , var_name : & str | {
950+ let print_limit = |end : & Expr < ' _ > , offset : Offset , var : & Expr < ' _ > | {
951951 if_chain ! {
952952 if let ExprKind :: MethodCall ( method, _, len_args) = end. kind;
953953 if method. ident. name == sym!( len) ;
954954 if len_args. len( ) == 1 ;
955955 if let Some ( arg) = len_args. get( 0 ) ;
956- if snippet ( cx, arg. span , "??" ) == var_name ;
956+ if var_def_id ( cx, arg) == var_def_id ( cx , var ) ;
957957 then {
958958 match offset. sign {
959959 OffsetSign :: Negative => format!( "({} - {})" , snippet( cx, end. span, "<src>.len()" ) , offset. value) ,
@@ -986,14 +986,12 @@ fn detect_manual_memcpy<'a, 'tcx>(
986986 && is_slice_like( cx, cx. tables. expr_ty( seqexpr_right) ) ;
987987 if let Some ( offset_left) = get_offset( cx, & idx_left, canonical_id) ;
988988 if let Some ( offset_right) = get_offset( cx, & idx_right, canonical_id) ;
989- let var_name_left = snippet_opt( cx, seqexpr_left. span) . unwrap_or_else( || "???" . into( ) ) ;
990- let var_name_right = snippet_opt( cx, seqexpr_right. span) . unwrap_or_else( || "???" . into( ) ) ;
991989
992990 // Source and destination must be different
993- if var_name_left != var_name_right ;
991+ if var_def_id ( cx , seqexpr_left ) != var_def_id ( cx , seqexpr_right ) ;
994992 then {
995- Some ( ( FixedOffsetVar { var_name : var_name_left , offset: offset_left } ,
996- FixedOffsetVar { var_name : var_name_right , offset: offset_right } ) )
993+ Some ( ( FixedOffsetVar { var : seqexpr_left , offset: offset_left } ,
994+ FixedOffsetVar { var : seqexpr_right , offset: offset_right } ) )
997995 } else {
998996 None
999997 }
@@ -1004,18 +1002,22 @@ fn detect_manual_memcpy<'a, 'tcx>(
10041002 o. map ( |( dst_var, src_var) | {
10051003 let start_str = snippet ( cx, start. span , "" ) . to_string ( ) ;
10061004 let dst_offset = print_offset ( & start_str, & dst_var. offset ) ;
1007- let dst_limit = print_limit ( end, dst_var. offset , & dst_var. var_name ) ;
1005+ let dst_limit = print_limit ( end, dst_var. offset , dst_var. var ) ;
10081006 let src_offset = print_offset ( & start_str, & src_var. offset ) ;
1009- let src_limit = print_limit ( end, src_var. offset , & src_var. var_name ) ;
1007+ let src_limit = print_limit ( end, src_var. offset , src_var. var ) ;
1008+
1009+ let dst_var_name = snippet_opt ( cx, dst_var. var . span ) . unwrap_or_else ( || "???" . into ( ) ) ;
1010+ let src_var_name = snippet_opt ( cx, src_var. var . span ) . unwrap_or_else ( || "???" . into ( ) ) ;
1011+
10101012 let dst = if dst_offset == "" && dst_limit == "" {
1011- dst_var . var_name
1013+ dst_var_name
10121014 } else {
1013- format ! ( "{}[{}..{}]" , dst_var . var_name , dst_offset, dst_limit)
1015+ format ! ( "{}[{}..{}]" , dst_var_name , dst_offset, dst_limit)
10141016 } ;
10151017
10161018 format ! (
10171019 "{}.clone_from_slice(&{}[{}..{}])" ,
1018- dst, src_var . var_name , src_offset, src_limit
1020+ dst, src_var_name , src_offset, src_limit
10191021 )
10201022 } )
10211023 } )
0 commit comments