@@ -12,7 +12,7 @@ use rustc_hir::{Block, Expr, ExprKind, HirId, HirIdSet, Local, Mutability, Node,
12
12
use rustc_lint:: LateContext ;
13
13
use rustc_middle:: hir:: map:: Map ;
14
14
use rustc_middle:: ty:: subst:: GenericArgKind ;
15
- use rustc_middle:: ty:: { TyKind , TyS } ;
15
+ use rustc_middle:: ty:: { self , TyS } ;
16
16
use rustc_span:: sym;
17
17
use rustc_span:: { MultiSpan , Span } ;
18
18
@@ -171,27 +171,23 @@ enum IterFunctionKind {
171
171
Contains ( Span ) ,
172
172
}
173
173
174
- struct IterFunctionVisitor < ' b , ' a > {
174
+ struct IterFunctionVisitor < ' a , ' tcx > {
175
175
illegal_mutable_capture_ids : HirIdSet ,
176
176
current_mutably_captured_ids : HirIdSet ,
177
- cx : & ' a LateContext < ' b > ,
177
+ cx : & ' a LateContext < ' tcx > ,
178
178
uses : Vec < Option < IterFunction > > ,
179
179
hir_id_uses_map : FxHashMap < HirId , usize > ,
180
180
current_statement_hir_id : Option < HirId > ,
181
181
seen_other : bool ,
182
182
target : HirId ,
183
183
}
184
184
impl < ' tcx > Visitor < ' tcx > for IterFunctionVisitor < ' _ , ' tcx > {
185
- fn visit_block ( & mut self , block : & ' txc Block < ' tcx > ) {
186
- for ( expr, hir_id) in block
187
- . stmts
188
- . iter ( )
189
- . filter_map ( get_expr_and_hir_id_from_stmt)
190
- . chain ( block. expr . map ( |expr| ( expr, None ) ) )
191
- {
192
- self . current_statement_hir_id = hir_id;
193
- self . current_mutably_captured_ids = get_captured_ids ( self . cx , self . cx . typeck_results ( ) . expr_ty ( expr) ) ;
194
- self . visit_expr ( expr) ;
185
+ fn visit_block ( & mut self , block : & ' tcx Block < ' tcx > ) {
186
+ for ( expr, hir_id) in block. stmts . iter ( ) . filter_map ( get_expr_and_hir_id_from_stmt) {
187
+ self . visit_block_expr ( expr, hir_id) ;
188
+ }
189
+ if let Some ( expr) = block. expr {
190
+ self . visit_block_expr ( expr, None ) ;
195
191
}
196
192
}
197
193
@@ -273,6 +269,14 @@ impl<'tcx> Visitor<'tcx> for IterFunctionVisitor<'_, 'tcx> {
273
269
}
274
270
}
275
271
272
+ impl < ' tcx > IterFunctionVisitor < ' _ , ' tcx > {
273
+ fn visit_block_expr ( & mut self , expr : & ' tcx Expr < ' tcx > , hir_id : Option < HirId > ) {
274
+ self . current_statement_hir_id = hir_id;
275
+ self . current_mutably_captured_ids = get_captured_ids ( self . cx , self . cx . typeck_results ( ) . expr_ty ( expr) ) ;
276
+ self . visit_expr ( expr) ;
277
+ }
278
+ }
279
+
276
280
fn get_expr_and_hir_id_from_stmt < ' v > ( stmt : & ' v Stmt < ' v > ) -> Option < ( & ' v Expr < ' v > , Option < HirId > ) > {
277
281
match stmt. kind {
278
282
StmtKind :: Expr ( expr) | StmtKind :: Semi ( expr) => Some ( ( expr, None ) ) ,
@@ -335,18 +339,17 @@ fn detect_iter_and_into_iters<'tcx: 'a, 'a>(
335
339
}
336
340
}
337
341
338
- #[ allow( rustc:: usage_of_ty_tykind) ]
339
342
fn get_captured_ids ( cx : & LateContext < ' tcx > , ty : & ' _ TyS < ' _ > ) -> HirIdSet {
340
343
fn get_captured_ids_recursive ( cx : & LateContext < ' tcx > , ty : & ' _ TyS < ' _ > , set : & mut HirIdSet ) {
341
344
match ty. kind ( ) {
342
- TyKind :: Adt ( _, generics) => {
345
+ ty :: Adt ( _, generics) => {
343
346
for generic in * generics {
344
347
if let GenericArgKind :: Type ( ty) = generic. unpack ( ) {
345
348
get_captured_ids_recursive ( cx, ty, set) ;
346
349
}
347
350
}
348
351
} ,
349
- TyKind :: Closure ( def_id, _) => {
352
+ ty :: Closure ( def_id, _) => {
350
353
let closure_hir_node = cx. tcx . hir ( ) . get_if_local ( * def_id) . unwrap ( ) ;
351
354
if let Node :: Expr ( closure_expr) = closure_hir_node {
352
355
can_move_expr_to_closure ( cx, closure_expr)
0 commit comments