@@ -3,6 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
3
3
use clippy_utils:: source:: snippet;
4
4
use clippy_utils:: sugg:: Sugg ;
5
5
use clippy_utils:: ty:: is_copy;
6
+ use clippy_utils:: usage:: local_used_in;
6
7
use clippy_utils:: { get_enclosing_block, higher, path_to_local, sugg} ;
7
8
use rustc_ast:: ast;
8
9
use rustc_errors:: Applicability ;
@@ -59,13 +60,13 @@ pub(super) fn check<'tcx>(
59
60
let rhs = fetch_cloned_expr ( rhs) ;
60
61
if let ExprKind :: Index ( base_left, idx_left, _) = lhs. kind
61
62
&& let ExprKind :: Index ( base_right, idx_right, _) = rhs. kind
62
- && is_index_suggestable ( base_left) && is_index_suggestable ( base_right)
63
63
&& let Some ( ty) = get_slice_like_element_ty ( cx, cx. typeck_results ( ) . expr_ty ( base_left) )
64
64
&& get_slice_like_element_ty ( cx, cx. typeck_results ( ) . expr_ty ( base_right) ) . is_some ( )
65
65
&& let Some ( ( start_left, offset_left) ) = get_details_from_idx ( cx, idx_left, & starts)
66
66
&& let Some ( ( start_right, offset_right) ) = get_details_from_idx ( cx, idx_right, & starts)
67
-
68
- // Source and destination must be different
67
+ && !local_used_in ( cx, canonical_id, base_left)
68
+ && !local_used_in ( cx, canonical_id, base_right)
69
+ // Source and destination must be different
69
70
&& path_to_local ( base_left) != path_to_local ( base_right)
70
71
{
71
72
Some ( (
@@ -487,19 +488,3 @@ fn is_array_length_equal_to_range(cx: &LateContext<'_>, start: &Expr<'_>, end: &
487
488
false
488
489
}
489
490
}
490
-
491
- // Returns true if index is suggestable
492
- // i.e. Returns false if patterns are Index(Path(_), Path(_)) or Index(Index(_, _, _), Path(_))
493
- fn is_index_suggestable ( expr : & Expr < ' _ > ) -> bool {
494
- if let ExprKind :: Index ( left_expr, right_expr, _) = expr. kind {
495
- // Index(Path(_), Path(_), _) returns false
496
- if matches ! ( left_expr. kind, ExprKind :: Path ( _) ) {
497
- return !matches ! ( right_expr. kind, ExprKind :: Path ( _) ) ;
498
- }
499
-
500
- // Nested Index pattern
501
- return is_index_suggestable ( left_expr) && !matches ! ( right_expr. kind, ExprKind :: Path ( _) ) ;
502
- }
503
-
504
- true
505
- }
0 commit comments