@@ -345,11 +345,6 @@ struct Builder<'a, 'tcx> {
345345
346346 var_debug_info : Vec < VarDebugInfo < ' tcx > > ,
347347
348- /// Cached block with the `RESUME` terminator; this is created
349- /// when first set of cleanups are built.
350- cached_resume_block : Option < BasicBlock > ,
351- /// Cached block with the `RETURN` terminator.
352- cached_return_block : Option < BasicBlock > ,
353348 /// Cached block with the `UNREACHABLE` terminator.
354349 cached_unreachable_block : Option < BasicBlock > ,
355350}
@@ -609,50 +604,34 @@ where
609604 region:: Scope { id : body. value . hir_id . local_id , data : region:: ScopeData :: CallSite } ;
610605 let arg_scope =
611606 region:: Scope { id : body. value . hir_id . local_id , data : region:: ScopeData :: Arguments } ;
612- let mut block = START_BLOCK ;
613607 let source_info = builder. source_info ( span) ;
614608 let call_site_s = ( call_site_scope, source_info) ;
615- unpack ! (
616- block = builder. in_scope( call_site_s, LintLevel :: Inherited , |builder| {
617- if should_abort_on_panic( tcx, fn_def_id, abi) {
618- builder. schedule_abort( ) ;
619- }
620-
621- let arg_scope_s = ( arg_scope, source_info) ;
622- // `return_block` is called when we evaluate a `return` expression, so
623- // we just use `START_BLOCK` here.
624- unpack!(
625- block = builder. in_breakable_scope(
626- None ,
627- START_BLOCK ,
628- Place :: return_place( ) ,
629- |builder| {
630- builder. in_scope( arg_scope_s, LintLevel :: Inherited , |builder| {
631- builder. args_and_body(
632- block,
633- fn_def_id. to_def_id( ) ,
634- & arguments,
635- arg_scope,
636- & body. value,
637- )
638- } )
639- } ,
640- )
641- ) ;
642- // Attribute epilogue to function's closing brace
643- let fn_end = span_with_body. shrink_to_hi( ) ;
644- let source_info = builder. source_info( fn_end) ;
645- let return_block = builder. return_block( ) ;
646- builder. cfg. goto( block, source_info, return_block) ;
647- builder. cfg. terminate( return_block, source_info, TerminatorKind :: Return ) ;
648- // Attribute any unreachable codepaths to the function's closing brace
649- if let Some ( unreachable_block) = builder. cached_unreachable_block {
650- builder. cfg. terminate( unreachable_block, source_info, TerminatorKind :: Unreachable ) ;
651- }
652- return_block. unit( )
653- } )
654- ) ;
655- assert_eq ! ( block, builder. return_block( ) ) ;
609+ unpack ! ( builder. in_scope( call_site_s, LintLevel :: Inherited , |builder| {
610+ let arg_scope_s = ( arg_scope, source_info) ;
611+ // Attribute epilogue to function's closing brace
612+ let fn_end = span_with_body. shrink_to_hi( ) ;
613+ let return_block =
614+ unpack!( builder. in_breakable_scope( None , Place :: return_place( ) , fn_end, |builder| {
615+ Some ( builder. in_scope( arg_scope_s, LintLevel :: Inherited , |builder| {
616+ builder. args_and_body(
617+ START_BLOCK ,
618+ fn_def_id. to_def_id( ) ,
619+ & arguments,
620+ arg_scope,
621+ & body. value,
622+ )
623+ } ) )
624+ } ) ) ;
625+ let source_info = builder. source_info( fn_end) ;
626+ builder. cfg. terminate( return_block, source_info, TerminatorKind :: Return ) ;
627+ let should_abort = should_abort_on_panic( tcx, fn_def_id, abi) ;
628+ builder. build_drop_trees( should_abort) ;
629+ // Attribute any unreachable codepaths to the function's closing brace
630+ if let Some ( unreachable_block) = builder. cached_unreachable_block {
631+ builder. cfg. terminate( unreachable_block, source_info, TerminatorKind :: Unreachable ) ;
632+ }
633+ return_block. unit( )
634+ } ) ) ;
656635
657636 let spread_arg = if abi == Abi :: RustCall {
658637 // RustCall pseudo-ABI untuples the last argument.
@@ -686,8 +665,7 @@ fn construct_const<'a, 'tcx>(
686665 let source_info = builder. source_info ( span) ;
687666 builder. cfg . terminate ( block, source_info, TerminatorKind :: Return ) ;
688667
689- // Constants can't `return` so a return block should not be created.
690- assert_eq ! ( builder. cached_return_block, None ) ;
668+ builder. build_drop_trees ( false ) ;
691669
692670 // Constants may be match expressions in which case an unreachable block may
693671 // be created, so terminate it properly.
@@ -754,7 +732,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
754732 fn_span : span,
755733 arg_count,
756734 generator_kind,
757- scopes : Default :: default ( ) ,
735+ scopes : scope :: Scopes :: new ( ) ,
758736 block_context : BlockContext :: new ( ) ,
759737 source_scopes : IndexVec :: new ( ) ,
760738 source_scope : OUTERMOST_SOURCE_SCOPE ,
@@ -767,8 +745,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
767745 var_indices : Default :: default ( ) ,
768746 unit_temp : None ,
769747 var_debug_info : vec ! [ ] ,
770- cached_resume_block : None ,
771- cached_return_block : None ,
772748 cached_unreachable_block : None ,
773749 } ;
774750
@@ -1003,17 +979,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1003979 }
1004980 }
1005981 }
1006-
1007- fn return_block ( & mut self ) -> BasicBlock {
1008- match self . cached_return_block {
1009- Some ( rb) => rb,
1010- None => {
1011- let rb = self . cfg . start_new_block ( ) ;
1012- self . cached_return_block = Some ( rb) ;
1013- rb
1014- }
1015- }
1016- }
1017982}
1018983
1019984///////////////////////////////////////////////////////////////////////////
0 commit comments