@@ -6,6 +6,7 @@ use std::{io, ops, str};
66
77use regex:: Regex ;
88use rustc_graphviz as dot;
9+ use rustc_index:: bit_set:: BitSet ;
910use rustc_middle:: mir:: graphviz_safe_def_name;
1011use rustc_middle:: mir:: { self , BasicBlock , Body , Location } ;
1112
@@ -34,14 +35,16 @@ where
3435 body : & ' a Body < ' tcx > ,
3536 results : & ' a Results < ' tcx , A > ,
3637 style : OutputStyle ,
38+ reachable : BitSet < BasicBlock > ,
3739}
3840
3941impl < ' a , ' tcx , A > Formatter < ' a , ' tcx , A >
4042where
4143 A : Analysis < ' tcx > ,
4244{
4345 pub fn new ( body : & ' a Body < ' tcx > , results : & ' a Results < ' tcx , A > , style : OutputStyle ) -> Self {
44- Formatter { body, results, style }
46+ let reachable = mir:: traversal:: reachable_as_bitset ( body) ;
47+ Formatter { body, results, style, reachable }
4548 }
4649}
4750
@@ -108,7 +111,12 @@ where
108111 type Edge = CfgEdge ;
109112
110113 fn nodes ( & self ) -> dot:: Nodes < ' _ , Self :: Node > {
111- self . body . basic_blocks . indices ( ) . collect :: < Vec < _ > > ( ) . into ( )
114+ self . body
115+ . basic_blocks
116+ . indices ( )
117+ . filter ( |& idx| self . reachable . contains ( idx) )
118+ . collect :: < Vec < _ > > ( )
119+ . into ( )
112120 }
113121
114122 fn edges ( & self ) -> dot:: Edges < ' _ , Self :: Edge > {
0 commit comments