@@ -554,7 +554,8 @@ impl<'tcx> Inliner<'tcx> {
554554 new_scopes : SourceScope :: new ( caller_body. source_scopes . len ( ) ) ..,
555555 new_blocks : BasicBlock :: new ( caller_body. basic_blocks ( ) . len ( ) ) ..,
556556 destination : dest,
557- return_block : callsite. target ,
557+ callsite_scope : caller_body. source_scopes [ callsite. source_info . scope ] . clone ( ) ,
558+ callsite,
558559 cleanup_block : cleanup,
559560 in_cleanup_block : false ,
560561 tcx : self . tcx ,
@@ -566,31 +567,6 @@ impl<'tcx> Inliner<'tcx> {
566567 // (or existing ones, in a few special cases) in the caller.
567568 integrator. visit_body ( & mut callee_body) ;
568569
569- for scope in & mut callee_body. source_scopes {
570- // FIXME(eddyb) move this into a `fn visit_scope_data` in `Integrator`.
571- if scope. parent_scope . is_none ( ) {
572- let callsite_scope = & caller_body. source_scopes [ callsite. source_info . scope ] ;
573-
574- // Attach the outermost callee scope as a child of the callsite
575- // scope, via the `parent_scope` and `inlined_parent_scope` chains.
576- scope. parent_scope = Some ( callsite. source_info . scope ) ;
577- assert_eq ! ( scope. inlined_parent_scope, None ) ;
578- scope. inlined_parent_scope = if callsite_scope. inlined . is_some ( ) {
579- Some ( callsite. source_info . scope )
580- } else {
581- callsite_scope. inlined_parent_scope
582- } ;
583-
584- // Mark the outermost callee scope as an inlined one.
585- assert_eq ! ( scope. inlined, None ) ;
586- scope. inlined = Some ( ( callsite. callee , callsite. source_info . span ) ) ;
587- } else if scope. inlined_parent_scope . is_none ( ) {
588- // Make it easy to find the scope with `inlined` set above.
589- scope. inlined_parent_scope =
590- Some ( integrator. map_scope ( OUTERMOST_SOURCE_SCOPE ) ) ;
591- }
592- }
593-
594570 // If there are any locals without storage markers, give them storage only for the
595571 // duration of the call.
596572 for local in callee_body. vars_and_temps_iter ( ) {
@@ -786,7 +762,8 @@ struct Integrator<'a, 'tcx> {
786762 new_scopes : RangeFrom < SourceScope > ,
787763 new_blocks : RangeFrom < BasicBlock > ,
788764 destination : Place < ' tcx > ,
789- return_block : Option < BasicBlock > ,
765+ callsite_scope : SourceScopeData < ' tcx > ,
766+ callsite : & ' a CallSite < ' tcx > ,
790767 cleanup_block : Option < BasicBlock > ,
791768 in_cleanup_block : bool ,
792769 tcx : TyCtxt < ' tcx > ,
@@ -832,6 +809,28 @@ impl<'tcx> MutVisitor<'tcx> for Integrator<'_, 'tcx> {
832809 * local = self . map_local ( * local) ;
833810 }
834811
812+ fn visit_source_scope_data ( & mut self , scope_data : & mut SourceScopeData < ' tcx > ) {
813+ self . super_source_scope_data ( scope_data) ;
814+ if scope_data. parent_scope . is_none ( ) {
815+ // Attach the outermost callee scope as a child of the callsite
816+ // scope, via the `parent_scope` and `inlined_parent_scope` chains.
817+ scope_data. parent_scope = Some ( self . callsite . source_info . scope ) ;
818+ assert_eq ! ( scope_data. inlined_parent_scope, None ) ;
819+ scope_data. inlined_parent_scope = if self . callsite_scope . inlined . is_some ( ) {
820+ Some ( self . callsite . source_info . scope )
821+ } else {
822+ self . callsite_scope . inlined_parent_scope
823+ } ;
824+
825+ // Mark the outermost callee scope as an inlined one.
826+ assert_eq ! ( scope_data. inlined, None ) ;
827+ scope_data. inlined = Some ( ( self . callsite . callee , self . callsite . source_info . span ) ) ;
828+ } else if scope_data. inlined_parent_scope . is_none ( ) {
829+ // Make it easy to find the scope with `inlined` set above.
830+ scope_data. inlined_parent_scope = Some ( self . map_scope ( OUTERMOST_SOURCE_SCOPE ) ) ;
831+ }
832+ }
833+
835834 fn visit_source_scope ( & mut self , scope : & mut SourceScope ) {
836835 * scope = self . map_scope ( * scope) ;
837836 }
@@ -938,7 +937,7 @@ impl<'tcx> MutVisitor<'tcx> for Integrator<'_, 'tcx> {
938937 }
939938 }
940939 TerminatorKind :: Return => {
941- terminator. kind = if let Some ( tgt) = self . return_block {
940+ terminator. kind = if let Some ( tgt) = self . callsite . target {
942941 TerminatorKind :: Goto { target : tgt }
943942 } else {
944943 TerminatorKind :: Unreachable
0 commit comments