@@ -306,6 +306,8 @@ struct Builder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
306306 cached_resume_block : Option < BasicBlock > ,
307307 /// cached block with the RETURN terminator
308308 cached_return_block : Option < BasicBlock > ,
309+ /// cached block with the UNREACHABLE terminator
310+ cached_unreachable_block : Option < BasicBlock > ,
309311}
310312
311313struct CFG < ' tcx > {
@@ -399,6 +401,11 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
399401 TerminatorKind :: Goto { target: return_block } ) ;
400402 builder. cfg. terminate( return_block, source_info,
401403 TerminatorKind :: Return ) ;
404+ // Attribute any unreachable codepaths to the function's closing brace
405+ if let Some ( unreachable_block) = builder. cached_unreachable_block {
406+ builder. cfg. terminate( unreachable_block, source_info,
407+ TerminatorKind :: Unreachable ) ;
408+ }
402409 return_block. unit( )
403410 } ) ) ;
404411 assert_eq ! ( block, builder. return_block( ) ) ;
@@ -501,7 +508,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
501508 var_indices : NodeMap ( ) ,
502509 unit_temp : None ,
503510 cached_resume_block : None ,
504- cached_return_block : None
511+ cached_return_block : None ,
512+ cached_unreachable_block : None ,
505513 } ;
506514
507515 assert_eq ! ( builder. cfg. start_new_block( ) , START_BLOCK ) ;
@@ -630,6 +638,17 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
630638 }
631639 }
632640 }
641+
642+ fn unreachable_block ( & mut self ) -> BasicBlock {
643+ match self . cached_unreachable_block {
644+ Some ( ub) => ub,
645+ None => {
646+ let ub = self . cfg . start_new_block ( ) ;
647+ self . cached_unreachable_block = Some ( ub) ;
648+ ub
649+ }
650+ }
651+ }
633652}
634653
635654///////////////////////////////////////////////////////////////////////////
0 commit comments