@@ -408,33 +408,39 @@ impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'tcx> {
408408 }
409409 }
410410
411- #[ tracing:: instrument( level = "trace" , skip( self , data ) , ret) ]
412- fn visit_basic_block_data ( & mut self , block : BasicBlock , data : & mut BasicBlockData < ' tcx > ) {
411+ #[ tracing:: instrument( level = "trace" , skip( self , stmt ) , ret) ]
412+ fn visit_statement ( & mut self , stmt : & mut Statement < ' tcx > , location : Location ) {
413413 // Remove StorageLive and StorageDead statements for remapped locals
414- for s in & mut data. statements {
415- if let StatementKind :: StorageLive ( l) | StatementKind :: StorageDead ( l) = s. kind
416- && self . remap . contains ( l)
417- {
418- s. make_nop ( true ) ;
419- }
414+ if let StatementKind :: StorageLive ( l) | StatementKind :: StorageDead ( l) = stmt. kind
415+ && self . remap . contains ( l)
416+ {
417+ stmt. make_nop ( true ) ;
420418 }
419+ self . super_statement ( stmt, location) ;
420+ }
421421
422- let ret_val = match data. terminator ( ) . kind {
422+ #[ tracing:: instrument( level = "trace" , skip( self , data) , ret) ]
423+ fn visit_basic_block_data ( & mut self , block : BasicBlock , data : & mut BasicBlockData < ' tcx > ) {
424+ match data. terminator ( ) . kind {
423425 TerminatorKind :: Return => {
424- Some ( ( true , None , Operand :: Move ( Place :: from ( self . old_ret_local ) ) , None ) )
425- }
426- TerminatorKind :: Yield { ref value, resume, resume_arg, drop } => {
427- Some ( ( false , Some ( ( resume, resume_arg) ) , value. clone ( ) , drop) )
426+ let source_info = data. terminator ( ) . source_info ;
427+ // We must assign the value first in case it gets declared dead below
428+ self . make_state (
429+ Operand :: Move ( Place :: from ( self . old_ret_local ) ) ,
430+ source_info,
431+ true ,
432+ & mut data. statements ,
433+ ) ;
434+ // Return state.
435+ let state = VariantIdx :: new ( CoroutineArgs :: RETURNED ) ;
436+ data. statements . push ( self . set_discr ( state, source_info) ) ;
437+ data. terminator_mut ( ) . kind = TerminatorKind :: Return ;
428438 }
429- _ => None ,
430- } ;
431-
432- if let Some ( ( is_return, resume, v, drop) ) = ret_val {
433- let source_info = data. terminator ( ) . source_info ;
434- // We must assign the value first in case it gets declared dead below
435- self . make_state ( v, source_info, is_return, & mut data. statements ) ;
436- let state = if let Some ( ( resume, mut resume_arg) ) = resume {
437- // Yield
439+ TerminatorKind :: Yield { ref value, resume, mut resume_arg, drop } => {
440+ let source_info = data. terminator ( ) . source_info ;
441+ // We must assign the value first in case it gets declared dead below
442+ self . make_state ( value. clone ( ) , source_info, false , & mut data. statements ) ;
443+ // Yield state.
438444 let state = CoroutineArgs :: RESERVED_VARIANTS + self . suspension_points . len ( ) ;
439445
440446 // The resume arg target location might itself be remapped if its base local is
@@ -465,13 +471,11 @@ impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'tcx> {
465471 storage_liveness,
466472 } ) ;
467473
468- VariantIdx :: new ( state)
469- } else {
470- // Return
471- VariantIdx :: new ( CoroutineArgs :: RETURNED ) // state for returned
472- } ;
473- data. statements . push ( self . set_discr ( state, source_info) ) ;
474- data. terminator_mut ( ) . kind = TerminatorKind :: Return ;
474+ let state = VariantIdx :: new ( state) ;
475+ data. statements . push ( self . set_discr ( state, source_info) ) ;
476+ data. terminator_mut ( ) . kind = TerminatorKind :: Return ;
477+ }
478+ _ => { }
475479 }
476480
477481 self . super_basic_block_data ( block, data) ;
0 commit comments