@@ -12,7 +12,7 @@ use rustc_middle::mir::graphviz_safe_def_name;
12
12
use rustc_middle:: mir:: { self , BasicBlock , Body , Location } ;
13
13
14
14
use super :: fmt:: { DebugDiffWithAdapter , DebugWithAdapter , DebugWithContext } ;
15
- use super :: { Analysis , CallReturnPlaces , Direction , Results , ResultsRefCursor , ResultsVisitor } ;
15
+ use super :: { Analysis , CallReturnPlaces , Direction , Results , ResultsCursor , ResultsVisitor } ;
16
16
17
17
#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
18
18
pub ( crate ) enum OutputStyle {
@@ -29,27 +29,31 @@ impl OutputStyle {
29
29
}
30
30
}
31
31
32
- pub ( crate ) struct Formatter < ' res , ' mir , ' tcx , A >
32
+ pub ( crate ) struct Formatter < ' mir , ' tcx , A >
33
33
where
34
34
A : Analysis < ' tcx > ,
35
35
{
36
36
body : & ' mir Body < ' tcx > ,
37
- results : RefCell < & ' res mut Results < ' tcx , A > > ,
37
+ results : RefCell < Option < Results < ' tcx , A > > > ,
38
38
style : OutputStyle ,
39
39
reachable : BitSet < BasicBlock > ,
40
40
}
41
41
42
- impl < ' res , ' mir , ' tcx , A > Formatter < ' res , ' mir , ' tcx , A >
42
+ impl < ' mir , ' tcx , A > Formatter < ' mir , ' tcx , A >
43
43
where
44
44
A : Analysis < ' tcx > ,
45
45
{
46
46
pub ( crate ) fn new (
47
47
body : & ' mir Body < ' tcx > ,
48
- results : & ' res mut Results < ' tcx , A > ,
48
+ results : Results < ' tcx , A > ,
49
49
style : OutputStyle ,
50
50
) -> Self {
51
51
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 ( )
53
57
}
54
58
}
55
59
@@ -69,7 +73,7 @@ fn dataflow_successors(body: &Body<'_>, bb: BasicBlock) -> Vec<CfgEdge> {
69
73
. collect ( )
70
74
}
71
75
72
- impl < ' tcx , A > dot:: Labeller < ' _ > for Formatter < ' _ , ' _ , ' tcx , A >
76
+ impl < ' tcx , A > dot:: Labeller < ' _ > for Formatter < ' _ , ' tcx , A >
73
77
where
74
78
A : Analysis < ' tcx > ,
75
79
A :: Domain : DebugWithContext < A > ,
@@ -88,14 +92,19 @@ where
88
92
89
93
fn node_label ( & self , block : & Self :: Node ) -> dot:: LabelText < ' _ > {
90
94
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
+ } ;
97
104
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
+ } ) ;
99
108
dot:: LabelText :: html ( String :: from_utf8 ( label) . unwrap ( ) )
100
109
}
101
110
@@ -109,7 +118,7 @@ where
109
118
}
110
119
}
111
120
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 >
113
122
where
114
123
A : Analysis < ' tcx > ,
115
124
{
@@ -143,16 +152,16 @@ where
143
152
}
144
153
}
145
154
146
- struct BlockFormatter < ' res , ' mir , ' tcx , A >
155
+ struct BlockFormatter < ' mir , ' tcx , A >
147
156
where
148
157
A : Analysis < ' tcx > ,
149
158
{
150
- results : ResultsRefCursor < ' res , ' mir , ' tcx , A > ,
159
+ results : ResultsCursor < ' mir , ' tcx , A > ,
151
160
bg : Background ,
152
161
style : OutputStyle ,
153
162
}
154
163
155
- impl < ' res , ' mir , ' tcx , A > BlockFormatter < ' res , ' mir , ' tcx , A >
164
+ impl < ' mir , ' tcx , A > BlockFormatter < ' mir , ' tcx , A >
156
165
where
157
166
A : Analysis < ' tcx > ,
158
167
A :: Domain : DebugWithContext < A > ,
0 commit comments