@@ -113,10 +113,7 @@ use visitors::Visitable;
113113
114114use crate :: consts:: { constant, mir_to_const, Constant } ;
115115use 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} ;
120117use crate :: visitors:: for_each_expr;
121118
122119use rustc_middle:: hir:: nested_filter;
@@ -1345,46 +1342,12 @@ pub fn get_enclosing_loop_or_multi_call_closure<'tcx>(
13451342 for ( _, node) in cx. tcx . hir ( ) . parent_iter ( expr. hir_id ) {
13461343 match node {
13471344 Node :: Expr ( e) => match e. kind {
1348- ExprKind :: Closure { .. } => {
1345+ ExprKind :: Closure { .. }
13491346 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) ,
13881351 _ => ( ) ,
13891352 } ,
13901353 Node :: Stmt ( _) | Node :: Block ( _) | Node :: Local ( _) | Node :: Arm ( _) => ( ) ,
0 commit comments