@@ -387,18 +387,6 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> {
387387 ty. needs_drop ( self . fcx . tcx , self . fcx . param_env )
388388 } ;
389389
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-
402390 // Typically, the value produced by an expression is consumed by its parent in some way,
403391 // so we only have to check if the parent contains a yield (note that the parent may, for
404392 // 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> {
421409 } ) {
422410 self . rvalue_scopes . temporary_scope ( self . region_scope_tree , expr. hir_id . local_id )
423411 } 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) ;
425419 debug ! ( "parent_expr: {:?}" , parent_expr) ;
426420 match parent_expr {
427421 Some ( parent) => Some ( Scope { id : parent. local_id , data : ScopeData :: Node } ) ,
0 commit comments