57
57
}
58
58
59
59
// Graph label
60
- let label = get_graph_label ( tcx, body) ;
60
+ let mut label = String :: from ( "" ) ;
61
+ // FIXME: remove this unwrap
62
+ write_graph_label ( tcx, body, & mut label) . unwrap ( ) ;
61
63
let g = mir_fn_to_generic_graph ( tcx, body, subgraph) ;
62
64
let settings = GraphvizSettings {
63
65
graph_attrs : Some ( graph_attrs. join ( " " ) ) ,
@@ -71,42 +73,47 @@ where
71
73
/// Write the graphviz DOT label for the overall graph. This is essentially a block of text that
72
74
/// will appear below the graph, showing the type of the `fn` this MIR represents and the types of
73
75
/// all the variables and temporaries.
74
- fn get_graph_label < ' tcx > ( tcx : TyCtxt < ' tcx > , body : & Body < ' _ > ) -> String {
76
+ fn write_graph_label < ' tcx , W : std:: fmt:: Write > (
77
+ tcx : TyCtxt < ' tcx > ,
78
+ body : & Body < ' _ > ,
79
+ w : & mut W ,
80
+ ) -> std:: fmt:: Result {
75
81
let def_id = body. source . def_id ( ) ;
76
- let mut label: Vec < String > = Vec :: new ( ) ;
77
82
78
- label . push ( format ! ( "fn {}(" , dot:: escape_html( & tcx. def_path_str( def_id) ) ) ) ;
83
+ write ! ( w , "fn {}(" , dot:: escape_html( & tcx. def_path_str( def_id) ) ) ? ;
79
84
80
85
// fn argument types.
81
86
for ( i, arg) in body. args_iter ( ) . enumerate ( ) {
82
87
if i > 0 {
83
- label . push ( ", " . to_owned ( ) ) ;
88
+ write ! ( w , ", " ) ? ;
84
89
}
85
- label . push ( format ! ( "{:?}: {}" , Place :: from( arg) , escape( & body. local_decls[ arg] . ty) ) ) ;
90
+ write ! ( w , "{:?}: {}" , Place :: from( arg) , escape( & body. local_decls[ arg] . ty) ) ? ;
86
91
}
87
92
88
- label . push ( format ! ( ") -> {}" , escape( & body. return_ty( ) ) ) ) ;
89
- label . push ( r#"<br align="left"/>"# . to_owned ( ) ) ;
93
+ write ! ( w , ") -> {}" , escape( & body. return_ty( ) ) ) ? ;
94
+ write ! ( w , r#"<br align="left"/>"# ) ? ;
90
95
91
96
for local in body. vars_and_temps_iter ( ) {
92
97
let decl = & body. local_decls [ local] ;
93
98
94
- label . push ( "let " . to_owned ( ) ) ;
99
+ write ! ( w , "let " ) ? ;
95
100
if decl. mutability == Mutability :: Mut {
96
- label . push ( "mut " . to_owned ( ) ) ;
101
+ write ! ( w , "mut " ) ? ;
97
102
}
98
103
99
- label . push ( format ! ( r#"{:?}: {};<br align="left"/>"# , Place :: from( local) , escape( & decl. ty) ) ) ;
104
+ write ! ( w , r#"{:?}: {};<br align="left"/>"# , Place :: from( local) , escape( & decl. ty) ) ? ;
100
105
}
101
106
102
107
for var_debug_info in & body. var_debug_info {
103
- label. push ( format ! (
108
+ write ! (
109
+ w,
104
110
r#"debug {} => {};<br align="left"/>"# ,
105
111
var_debug_info. name,
106
112
escape( & var_debug_info. place)
107
- ) ) ;
113
+ ) ? ;
108
114
}
109
- label. join ( "" )
115
+
116
+ Ok ( ( ) )
110
117
}
111
118
112
119
fn escape < T : Debug > ( t : & T ) -> String {
0 commit comments