@@ -12,7 +12,7 @@ use rustc_middle::mir::graphviz_safe_def_name;
1212use rustc_middle:: mir:: { self , BasicBlock , Body , Location } ;
1313
1414use super :: fmt:: { DebugDiffWithAdapter , DebugWithAdapter , DebugWithContext } ;
15- use super :: { Analysis , CallReturnPlaces , Direction , Results , ResultsRefCursor , ResultsVisitor } ;
15+ use super :: { Analysis , CallReturnPlaces , Direction , Results , ResultsCursor , ResultsVisitor } ;
1616
1717#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
1818pub ( crate ) enum OutputStyle {
@@ -29,27 +29,31 @@ impl OutputStyle {
2929 }
3030}
3131
32- pub ( crate ) struct Formatter < ' res , ' mir , ' tcx , A >
32+ pub ( crate ) struct Formatter < ' mir , ' tcx , A >
3333where
3434 A : Analysis < ' tcx > ,
3535{
3636 body : & ' mir Body < ' tcx > ,
37- results : RefCell < & ' res mut Results < ' tcx , A > > ,
37+ results : RefCell < Option < Results < ' tcx , A > > > ,
3838 style : OutputStyle ,
3939 reachable : BitSet < BasicBlock > ,
4040}
4141
42- impl < ' res , ' mir , ' tcx , A > Formatter < ' res , ' mir , ' tcx , A >
42+ impl < ' mir , ' tcx , A > Formatter < ' mir , ' tcx , A >
4343where
4444 A : Analysis < ' tcx > ,
4545{
4646 pub ( crate ) fn new (
4747 body : & ' mir Body < ' tcx > ,
48- results : & ' res mut Results < ' tcx , A > ,
48+ results : Results < ' tcx , A > ,
4949 style : OutputStyle ,
5050 ) -> Self {
5151 let reachable = mir:: traversal:: reachable_as_bitset ( body) ;
52- Formatter { body, results : results. into ( ) , style, reachable }
52+ Formatter { body, results : Some ( results) . into ( ) , style, reachable }
53+ }
54+
55+ pub ( crate ) fn into_results ( self ) -> Results < ' tcx , A > {
56+ self . results . into_inner ( ) . unwrap ( )
5357 }
5458}
5559
@@ -69,7 +73,7 @@ fn dataflow_successors(body: &Body<'_>, bb: BasicBlock) -> Vec<CfgEdge> {
6973 . collect ( )
7074}
7175
72- impl < ' tcx , A > dot:: Labeller < ' _ > for Formatter < ' _ , ' _ , ' tcx , A >
76+ impl < ' tcx , A > dot:: Labeller < ' _ > for Formatter < ' _ , ' tcx , A >
7377where
7478 A : Analysis < ' tcx > ,
7579 A :: Domain : DebugWithContext < A > ,
@@ -88,14 +92,19 @@ where
8892
8993 fn node_label ( & self , block : & Self :: Node ) -> dot:: LabelText < ' _ > {
9094 let mut label = Vec :: new ( ) ;
91- let mut results = self . results . borrow_mut ( ) ;
92- let mut fmt = BlockFormatter {
93- results : results. as_results_cursor ( self . body ) ,
94- style : self . style ,
95- bg : Background :: Light ,
96- } ;
95+ self . results . replace_with ( |results| {
96+ // `Formatter::result` is a `RefCell<Option<_>>` so we can replace
97+ // the value with `None`, move it into the results cursor, move it
98+ // back out, and return it to the refcell wrapped in `Some`.
99+ let mut fmt = BlockFormatter {
100+ results : results. take ( ) . unwrap ( ) . into_results_cursor ( self . body ) ,
101+ style : self . style ,
102+ bg : Background :: Light ,
103+ } ;
97104
98- fmt. write_node_label ( & mut label, * block) . unwrap ( ) ;
105+ fmt. write_node_label ( & mut label, * block) . unwrap ( ) ;
106+ Some ( fmt. results . into_results ( ) )
107+ } ) ;
99108 dot:: LabelText :: html ( String :: from_utf8 ( label) . unwrap ( ) )
100109 }
101110
@@ -109,7 +118,7 @@ where
109118 }
110119}
111120
112- impl < ' mir , ' tcx , A > dot:: GraphWalk < ' mir > for Formatter < ' _ , ' mir , ' tcx , A >
121+ impl < ' mir , ' tcx , A > dot:: GraphWalk < ' mir > for Formatter < ' mir , ' tcx , A >
113122where
114123 A : Analysis < ' tcx > ,
115124{
@@ -143,16 +152,16 @@ where
143152 }
144153}
145154
146- struct BlockFormatter < ' res , ' mir , ' tcx , A >
155+ struct BlockFormatter < ' mir , ' tcx , A >
147156where
148157 A : Analysis < ' tcx > ,
149158{
150- results : ResultsRefCursor < ' res , ' mir , ' tcx , A > ,
159+ results : ResultsCursor < ' mir , ' tcx , A > ,
151160 bg : Background ,
152161 style : OutputStyle ,
153162}
154163
155- impl < ' res , ' mir , ' tcx , A > BlockFormatter < ' res , ' mir , ' tcx , A >
164+ impl < ' mir , ' tcx , A > BlockFormatter < ' mir , ' tcx , A >
156165where
157166 A : Analysis < ' tcx > ,
158167 A :: Domain : DebugWithContext < A > ,
0 commit comments