@@ -51,9 +51,6 @@ pub const START_BLOCK: BasicBlock = BasicBlock(0);
5151/// where execution ends, on normal return
5252pub const END_BLOCK : BasicBlock = BasicBlock ( 1 ) ;
5353
54- /// where execution ends, on panic
55- pub const DIVERGE_BLOCK : BasicBlock = BasicBlock ( 2 ) ;
56-
5754impl < ' tcx > Mir < ' tcx > {
5855 pub fn all_basic_blocks ( & self ) -> Vec < BasicBlock > {
5956 ( 0 ..self . basic_blocks . len ( ) )
@@ -194,7 +191,7 @@ impl Debug for BasicBlock {
194191#[ derive( Debug , RustcEncodable , RustcDecodable ) ]
195192pub struct BasicBlockData < ' tcx > {
196193 pub statements : Vec < Statement < ' tcx > > ,
197- pub terminator : Terminator < ' tcx > ,
194+ pub terminator : Option < Terminator < ' tcx > > ,
198195}
199196
200197#[ derive( RustcEncodable , RustcDecodable ) ]
@@ -237,14 +234,6 @@ pub enum Terminator<'tcx> {
237234 targets : Vec < BasicBlock > ,
238235 } ,
239236
240- /// Indicates that the last statement in the block panics, aborts,
241- /// etc. No successors. This terminator appears on exactly one
242- /// basic block which we create in advance. However, during
243- /// construction, we use this value as a sentinel for "terminator
244- /// not yet assigned", and assert at the end that only the
245- /// well-known diverging block actually diverges.
246- Diverge ,
247-
248237 /// Indicates that the landing pad is finished and unwinding should
249238 /// continue. Emitted by build::scope::diverge_cleanup.
250239 Resume ,
@@ -317,7 +306,6 @@ impl<'tcx> Terminator<'tcx> {
317306 If { targets : ref b, .. } => b. as_slice ( ) ,
318307 Switch { targets : ref b, .. } => b,
319308 SwitchInt { targets : ref b, .. } => b,
320- Diverge => & [ ] ,
321309 Resume => & [ ] ,
322310 Return => & [ ] ,
323311 Call { targets : ref b, .. } => b. as_slice ( ) ,
@@ -336,7 +324,6 @@ impl<'tcx> Terminator<'tcx> {
336324 If { targets : ref mut b, .. } => b. as_mut_slice ( ) ,
337325 Switch { targets : ref mut b, .. } => b,
338326 SwitchInt { targets : ref mut b, .. } => b,
339- Diverge => & mut [ ] ,
340327 Resume => & mut [ ] ,
341328 Return => & mut [ ] ,
342329 Call { targets : ref mut b, .. } => b. as_mut_slice ( ) ,
@@ -350,12 +337,24 @@ impl<'tcx> Terminator<'tcx> {
350337}
351338
352339impl < ' tcx > BasicBlockData < ' tcx > {
353- pub fn new ( terminator : Terminator < ' tcx > ) -> BasicBlockData < ' tcx > {
340+ pub fn new ( terminator : Option < Terminator < ' tcx > > ) -> BasicBlockData < ' tcx > {
354341 BasicBlockData {
355342 statements : vec ! [ ] ,
356343 terminator : terminator,
357344 }
358345 }
346+
347+ /// Accessor for terminator.
348+ ///
349+ /// Terminator may not be None after construction of the basic block is complete. This accessor
350+ /// provides a convenience way to reach the terminator.
351+ pub fn terminator ( & self ) -> & Terminator < ' tcx > {
352+ self . terminator . as_ref ( ) . expect ( "invalid terminator state" )
353+ }
354+
355+ pub fn terminator_mut ( & mut self ) -> & mut Terminator < ' tcx > {
356+ self . terminator . as_mut ( ) . expect ( "invalid terminator state" )
357+ }
359358}
360359
361360impl < ' tcx > Debug for Terminator < ' tcx > {
@@ -396,7 +395,6 @@ impl<'tcx> Terminator<'tcx> {
396395 If { cond : ref lv, .. } => write ! ( fmt, "if({:?})" , lv) ,
397396 Switch { discr : ref lv, .. } => write ! ( fmt, "switch({:?})" , lv) ,
398397 SwitchInt { discr : ref lv, .. } => write ! ( fmt, "switchInt({:?})" , lv) ,
399- Diverge => write ! ( fmt, "diverge" ) ,
400398 Return => write ! ( fmt, "return" ) ,
401399 Resume => write ! ( fmt, "resume" ) ,
402400 Call { .. } => {
@@ -414,7 +412,7 @@ impl<'tcx> Terminator<'tcx> {
414412 pub fn fmt_successor_labels ( & self ) -> Vec < Cow < ' static , str > > {
415413 use self :: Terminator :: * ;
416414 match * self {
417- Diverge | Return | Resume => vec ! [ ] ,
415+ Return | Resume => vec ! [ ] ,
418416 Goto { .. } => vec ! [ "" . into_cow( ) ] ,
419417 If { .. } => vec ! [ "true" . into_cow( ) , "false" . into_cow( ) ] ,
420418 Call { .. } => vec ! [ "return" . into_cow( ) , "unwind" . into_cow( ) ] ,
0 commit comments