]> git.lizzy.rs Git - rust.git/blob - src/librustc_driver/pretty.rs
Merge pull request #20510 from tshepang/patch-6
[rust.git] / src / librustc_driver / pretty.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! The various pretty print routines.
12
13 pub use self::UserIdentifiedItem::*;
14 pub use self::PpSourceMode::*;
15 pub use self::PpMode::*;
16 use self::NodesMatchingUII::*;
17
18 use rustc_trans::back::link;
19
20 use driver;
21
22 use rustc::middle::ty;
23 use rustc::middle::cfg;
24 use rustc::middle::cfg::graphviz::LabelledCFG;
25 use rustc::session::Session;
26 use rustc::session::config::{self, Input};
27 use rustc::util::ppaux;
28 use rustc_borrowck as borrowck;
29 use rustc_borrowck::graphviz as borrowck_dot;
30
31 use syntax::ast;
32 use syntax::ast_map::{self, blocks, NodePrinter};
33 use syntax::codemap;
34 use syntax::fold::{self, Folder};
35 use syntax::print::{pp, pprust};
36 use syntax::ptr::P;
37
38 use graphviz as dot;
39
40 use std::io::{self, MemReader};
41 use std::option;
42 use std::str::FromStr;
43
44 #[derive(Copy, PartialEq, Show)]
45 pub enum PpSourceMode {
46     PpmNormal,
47     PpmEveryBodyLoops,
48     PpmExpanded,
49     PpmTyped,
50     PpmIdentified,
51     PpmExpandedIdentified,
52     PpmExpandedHygiene,
53 }
54
55 #[derive(Copy, PartialEq, Show)]
56 pub enum PpMode {
57     PpmSource(PpSourceMode),
58     PpmFlowGraph,
59 }
60
61 pub fn parse_pretty(sess: &Session,
62                     name: &str,
63                     extended: bool) -> (PpMode, Option<UserIdentifiedItem>) {
64     let mut split = name.splitn(1, '=');
65     let first = split.next().unwrap();
66     let opt_second = split.next();
67     let first = match (first, extended) {
68         ("normal", _)       => PpmSource(PpmNormal),
69         ("everybody_loops", true) => PpmSource(PpmEveryBodyLoops),
70         ("expanded", _)     => PpmSource(PpmExpanded),
71         ("typed", _)        => PpmSource(PpmTyped),
72         ("expanded,identified", _) => PpmSource(PpmExpandedIdentified),
73         ("expanded,hygiene", _) => PpmSource(PpmExpandedHygiene),
74         ("identified", _)   => PpmSource(PpmIdentified),
75         ("flowgraph", true)    => PpmFlowGraph,
76         _ => {
77             if extended {
78                 sess.fatal(format!(
79                     "argument to `xpretty` must be one of `normal`, \
80                      `expanded`, `flowgraph=<nodeid>`, `typed`, `identified`, \
81                      `expanded,identified`, or `everybody_loops`; got {}", name).as_slice());
82             } else {
83                 sess.fatal(format!(
84                     "argument to `pretty` must be one of `normal`, \
85                      `expanded`, `typed`, `identified`, \
86                      or `expanded,identified`; got {}", name).as_slice());
87             }
88         }
89     };
90     let opt_second = opt_second.and_then(|s| s.parse::<UserIdentifiedItem>());
91     (first, opt_second)
92 }
93
94
95
96 // This slightly awkward construction is to allow for each PpMode to
97 // choose whether it needs to do analyses (which can consume the
98 // Session) and then pass through the session (now attached to the
99 // analysis results) on to the chosen pretty-printer, along with the
100 // `&PpAnn` object.
101 //
102 // Note that since the `&PrinterSupport` is freshly constructed on each
103 // call, it would not make sense to try to attach the lifetime of `self`
104 // to the lifetime of the `&PrinterObject`.
105 //
106 // (The `use_once_payload` is working around the current lack of once
107 // functions in the compiler.)
108
109 impl PpSourceMode {
110     /// Constructs a `PrinterSupport` object and passes it to `f`.
111     fn call_with_pp_support<'tcx, A, B, F>(&self,
112                                            sess: Session,
113                                            ast_map: Option<ast_map::Map<'tcx>>,
114                                            arenas: &'tcx ty::CtxtArenas<'tcx>,
115                                            id: String,
116                                            payload: B,
117                                            f: F) -> A where
118         F: FnOnce(&PrinterSupport, B) -> A,
119     {
120         match *self {
121             PpmNormal | PpmEveryBodyLoops | PpmExpanded => {
122                 let annotation = NoAnn { sess: sess, ast_map: ast_map };
123                 f(&annotation, payload)
124             }
125
126             PpmIdentified | PpmExpandedIdentified => {
127                 let annotation = IdentifiedAnnotation { sess: sess, ast_map: ast_map };
128                 f(&annotation, payload)
129             }
130             PpmExpandedHygiene => {
131                 let annotation = HygieneAnnotation { sess: sess, ast_map: ast_map };
132                 f(&annotation, payload)
133             }
134             PpmTyped => {
135                 let ast_map = ast_map.expect("--pretty=typed missing ast_map");
136                 let analysis = driver::phase_3_run_analysis_passes(sess, ast_map, arenas, id);
137                 let annotation = TypedAnnotation { analysis: analysis };
138                 f(&annotation, payload)
139             }
140         }
141     }
142 }
143
144 trait PrinterSupport<'ast>: pprust::PpAnn {
145     /// Provides a uniform interface for re-extracting a reference to a
146     /// `Session` from a value that now owns it.
147     fn sess<'a>(&'a self) -> &'a Session;
148
149     /// Provides a uniform interface for re-extracting a reference to an
150     /// `ast_map::Map` from a value that now owns it.
151     fn ast_map<'a>(&'a self) -> Option<&'a ast_map::Map<'ast>>;
152
153     /// Produces the pretty-print annotation object.
154     ///
155     /// (Rust does not yet support upcasting from a trait object to
156     /// an object for one of its super-traits.)
157     fn pp_ann<'a>(&'a self) -> &'a pprust::PpAnn;
158 }
159
160 struct NoAnn<'ast> {
161     sess: Session,
162     ast_map: Option<ast_map::Map<'ast>>
163 }
164
165 impl<'ast> PrinterSupport<'ast> for NoAnn<'ast> {
166     fn sess<'a>(&'a self) -> &'a Session { &self.sess }
167
168     fn ast_map<'a>(&'a self) -> Option<&'a ast_map::Map<'ast>> {
169         self.ast_map.as_ref()
170     }
171
172     fn pp_ann<'a>(&'a self) -> &'a pprust::PpAnn { self }
173 }
174
175 impl<'ast> pprust::PpAnn for NoAnn<'ast> {}
176
177 struct IdentifiedAnnotation<'ast> {
178     sess: Session,
179     ast_map: Option<ast_map::Map<'ast>>,
180 }
181
182 impl<'ast> PrinterSupport<'ast> for IdentifiedAnnotation<'ast> {
183     fn sess<'a>(&'a self) -> &'a Session { &self.sess }
184
185     fn ast_map<'a>(&'a self) -> Option<&'a ast_map::Map<'ast>> {
186         self.ast_map.as_ref()
187     }
188
189     fn pp_ann<'a>(&'a self) -> &'a pprust::PpAnn { self }
190 }
191
192 impl<'ast> pprust::PpAnn for IdentifiedAnnotation<'ast> {
193     fn pre(&self,
194            s: &mut pprust::State,
195            node: pprust::AnnNode) -> io::IoResult<()> {
196         match node {
197             pprust::NodeExpr(_) => s.popen(),
198             _ => Ok(())
199         }
200     }
201     fn post(&self,
202             s: &mut pprust::State,
203             node: pprust::AnnNode) -> io::IoResult<()> {
204         match node {
205             pprust::NodeIdent(_) | pprust::NodeName(_) => Ok(()),
206
207             pprust::NodeItem(item) => {
208                 try!(pp::space(&mut s.s));
209                 s.synth_comment(item.id.to_string())
210             }
211             pprust::NodeBlock(blk) => {
212                 try!(pp::space(&mut s.s));
213                 s.synth_comment(format!("block {}", blk.id))
214             }
215             pprust::NodeExpr(expr) => {
216                 try!(pp::space(&mut s.s));
217                 try!(s.synth_comment(expr.id.to_string()));
218                 s.pclose()
219             }
220             pprust::NodePat(pat) => {
221                 try!(pp::space(&mut s.s));
222                 s.synth_comment(format!("pat {}", pat.id))
223             }
224         }
225     }
226 }
227
228 struct HygieneAnnotation<'ast> {
229     sess: Session,
230     ast_map: Option<ast_map::Map<'ast>>,
231 }
232
233 impl<'ast> PrinterSupport<'ast> for HygieneAnnotation<'ast> {
234     fn sess<'a>(&'a self) -> &'a Session { &self.sess }
235
236     fn ast_map<'a>(&'a self) -> Option<&'a ast_map::Map<'ast>> {
237         self.ast_map.as_ref()
238     }
239
240     fn pp_ann<'a>(&'a self) -> &'a pprust::PpAnn { self }
241 }
242
243 impl<'ast> pprust::PpAnn for HygieneAnnotation<'ast> {
244     fn post(&self,
245             s: &mut pprust::State,
246             node: pprust::AnnNode) -> io::IoResult<()> {
247         match node {
248             pprust::NodeIdent(&ast::Ident { name: ast::Name(nm), ctxt }) => {
249                 try!(pp::space(&mut s.s));
250                 // FIXME #16420: this doesn't display the connections
251                 // between syntax contexts
252                 s.synth_comment(format!("{}#{}", nm, ctxt))
253             }
254             pprust::NodeName(&ast::Name(nm)) => {
255                 try!(pp::space(&mut s.s));
256                 s.synth_comment(nm.to_string())
257             }
258             _ => Ok(())
259         }
260     }
261 }
262
263
264 struct TypedAnnotation<'tcx> {
265     analysis: ty::CrateAnalysis<'tcx>,
266 }
267
268 impl<'tcx> PrinterSupport<'tcx> for TypedAnnotation<'tcx> {
269     fn sess<'a>(&'a self) -> &'a Session { &self.analysis.ty_cx.sess }
270
271     fn ast_map<'a>(&'a self) -> Option<&'a ast_map::Map<'tcx>> {
272         Some(&self.analysis.ty_cx.map)
273     }
274
275     fn pp_ann<'a>(&'a self) -> &'a pprust::PpAnn { self }
276 }
277
278 impl<'tcx> pprust::PpAnn for TypedAnnotation<'tcx> {
279     fn pre(&self,
280            s: &mut pprust::State,
281            node: pprust::AnnNode) -> io::IoResult<()> {
282         match node {
283             pprust::NodeExpr(_) => s.popen(),
284             _ => Ok(())
285         }
286     }
287     fn post(&self,
288             s: &mut pprust::State,
289             node: pprust::AnnNode) -> io::IoResult<()> {
290         let tcx = &self.analysis.ty_cx;
291         match node {
292             pprust::NodeExpr(expr) => {
293                 try!(pp::space(&mut s.s));
294                 try!(pp::word(&mut s.s, "as"));
295                 try!(pp::space(&mut s.s));
296                 try!(pp::word(&mut s.s,
297                               ppaux::ty_to_string(
298                                   tcx,
299                                   ty::expr_ty(tcx, expr))[]));
300                 s.pclose()
301             }
302             _ => Ok(())
303         }
304     }
305 }
306
307 fn gather_flowgraph_variants(sess: &Session) -> Vec<borrowck_dot::Variant> {
308     let print_loans   = config::FLOWGRAPH_PRINT_LOANS;
309     let print_moves   = config::FLOWGRAPH_PRINT_MOVES;
310     let print_assigns = config::FLOWGRAPH_PRINT_ASSIGNS;
311     let print_all     = config::FLOWGRAPH_PRINT_ALL;
312     let opt = |&: print_which| sess.debugging_opt(print_which);
313     let mut variants = Vec::new();
314     if opt(print_all) || opt(print_loans) {
315         variants.push(borrowck_dot::Loans);
316     }
317     if opt(print_all) || opt(print_moves) {
318         variants.push(borrowck_dot::Moves);
319     }
320     if opt(print_all) || opt(print_assigns) {
321         variants.push(borrowck_dot::Assigns);
322     }
323     variants
324 }
325
326 #[derive(Clone, Show)]
327 pub enum UserIdentifiedItem {
328     ItemViaNode(ast::NodeId),
329     ItemViaPath(Vec<String>),
330 }
331
332 impl FromStr for UserIdentifiedItem {
333     fn from_str(s: &str) -> Option<UserIdentifiedItem> {
334         s.parse().map(ItemViaNode).or_else(|| {
335             let v : Vec<_> = s.split_str("::")
336                 .map(|x|x.to_string())
337                 .collect();
338             Some(ItemViaPath(v))
339         })
340     }
341 }
342
343 enum NodesMatchingUII<'a, 'ast: 'a> {
344     NodesMatchingDirect(option::IntoIter<ast::NodeId>),
345     NodesMatchingSuffix(ast_map::NodesMatchingSuffix<'a, 'ast>),
346 }
347
348 impl<'a, 'ast> Iterator for NodesMatchingUII<'a, 'ast> {
349     type Item = ast::NodeId;
350
351     fn next(&mut self) -> Option<ast::NodeId> {
352         match self {
353             &NodesMatchingDirect(ref mut iter) => iter.next(),
354             &NodesMatchingSuffix(ref mut iter) => iter.next(),
355         }
356     }
357 }
358
359 impl UserIdentifiedItem {
360     fn reconstructed_input(&self) -> String {
361         match *self {
362             ItemViaNode(node_id) => node_id.to_string(),
363             ItemViaPath(ref parts) => parts.connect("::"),
364         }
365     }
366
367     fn all_matching_node_ids<'a, 'ast>(&'a self, map: &'a ast_map::Map<'ast>)
368                                        -> NodesMatchingUII<'a, 'ast> {
369         match *self {
370             ItemViaNode(node_id) =>
371                 NodesMatchingDirect(Some(node_id).into_iter()),
372             ItemViaPath(ref parts) =>
373                 NodesMatchingSuffix(map.nodes_matching_suffix(parts[])),
374         }
375     }
376
377     fn to_one_node_id(self, user_option: &str, sess: &Session, map: &ast_map::Map) -> ast::NodeId {
378         let fail_because = |&: is_wrong_because| -> ast::NodeId {
379             let message =
380                 format!("{} needs NodeId (int) or unique \
381                          path suffix (b::c::d); got {}, which {}",
382                         user_option,
383                         self.reconstructed_input(),
384                         is_wrong_because);
385             sess.fatal(message[])
386         };
387
388         let mut saw_node = ast::DUMMY_NODE_ID;
389         let mut seen = 0u;
390         for node in self.all_matching_node_ids(map) {
391             saw_node = node;
392             seen += 1;
393             if seen > 1 {
394                 fail_because("does not resolve uniquely");
395             }
396         }
397         if seen == 0 {
398             fail_because("does not resolve to any item");
399         }
400
401         assert!(seen == 1);
402         return saw_node;
403     }
404 }
405
406 fn needs_ast_map(ppm: &PpMode, opt_uii: &Option<UserIdentifiedItem>) -> bool {
407     match *ppm {
408         PpmSource(PpmNormal) |
409         PpmSource(PpmEveryBodyLoops) |
410         PpmSource(PpmIdentified) => opt_uii.is_some(),
411
412         PpmSource(PpmExpanded) |
413         PpmSource(PpmExpandedIdentified) |
414         PpmSource(PpmExpandedHygiene) |
415         PpmSource(PpmTyped) |
416         PpmFlowGraph => true
417     }
418 }
419
420 fn needs_expansion(ppm: &PpMode) -> bool {
421     match *ppm {
422         PpmSource(PpmNormal) |
423         PpmSource(PpmEveryBodyLoops) |
424         PpmSource(PpmIdentified) => false,
425
426         PpmSource(PpmExpanded) |
427         PpmSource(PpmExpandedIdentified) |
428         PpmSource(PpmExpandedHygiene) |
429         PpmSource(PpmTyped) |
430         PpmFlowGraph => true
431     }
432 }
433
434 struct ReplaceBodyWithLoop {
435     within_static_or_const: bool,
436 }
437
438 impl ReplaceBodyWithLoop {
439     fn new() -> ReplaceBodyWithLoop {
440         ReplaceBodyWithLoop { within_static_or_const: false }
441     }
442 }
443
444 impl fold::Folder for ReplaceBodyWithLoop {
445     fn fold_item_underscore(&mut self, i: ast::Item_) -> ast::Item_ {
446         match i {
447             ast::ItemStatic(..) | ast::ItemConst(..) => {
448                 self.within_static_or_const = true;
449                 let ret = fold::noop_fold_item_underscore(i, self);
450                 self.within_static_or_const = false;
451                 return ret;
452             }
453             _ => {
454                 fold::noop_fold_item_underscore(i, self)
455             }
456         }
457     }
458
459
460     fn fold_block(&mut self, b: P<ast::Block>) -> P<ast::Block> {
461         fn expr_to_block(rules: ast::BlockCheckMode,
462                          e: Option<P<ast::Expr>>) -> P<ast::Block> {
463             P(ast::Block {
464                 expr: e,
465                 view_items: vec![], stmts: vec![], rules: rules,
466                 id: ast::DUMMY_NODE_ID, span: codemap::DUMMY_SP,
467             })
468         }
469
470         if !self.within_static_or_const {
471
472             let empty_block = expr_to_block(ast::DefaultBlock, None);
473             let loop_expr = P(ast::Expr {
474                 node: ast::ExprLoop(empty_block, None),
475                 id: ast::DUMMY_NODE_ID, span: codemap::DUMMY_SP
476             });
477
478             expr_to_block(b.rules, Some(loop_expr))
479
480         } else {
481             fold::noop_fold_block(b, self)
482         }
483     }
484
485     // in general the pretty printer processes unexpanded code, so
486     // we override the default `fold_mac` method which panics.
487     fn fold_mac(&mut self, _macro: ast::Mac) -> ast::Mac {
488         fold::noop_fold_mac(_macro, self)
489     }
490 }
491
492 pub fn pretty_print_input(sess: Session,
493                           cfg: ast::CrateConfig,
494                           input: &Input,
495                           ppm: PpMode,
496                           opt_uii: Option<UserIdentifiedItem>,
497                           ofile: Option<Path>) {
498     let krate = driver::phase_1_parse_input(&sess, cfg, input);
499
500     let krate = if let PpmSource(PpmEveryBodyLoops) = ppm {
501         let mut fold = ReplaceBodyWithLoop::new();
502         fold.fold_crate(krate)
503     } else {
504         krate
505     };
506
507     let id = link::find_crate_name(Some(&sess), krate.attrs.as_slice(), input);
508
509     let is_expanded = needs_expansion(&ppm);
510     let compute_ast_map = needs_ast_map(&ppm, &opt_uii);
511     let krate = if compute_ast_map {
512         match driver::phase_2_configure_and_expand(&sess, krate, id[], None) {
513             None => return,
514             Some(k) => k
515         }
516     } else {
517         krate
518     };
519
520     let mut forest = ast_map::Forest::new(krate);
521     let arenas = ty::CtxtArenas::new();
522
523     let (krate, ast_map) = if compute_ast_map {
524         let map = driver::assign_node_ids_and_map(&sess, &mut forest);
525         (map.krate(), Some(map))
526     } else {
527         (forest.krate(), None)
528     };
529
530     let src_name = driver::source_name(input);
531     let src = sess.codemap().get_filemap(src_name[])
532                             .src.as_bytes().to_vec();
533     let mut rdr = MemReader::new(src);
534
535     let out = match ofile {
536         None => box io::stdout() as Box<Writer+'static>,
537         Some(p) => {
538             let r = io::File::create(&p);
539             match r {
540                 Ok(w) => box w as Box<Writer+'static>,
541                 Err(e) => panic!("print-print failed to open {} due to {}",
542                                 p.display(), e),
543             }
544         }
545     };
546
547     match (ppm, opt_uii) {
548         (PpmSource(s), None) =>
549             s.call_with_pp_support(
550                 sess, ast_map, &arenas, id, out, |annotation, out| {
551                     debug!("pretty printing source code {}", s);
552                     let sess = annotation.sess();
553                     pprust::print_crate(sess.codemap(),
554                                         sess.diagnostic(),
555                                         krate,
556                                         src_name.to_string(),
557                                         &mut rdr,
558                                         out,
559                                         annotation.pp_ann(),
560                                         is_expanded)
561                 }),
562
563         (PpmSource(s), Some(uii)) =>
564             s.call_with_pp_support(
565                 sess, ast_map, &arenas, id, (out,uii), |annotation, (out,uii)| {
566                     debug!("pretty printing source code {}", s);
567                     let sess = annotation.sess();
568                     let ast_map = annotation.ast_map()
569                         .expect("--pretty missing ast_map");
570                     let mut pp_state =
571                         pprust::State::new_from_input(sess.codemap(),
572                                                       sess.diagnostic(),
573                                                       src_name.to_string(),
574                                                       &mut rdr,
575                                                       out,
576                                                       annotation.pp_ann(),
577                                                       is_expanded);
578                     for node_id in uii.all_matching_node_ids(ast_map) {
579                         let node = ast_map.get(node_id);
580                         try!(pp_state.print_node(&node));
581                         try!(pp::space(&mut pp_state.s));
582                         try!(pp_state.synth_comment(ast_map.path_to_string(node_id)));
583                         try!(pp::hardbreak(&mut pp_state.s));
584                     }
585                     pp::eof(&mut pp_state.s)
586                 }),
587
588         (PpmFlowGraph, opt_uii) => {
589             debug!("pretty printing flow graph for {}", opt_uii);
590             let uii = opt_uii.unwrap_or_else(|| {
591                 sess.fatal(format!("`pretty flowgraph=..` needs NodeId (int) or
592                                      unique path suffix (b::c::d)")[])
593
594             });
595             let ast_map = ast_map.expect("--pretty flowgraph missing ast_map");
596             let nodeid = uii.to_one_node_id("--pretty", &sess, &ast_map);
597
598             let node = ast_map.find(nodeid).unwrap_or_else(|| {
599                 sess.fatal(format!("--pretty flowgraph couldn't find id: {}",
600                                    nodeid)[])
601             });
602
603             let code = blocks::Code::from_node(node);
604             match code {
605                 Some(code) => {
606                     let variants = gather_flowgraph_variants(&sess);
607                     let analysis = driver::phase_3_run_analysis_passes(sess, ast_map, &arenas, id);
608                     print_flowgraph(variants, analysis, code, out)
609                 }
610                 None => {
611                     let message = format!("--pretty=flowgraph needs \
612                                            block, fn, or method; got {}",
613                                           node);
614
615                     // point to what was found, if there's an
616                     // accessible span.
617                     match ast_map.opt_span(nodeid) {
618                         Some(sp) => sess.span_fatal(sp, message[]),
619                         None => sess.fatal(message[])
620                     }
621                 }
622             }
623         }
624     }.unwrap()
625 }
626
627 fn print_flowgraph<W:io::Writer>(variants: Vec<borrowck_dot::Variant>,
628                                  analysis: ty::CrateAnalysis,
629                                  code: blocks::Code,
630                                  mut out: W) -> io::IoResult<()> {
631     let ty_cx = &analysis.ty_cx;
632     let cfg = match code {
633         blocks::BlockCode(block) => cfg::CFG::new(ty_cx, &*block),
634         blocks::FnLikeCode(fn_like) => cfg::CFG::new(ty_cx, &*fn_like.body()),
635     };
636
637     match code {
638         _ if variants.len() == 0 => {
639             let lcfg = LabelledCFG {
640                 ast_map: &ty_cx.map,
641                 cfg: &cfg,
642                 name: format!("node_{}", code.id()),
643             };
644             let r = dot::render(&lcfg, &mut out);
645             return expand_err_details(r);
646         }
647         blocks::BlockCode(_) => {
648             ty_cx.sess.err("--pretty flowgraph with -Z flowgraph-print \
649                             annotations requires fn-like node id.");
650             return Ok(())
651         }
652         blocks::FnLikeCode(fn_like) => {
653             let fn_parts = borrowck::FnPartsWithCFG::from_fn_like(&fn_like, &cfg);
654             let (bccx, analysis_data) =
655                 borrowck::build_borrowck_dataflow_data_for_fn(ty_cx, fn_parts);
656
657             let lcfg = LabelledCFG {
658                 ast_map: &ty_cx.map,
659                 cfg: &cfg,
660                 name: format!("node_{}", code.id()),
661             };
662             let lcfg = borrowck_dot::DataflowLabeller {
663                 inner: lcfg,
664                 variants: variants,
665                 borrowck_ctxt: &bccx,
666                 analysis_data: &analysis_data,
667             };
668             let r = dot::render(&lcfg, &mut out);
669             return expand_err_details(r);
670         }
671     }
672
673     fn expand_err_details(r: io::IoResult<()>) -> io::IoResult<()> {
674         r.map_err(|ioerr| {
675             let orig_detail = ioerr.detail.clone();
676             let m = "graphviz::render failed";
677             io::IoError {
678                 detail: Some(match orig_detail {
679                     None => m.to_string(),
680                     Some(d) => format!("{}: {}", m, d)
681                 }),
682                 ..ioerr
683             }
684         })
685     }
686 }