@@ -113,10 +113,7 @@ use visitors::Visitable;
113
113
114
114
use crate :: consts:: { constant, mir_to_const, Constant } ;
115
115
use crate :: higher:: Range ;
116
- use crate :: ty:: {
117
- adt_and_variant_of_res, can_partially_move_ty, expr_sig, is_copy, is_recursively_primitive_type,
118
- ty_is_fn_once_param,
119
- } ;
116
+ use crate :: ty:: { adt_and_variant_of_res, can_partially_move_ty, expr_sig, is_copy, is_recursively_primitive_type} ;
120
117
use crate :: visitors:: for_each_expr;
121
118
122
119
use rustc_middle:: hir:: nested_filter;
@@ -1345,46 +1342,12 @@ pub fn get_enclosing_loop_or_multi_call_closure<'tcx>(
1345
1342
for ( _, node) in cx. tcx . hir ( ) . parent_iter ( expr. hir_id ) {
1346
1343
match node {
1347
1344
Node :: Expr ( e) => match e. kind {
1348
- ExprKind :: Closure { .. } => {
1345
+ ExprKind :: Closure { .. }
1349
1346
if let rustc_ty:: Closure ( _, subs) = cx. typeck_results ( ) . expr_ty ( e) . kind ( )
1350
- && subs. as_closure ( ) . kind ( ) == ClosureKind :: FnOnce
1351
- {
1352
- continue ;
1353
- }
1354
- let is_once = walk_to_expr_usage ( cx, e, |node, id| {
1355
- let Node :: Expr ( e) = node else {
1356
- return None ;
1357
- } ;
1358
- match e. kind {
1359
- ExprKind :: Call ( f, _) if f. hir_id == id => Some ( ( ) ) ,
1360
- ExprKind :: Call ( f, args) => {
1361
- let i = args. iter ( ) . position ( |arg| arg. hir_id == id) ?;
1362
- let sig = expr_sig ( cx, f) ?;
1363
- let predicates = sig
1364
- . predicates_id ( )
1365
- . map_or ( cx. param_env , |id| cx. tcx . param_env ( id) )
1366
- . caller_bounds ( ) ;
1367
- sig. input ( i) . and_then ( |ty| {
1368
- ty_is_fn_once_param ( cx. tcx , ty. skip_binder ( ) , predicates) . then_some ( ( ) )
1369
- } )
1370
- } ,
1371
- ExprKind :: MethodCall ( _, receiver, args, _) => {
1372
- let i = std:: iter:: once ( receiver)
1373
- . chain ( args. iter ( ) )
1374
- . position ( |arg| arg. hir_id == id) ?;
1375
- let id = cx. typeck_results ( ) . type_dependent_def_id ( e. hir_id ) ?;
1376
- let ty = cx. tcx . fn_sig ( id) . instantiate_identity ( ) . skip_binder ( ) . inputs ( ) [ i] ;
1377
- ty_is_fn_once_param ( cx. tcx , ty, cx. tcx . param_env ( id) . caller_bounds ( ) ) . then_some ( ( ) )
1378
- } ,
1379
- _ => None ,
1380
- }
1381
- } )
1382
- . is_some ( ) ;
1383
- if !is_once {
1384
- return Some ( e) ;
1385
- }
1386
- } ,
1387
- ExprKind :: Loop ( ..) => return Some ( e) ,
1347
+ && subs. as_closure ( ) . kind ( ) == ClosureKind :: FnOnce => { } ,
1348
+
1349
+ // Note: A closure's kind is determined by how it's used, not it's captures.
1350
+ ExprKind :: Closure { .. } | ExprKind :: Loop ( ..) => return Some ( e) ,
1388
1351
_ => ( ) ,
1389
1352
} ,
1390
1353
Node :: Stmt ( _) | Node :: Block ( _) | Node :: Local ( _) | Node :: Arm ( _) => ( ) ,
0 commit comments