@@ -4,11 +4,11 @@ use clippy_utils::higher::ForLoop;
4
4
use clippy_utils:: source:: SpanRangeExt ;
5
5
use clippy_utils:: ty:: { get_iterator_item_ty, implements_trait} ;
6
6
use clippy_utils:: visitors:: for_each_expr_without_closures;
7
- use clippy_utils:: { can_mut_borrow_both, fn_def_id, get_parent_expr, path_to_local } ;
7
+ use clippy_utils:: { can_mut_borrow_both, fn_def_id, get_parent_expr, is_path_mutable } ;
8
8
use core:: ops:: ControlFlow ;
9
9
use rustc_errors:: Applicability ;
10
10
use rustc_hir:: def_id:: DefId ;
11
- use rustc_hir:: { BindingMode , Expr , ExprKind , Node , PatKind } ;
11
+ use rustc_hir:: { Expr , ExprKind } ;
12
12
use rustc_lint:: LateContext ;
13
13
use rustc_span:: { Symbol , sym} ;
14
14
@@ -42,22 +42,7 @@ pub fn check_for_loop_iter(
42
42
&& !clone_or_copy_needed
43
43
&& let Some ( receiver_snippet) = receiver. span . get_source_text ( cx)
44
44
{
45
- // Issue 12098
46
- // https://github.com/rust-lang/rust-clippy/issues/12098
47
- // if the assignee have `mut borrow` conflict with the iteratee
48
- // the lint should not execute, former didn't consider the mut case
49
-
50
45
// check whether `expr` is mutable
51
- fn is_mutable ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> bool {
52
- if let Some ( hir_id) = path_to_local ( expr)
53
- && let Node :: Pat ( pat) = cx. tcx . hir_node ( hir_id)
54
- {
55
- matches ! ( pat. kind, PatKind :: Binding ( BindingMode :: MUT , ..) )
56
- } else {
57
- true
58
- }
59
- }
60
-
61
46
fn is_caller_or_fields_change ( cx : & LateContext < ' _ > , body : & Expr < ' _ > , caller : & Expr < ' _ > ) -> bool {
62
47
let mut change = false ;
63
48
if let ExprKind :: Block ( block, ..) = body. kind {
@@ -82,7 +67,12 @@ pub fn check_for_loop_iter(
82
67
while let ExprKind :: MethodCall ( _, caller, _, _) = child. kind {
83
68
child = caller;
84
69
}
85
- if is_mutable ( cx, child) && is_caller_or_fields_change ( cx, body, child) {
70
+
71
+ // Issue 12098
72
+ // https://github.com/rust-lang/rust-clippy/issues/12098
73
+ // if the assignee have `mut borrow` conflict with the iteratee
74
+ // the lint should not execute, former didn't consider the mut case
75
+ if is_path_mutable ( cx, child) . unwrap_or ( true ) && is_caller_or_fields_change ( cx, body, child) {
86
76
// skip lint
87
77
return true ;
88
78
}
0 commit comments