@@ -72,6 +72,7 @@ impl<'tcx> LateLintPass<'tcx> for ParIter {
72
72
73
73
let mut top_expr = * recv;
74
74
let mut found_iter_method = false ;
75
+ let mut is_mut = false ;
75
76
76
77
while let Some ( parent_expr) = get_parent_expr ( cx, top_expr) {
77
78
match parent_expr. kind {
@@ -86,6 +87,9 @@ impl<'tcx> LateLintPass<'tcx> for ParIter {
86
87
// Mark that we've found an iteration method
87
88
found_iter_method = true ;
88
89
}
90
+ if method_name. ident . as_str ( ) == "iter_mut" {
91
+ is_mut = true ;
92
+ }
89
93
90
94
if !allowed_methods. contains ( method_name. ident . as_str ( ) ) {
91
95
return ;
@@ -109,7 +113,11 @@ impl<'tcx> LateLintPass<'tcx> for ParIter {
109
113
return ;
110
114
}
111
115
112
- let mut validator = Validator { cx, is_valid : true } ;
116
+ let mut validator = Validator {
117
+ cx,
118
+ is_valid : true ,
119
+ is_mut,
120
+ } ;
113
121
validator. visit_expr ( top_expr) ;
114
122
if !validator. is_valid {
115
123
return ;
@@ -135,6 +143,7 @@ impl<'tcx> LateLintPass<'tcx> for ParIter {
135
143
struct Validator < ' a , ' tcx > {
136
144
cx : & ' a LateContext < ' tcx > ,
137
145
is_valid : bool ,
146
+ is_mut : bool ,
138
147
}
139
148
140
149
impl < ' a , ' tcx > hir:: intravisit:: Visitor < ' _ > for Validator < ' a , ' tcx > {
@@ -148,8 +157,18 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'_> for Validator<'a, 'tcx> {
148
157
149
158
for arg in args {
150
159
if let hir:: ExprKind :: Closure ( closure) = arg. kind {
160
+ let mut mut_params = hir:: HirIdSet :: default ( ) ;
151
161
let body = self . cx . tcx . hir ( ) . body ( closure. body ) ;
152
- self . is_valid &= check_variables ( self . cx , closure. def_id , body) ;
162
+
163
+ if self . is_mut {
164
+ for param in body. params {
165
+ if let hir:: PatKind :: Binding ( _, hir_id, _, _) = param. pat . kind {
166
+ mut_params. insert ( hir_id) ;
167
+ }
168
+ }
169
+ }
170
+
171
+ self . is_valid &= check_variables ( self . cx , closure. def_id , body, & mut_params) ;
153
172
}
154
173
}
155
174
}
0 commit comments