@@ -306,6 +306,8 @@ struct Builder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
306
306
cached_resume_block : Option < BasicBlock > ,
307
307
/// cached block with the RETURN terminator
308
308
cached_return_block : Option < BasicBlock > ,
309
+ /// cached block with the UNREACHABLE terminator
310
+ cached_unreachable_block : Option < BasicBlock > ,
309
311
}
310
312
311
313
struct CFG < ' tcx > {
@@ -399,6 +401,11 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
399
401
TerminatorKind :: Goto { target: return_block } ) ;
400
402
builder. cfg. terminate( return_block, source_info,
401
403
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
+ }
402
409
return_block. unit( )
403
410
} ) ) ;
404
411
assert_eq ! ( block, builder. return_block( ) ) ;
@@ -501,7 +508,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
501
508
var_indices : NodeMap ( ) ,
502
509
unit_temp : None ,
503
510
cached_resume_block : None ,
504
- cached_return_block : None
511
+ cached_return_block : None ,
512
+ cached_unreachable_block : None ,
505
513
} ;
506
514
507
515
assert_eq ! ( builder. cfg. start_new_block( ) , START_BLOCK ) ;
@@ -630,6 +638,17 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
630
638
}
631
639
}
632
640
}
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
+ }
633
652
}
634
653
635
654
///////////////////////////////////////////////////////////////////////////
0 commit comments