@@ -387,18 +387,6 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> {
387
387
ty. needs_drop ( self . fcx . tcx , self . fcx . param_env )
388
388
} ;
389
389
390
- let find_parent_expr = |mut hir_id| {
391
- let hir = self . fcx . tcx . hir ( ) ;
392
- hir_id = hir. find_parent_node ( hir_id) ?;
393
- loop {
394
- if let hir:: Node :: Expr ( _) = self . fcx . tcx . hir ( ) . find ( hir_id) ? {
395
- return Some ( hir_id) ;
396
- } else {
397
- hir_id = hir. find_parent_node ( hir_id) ?;
398
- }
399
- }
400
- } ;
401
-
402
390
// Typically, the value produced by an expression is consumed by its parent in some way,
403
391
// so we only have to check if the parent contains a yield (note that the parent may, for
404
392
// example, store the value into a local variable, but then we already consider local
@@ -421,7 +409,13 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> {
421
409
} ) {
422
410
self . rvalue_scopes . temporary_scope ( self . region_scope_tree , expr. hir_id . local_id )
423
411
} else {
424
- let parent_expr = find_parent_expr ( expr. hir_id ) ;
412
+ let parent_expr = self
413
+ . fcx
414
+ . tcx
415
+ . hir ( )
416
+ . parent_iter ( expr. hir_id )
417
+ . find ( |( _, node) | matches ! ( node, hir:: Node :: Expr ( _) ) )
418
+ . map ( |( id, _) | id) ;
425
419
debug ! ( "parent_expr: {:?}" , parent_expr) ;
426
420
match parent_expr {
427
421
Some ( parent) => Some ( Scope { id : parent. local_id , data : ScopeData :: Node } ) ,
0 commit comments