@@ -2154,9 +2154,10 @@ fn check_infinite_loop<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, cond: &'tcx Expr, b
2154
2154
let mut mut_var_visitor = VarCollectorVisitor {
2155
2155
cx,
2156
2156
ids : HashMap :: new ( ) ,
2157
+ def_ids : HashMap :: new ( ) ,
2157
2158
skip : false ,
2158
2159
} ;
2159
- walk_expr ( & mut mut_var_visitor, expr ) ;
2160
+ mut_var_visitor. visit_expr ( cond ) ;
2160
2161
if mut_var_visitor. skip {
2161
2162
return ;
2162
2163
}
@@ -2172,7 +2173,7 @@ fn check_infinite_loop<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, cond: &'tcx Expr, b
2172
2173
if delegate. skip {
2173
2174
return ;
2174
2175
}
2175
- if !delegate. used_mutably . iter ( ) . any ( |( _, v) | * v) {
2176
+ if !( delegate. used_mutably . iter ( ) . any ( |( _, v) | * v) || mut_var_visitor . def_ids . iter ( ) . any ( | ( _ , v ) | * v ) ) {
2176
2177
span_lint (
2177
2178
cx,
2178
2179
WHILE_IMMUTABLE_CONDITION ,
@@ -2189,6 +2190,7 @@ fn check_infinite_loop<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, cond: &'tcx Expr, b
2189
2190
struct VarCollectorVisitor < ' a , ' tcx : ' a > {
2190
2191
cx : & ' a LateContext < ' a , ' tcx > ,
2191
2192
ids : HashMap < NodeId , bool > ,
2193
+ def_ids : HashMap < def_id:: DefId , bool > ,
2192
2194
skip : bool ,
2193
2195
}
2194
2196
@@ -2203,6 +2205,9 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> {
2203
2205
Def :: Local ( node_id) | Def :: Upvar ( node_id, ..) => {
2204
2206
self . ids. insert( node_id, false ) ;
2205
2207
} ,
2208
+ Def :: Static ( def_id, mutable) => {
2209
+ self . def_ids. insert( def_id, mutable) ;
2210
+ } ,
2206
2211
_ => { } ,
2207
2212
}
2208
2213
}
@@ -2221,8 +2226,6 @@ impl<'a, 'tcx> Visitor<'tcx> for VarCollectorVisitor<'a, 'tcx> {
2221
2226
}
2222
2227
}
2223
2228
2224
- fn visit_block ( & mut self , _b : & ' tcx Block ) { }
2225
-
2226
2229
fn nested_visit_map < ' this > ( & ' this mut self ) -> NestedVisitorMap < ' this , ' tcx > {
2227
2230
NestedVisitorMap :: None
2228
2231
}
0 commit comments