1 //! The various pretty-printing routines.
4 use rustc::cfg::graphviz::LabelledCFG;
6 use rustc::hir::map as hir_map;
7 use rustc::hir::map::blocks;
8 use rustc::hir::print as pprust_hir;
9 use rustc::hir::def_id::LOCAL_CRATE;
10 use rustc::session::Session;
11 use rustc::session::config::Input;
12 use rustc::ty::{self, TyCtxt};
13 use rustc::util::common::ErrorReported;
14 use rustc_interface::util::ReplaceBodyWithLoop;
15 use rustc_ast_borrowck as borrowck;
16 use rustc_ast_borrowck::graphviz as borrowck_dot;
17 use rustc_mir::util::{write_mir_pretty, write_mir_graphviz};
20 use syntax::mut_visit::MutVisitor;
21 use syntax::print::{pprust};
22 use syntax_pos::FileName;
28 use std::io::{self, Write};
31 use std::str::FromStr;
33 pub use self::UserIdentifiedItem::*;
34 pub use self::PpSourceMode::*;
35 pub use self::PpMode::*;
36 use self::NodesMatchingUII::*;
37 use crate::abort_on_err;
39 use crate::source_name;
41 #[derive(Copy, Clone, PartialEq, Debug)]
42 pub enum PpSourceMode {
47 PpmExpandedIdentified,
52 #[derive(Copy, Clone, PartialEq, Debug)]
53 pub enum PpFlowGraphMode {
55 /// Drops the labels from the edges in the flowgraph output. This
56 /// is mostly for use in the -Z unpretty flowgraph run-make tests,
57 /// since the labels are largely uninteresting in those cases and
58 /// have become a pain to maintain.
61 #[derive(Copy, Clone, PartialEq, Debug)]
63 PpmSource(PpSourceMode),
65 PpmHirTree(PpSourceMode),
66 PpmFlowGraph(PpFlowGraphMode),
72 pub fn needs_ast_map(&self, opt_uii: &Option<UserIdentifiedItem>) -> bool {
74 PpmSource(PpmNormal) |
75 PpmSource(PpmEveryBodyLoops) |
76 PpmSource(PpmIdentified) => opt_uii.is_some(),
78 PpmSource(PpmExpanded) |
79 PpmSource(PpmExpandedIdentified) |
80 PpmSource(PpmExpandedHygiene) |
85 PpmFlowGraph(_) => true,
86 PpmSource(PpmTyped) => panic!("invalid state"),
90 pub fn needs_analysis(&self) -> bool {
92 PpmMir | PpmMirCFG | PpmFlowGraph(_) => true,
98 pub fn parse_pretty(sess: &Session,
101 -> (PpMode, Option<UserIdentifiedItem>) {
102 let mut split = name.splitn(2, '=');
103 let first = split.next().unwrap();
104 let opt_second = split.next();
105 let first = match (first, extended) {
106 ("normal", _) => PpmSource(PpmNormal),
107 ("identified", _) => PpmSource(PpmIdentified),
108 ("everybody_loops", true) => PpmSource(PpmEveryBodyLoops),
109 ("expanded", _) => PpmSource(PpmExpanded),
110 ("expanded,identified", _) => PpmSource(PpmExpandedIdentified),
111 ("expanded,hygiene", _) => PpmSource(PpmExpandedHygiene),
112 ("hir", true) => PpmHir(PpmNormal),
113 ("hir,identified", true) => PpmHir(PpmIdentified),
114 ("hir,typed", true) => PpmHir(PpmTyped),
115 ("hir-tree", true) => PpmHirTree(PpmNormal),
116 ("mir", true) => PpmMir,
117 ("mir-cfg", true) => PpmMirCFG,
118 ("flowgraph", true) => PpmFlowGraph(PpFlowGraphMode::Default),
119 ("flowgraph,unlabelled", true) => PpmFlowGraph(PpFlowGraphMode::UnlabelledEdges),
122 sess.fatal(&format!("argument to `unpretty` must be one of `normal`, \
123 `expanded`, `flowgraph[,unlabelled]=<nodeid>`, \
124 `identified`, `expanded,identified`, `everybody_loops`, \
125 `hir`, `hir,identified`, `hir,typed`, `hir-tree`, \
126 `mir` or `mir-cfg`; got {}",
129 sess.fatal(&format!("argument to `pretty` must be one of `normal`, `expanded`, \
130 `identified`, or `expanded,identified`; got {}",
135 let opt_second = opt_second.and_then(|s| s.parse::<UserIdentifiedItem>().ok());
141 // This slightly awkward construction is to allow for each PpMode to
142 // choose whether it needs to do analyses (which can consume the
143 // Session) and then pass through the session (now attached to the
144 // analysis results) on to the chosen pretty-printer, along with the
147 // Note that since the `&PrinterSupport` is freshly constructed on each
148 // call, it would not make sense to try to attach the lifetime of `self`
149 // to the lifetime of the `&PrinterObject`.
151 // (The `use_once_payload` is working around the current lack of once
152 // functions in the compiler.)
155 /// Constructs a `PrinterSupport` object and passes it to `f`.
156 fn call_with_pp_support<'tcx, A, F>(
159 tcx: Option<TyCtxt<'tcx>>,
163 F: FnOnce(&dyn PrinterSupport) -> A,
166 PpmNormal | PpmEveryBodyLoops | PpmExpanded => {
167 let annotation = NoAnn {
174 PpmIdentified | PpmExpandedIdentified => {
175 let annotation = IdentifiedAnnotation {
181 PpmExpandedHygiene => {
182 let annotation = HygieneAnnotation {
187 _ => panic!("Should use call_with_pp_support_hir"),
190 fn call_with_pp_support_hir<A, F>(&self, tcx: TyCtxt<'_>, f: F) -> A
192 F: FnOnce(&dyn HirPrinterSupport<'_>, &hir::Crate) -> A,
196 let annotation = NoAnn {
200 f(&annotation, tcx.hir().forest.krate())
204 let annotation = IdentifiedAnnotation {
208 f(&annotation, tcx.hir().forest.krate())
211 abort_on_err(tcx.analysis(LOCAL_CRATE), tcx.sess);
213 let empty_tables = ty::TypeckTables::empty(None);
214 let annotation = TypedAnnotation {
216 tables: Cell::new(&empty_tables)
218 tcx.dep_graph.with_ignore(|| {
219 f(&annotation, tcx.hir().forest.krate())
222 _ => panic!("Should use call_with_pp_support"),
227 trait PrinterSupport: pprust::PpAnn {
228 /// Provides a uniform interface for re-extracting a reference to a
229 /// `Session` from a value that now owns it.
230 fn sess(&self) -> &Session;
232 /// Produces the pretty-print annotation object.
234 /// (Rust does not yet support upcasting from a trait object to
235 /// an object for one of its super-traits.)
236 fn pp_ann<'a>(&'a self) -> &'a dyn pprust::PpAnn;
239 trait HirPrinterSupport<'hir>: pprust_hir::PpAnn {
240 /// Provides a uniform interface for re-extracting a reference to a
241 /// `Session` from a value that now owns it.
242 fn sess(&self) -> &Session;
244 /// Provides a uniform interface for re-extracting a reference to an
245 /// `hir_map::Map` from a value that now owns it.
246 fn hir_map<'a>(&'a self) -> Option<&'a hir_map::Map<'hir>>;
248 /// Produces the pretty-print annotation object.
250 /// (Rust does not yet support upcasting from a trait object to
251 /// an object for one of its super-traits.)
252 fn pp_ann<'a>(&'a self) -> &'a dyn pprust_hir::PpAnn;
254 /// Computes an user-readable representation of a path, if possible.
255 fn node_path(&self, id: hir::HirId) -> Option<String> {
256 self.hir_map().and_then(|map| {
257 map.def_path_from_hir_id(id)
261 .map(|elem| elem.data.to_string())
270 tcx: Option<TyCtxt<'hir>>,
273 impl<'hir> PrinterSupport for NoAnn<'hir> {
274 fn sess(&self) -> &Session {
278 fn pp_ann<'a>(&'a self) -> &'a dyn pprust::PpAnn {
283 impl<'hir> HirPrinterSupport<'hir> for NoAnn<'hir> {
284 fn sess(&self) -> &Session {
288 fn hir_map<'a>(&'a self) -> Option<&'a hir_map::Map<'hir>> {
289 self.tcx.map(|tcx| tcx.hir())
292 fn pp_ann<'a>(&'a self) -> &'a dyn pprust_hir::PpAnn {
297 impl<'hir> pprust::PpAnn for NoAnn<'hir> {}
298 impl<'hir> pprust_hir::PpAnn for NoAnn<'hir> {
299 fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) {
300 if let Some(tcx) = self.tcx {
301 pprust_hir::PpAnn::nested(tcx.hir(), state, nested)
306 struct IdentifiedAnnotation<'hir> {
308 tcx: Option<TyCtxt<'hir>>,
311 impl<'hir> PrinterSupport for IdentifiedAnnotation<'hir> {
312 fn sess(&self) -> &Session {
316 fn pp_ann<'a>(&'a self) -> &'a dyn pprust::PpAnn {
321 impl<'hir> pprust::PpAnn for IdentifiedAnnotation<'hir> {
322 fn pre(&self, s: &mut pprust::State<'_>, node: pprust::AnnNode<'_>) {
324 pprust::AnnNode::Expr(_) => s.popen(),
328 fn post(&self, s: &mut pprust::State<'_>, node: pprust::AnnNode<'_>) {
330 pprust::AnnNode::Ident(_) |
331 pprust::AnnNode::Name(_) => {},
333 pprust::AnnNode::Item(item) => {
335 s.synth_comment(item.id.to_string())
337 pprust::AnnNode::SubItem(id) => {
339 s.synth_comment(id.to_string())
341 pprust::AnnNode::Block(blk) => {
343 s.synth_comment(format!("block {}", blk.id))
345 pprust::AnnNode::Expr(expr) => {
347 s.synth_comment(expr.id.to_string());
350 pprust::AnnNode::Pat(pat) => {
352 s.synth_comment(format!("pat {}", pat.id));
358 impl<'hir> HirPrinterSupport<'hir> for IdentifiedAnnotation<'hir> {
359 fn sess(&self) -> &Session {
363 fn hir_map<'a>(&'a self) -> Option<&'a hir_map::Map<'hir>> {
364 self.tcx.map(|tcx| tcx.hir())
367 fn pp_ann<'a>(&'a self) -> &'a dyn pprust_hir::PpAnn {
372 impl<'hir> pprust_hir::PpAnn for IdentifiedAnnotation<'hir> {
373 fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) {
374 if let Some(ref tcx) = self.tcx {
375 pprust_hir::PpAnn::nested(tcx.hir(), state, nested)
378 fn pre(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
380 pprust_hir::AnnNode::Expr(_) => s.popen(),
384 fn post(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
386 pprust_hir::AnnNode::Name(_) => {},
387 pprust_hir::AnnNode::Item(item) => {
389 s.synth_comment(format!("hir_id: {}", item.hir_id));
391 pprust_hir::AnnNode::SubItem(id) => {
393 s.synth_comment(id.to_string());
395 pprust_hir::AnnNode::Block(blk) => {
397 s.synth_comment(format!("block hir_id: {}", blk.hir_id));
399 pprust_hir::AnnNode::Expr(expr) => {
401 s.synth_comment(format!("expr hir_id: {}", expr.hir_id));
404 pprust_hir::AnnNode::Pat(pat) => {
406 s.synth_comment(format!("pat hir_id: {}", pat.hir_id));
408 pprust_hir::AnnNode::Arm(arm) => {
410 s.synth_comment(format!("arm hir_id: {}", arm.hir_id));
416 struct HygieneAnnotation<'a> {
420 impl<'a> PrinterSupport for HygieneAnnotation<'a> {
421 fn sess(&self) -> &Session {
425 fn pp_ann(&self) -> &dyn pprust::PpAnn {
430 impl<'a> pprust::PpAnn for HygieneAnnotation<'a> {
431 fn post(&self, s: &mut pprust::State<'_>, node: pprust::AnnNode<'_>) {
433 pprust::AnnNode::Ident(&ast::Ident { name, span }) => {
435 // FIXME #16420: this doesn't display the connections
436 // between syntax contexts
437 s.synth_comment(format!("{}{:?}", name.as_u32(), span.ctxt()))
439 pprust::AnnNode::Name(&name) => {
441 s.synth_comment(name.as_u32().to_string())
448 struct TypedAnnotation<'a, 'tcx> {
450 tables: Cell<&'a ty::TypeckTables<'tcx>>,
453 impl<'b, 'tcx> HirPrinterSupport<'tcx> for TypedAnnotation<'b, 'tcx> {
454 fn sess(&self) -> &Session {
458 fn hir_map<'a>(&'a self) -> Option<&'a hir_map::Map<'tcx>> {
459 Some(&self.tcx.hir())
462 fn pp_ann<'a>(&'a self) -> &'a dyn pprust_hir::PpAnn {
466 fn node_path(&self, id: hir::HirId) -> Option<String> {
467 Some(self.tcx.def_path_str(self.tcx.hir().local_def_id(id)))
471 impl<'a, 'tcx> pprust_hir::PpAnn for TypedAnnotation<'a, 'tcx> {
472 fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) {
473 let old_tables = self.tables.get();
474 if let pprust_hir::Nested::Body(id) = nested {
475 self.tables.set(self.tcx.body_tables(id));
477 pprust_hir::PpAnn::nested(self.tcx.hir(), state, nested);
478 self.tables.set(old_tables);
480 fn pre(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
482 pprust_hir::AnnNode::Expr(_) => s.popen(),
486 fn post(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
488 pprust_hir::AnnNode::Expr(expr) => {
492 s.s.word(self.tables.get().expr_ty(expr).to_string());
500 fn gather_flowgraph_variants(sess: &Session) -> Vec<borrowck_dot::Variant> {
501 let print_loans = sess.opts.debugging_opts.flowgraph_print_loans;
502 let print_moves = sess.opts.debugging_opts.flowgraph_print_moves;
503 let print_assigns = sess.opts.debugging_opts.flowgraph_print_assigns;
504 let print_all = sess.opts.debugging_opts.flowgraph_print_all;
505 let mut variants = Vec::new();
506 if print_all || print_loans {
507 variants.push(borrowck_dot::Loans);
509 if print_all || print_moves {
510 variants.push(borrowck_dot::Moves);
512 if print_all || print_assigns {
513 variants.push(borrowck_dot::Assigns);
518 #[derive(Clone, Debug)]
519 pub enum UserIdentifiedItem {
520 ItemViaNode(ast::NodeId),
521 ItemViaPath(Vec<String>),
524 impl FromStr for UserIdentifiedItem {
526 fn from_str(s: &str) -> Result<UserIdentifiedItem, ()> {
528 .map(ast::NodeId::from_u32)
530 .unwrap_or_else(|_| ItemViaPath(s.split("::").map(|s| s.to_string()).collect())))
534 enum NodesMatchingUII<'a> {
535 NodesMatchingDirect(option::IntoIter<ast::NodeId>),
536 NodesMatchingSuffix(Box<dyn Iterator<Item = ast::NodeId> + 'a>),
539 impl<'a> Iterator for NodesMatchingUII<'a> {
540 type Item = ast::NodeId;
542 fn next(&mut self) -> Option<ast::NodeId> {
544 &mut NodesMatchingDirect(ref mut iter) => iter.next(),
545 &mut NodesMatchingSuffix(ref mut iter) => iter.next(),
549 fn size_hint(&self) -> (usize, Option<usize>) {
551 &NodesMatchingDirect(ref iter) => iter.size_hint(),
552 &NodesMatchingSuffix(ref iter) => iter.size_hint(),
557 impl UserIdentifiedItem {
558 fn reconstructed_input(&self) -> String {
560 ItemViaNode(node_id) => node_id.to_string(),
561 ItemViaPath(ref parts) => parts.join("::"),
565 fn all_matching_node_ids<'a, 'hir>(&'a self,
566 map: &'a hir_map::Map<'hir>)
567 -> NodesMatchingUII<'a> {
569 ItemViaNode(node_id) => NodesMatchingDirect(Some(node_id).into_iter()),
570 ItemViaPath(ref parts) => {
571 NodesMatchingSuffix(Box::new(map.nodes_matching_suffix(&parts)))
576 fn to_one_node_id(self,
579 map: &hir_map::Map<'_>)
581 let fail_because = |is_wrong_because| -> ast::NodeId {
582 let message = format!("{} needs NodeId (int) or unique path suffix (b::c::d); got \
585 self.reconstructed_input(),
590 let mut saw_node = ast::DUMMY_NODE_ID;
592 for node in self.all_matching_node_ids(map) {
596 fail_because("does not resolve uniquely");
600 fail_because("does not resolve to any item");
608 fn print_flowgraph<'tcx, W: Write>(
609 variants: Vec<borrowck_dot::Variant>,
611 code: blocks::Code<'tcx>,
612 mode: PpFlowGraphMode,
614 ) -> io::Result<()> {
615 let body_id = match code {
616 blocks::Code::Expr(expr) => {
617 // Find the function this expression is from.
618 let mut hir_id = expr.hir_id;
620 let node = tcx.hir().get(hir_id);
621 if let Some(n) = hir::map::blocks::FnLikeNode::from_node(node) {
624 let parent = tcx.hir().get_parent_node(hir_id);
625 assert_ne!(hir_id, parent);
629 blocks::Code::FnLike(fn_like) => fn_like.body(),
631 let body = tcx.hir().body(body_id);
632 let cfg = cfg::CFG::new(tcx, &body);
633 let labelled_edges = mode != PpFlowGraphMode::UnlabelledEdges;
634 let hir_id = code.id();
635 // We have to disassemble the hir_id because name must be ASCII
636 // alphanumeric. This does not appear in the rendered graph, so it does not
637 // have to be user friendly.
640 hir_id.owner.index(),
641 hir_id.local_id.index(),
643 let lcfg = LabelledCFG {
651 _ if variants.is_empty() => {
652 let r = dot::render(&lcfg, &mut out);
653 return expand_err_details(r);
655 blocks::Code::Expr(_) => {
656 tcx.sess.err("--pretty flowgraph with -Z flowgraph-print annotations requires \
660 blocks::Code::FnLike(fn_like) => {
661 let (bccx, analysis_data) =
662 borrowck::build_borrowck_dataflow_data_for_fn(tcx, fn_like.body(), &cfg);
664 let lcfg = borrowck_dot::DataflowLabeller {
667 borrowck_ctxt: &bccx,
668 analysis_data: &analysis_data,
670 let r = dot::render(&lcfg, &mut out);
671 return expand_err_details(r);
675 fn expand_err_details(r: io::Result<()>) -> io::Result<()> {
677 io::Error::new(io::ErrorKind::Other,
678 format!("graphviz::render failed: {}", ioerr))
683 pub fn visit_crate(sess: &Session, krate: &mut ast::Crate, ppm: PpMode) {
684 if let PpmSource(PpmEveryBodyLoops) = ppm {
685 ReplaceBodyWithLoop::new(sess).visit_crate(krate);
689 fn get_source(input: &Input, sess: &Session) -> (String, FileName) {
690 let src_name = source_name(input);
691 let src = String::clone(&sess.source_map()
692 .get_source_file(&src_name)
700 fn write_output(out: Vec<u8>, ofile: Option<&Path>) {
702 None => print!("{}", String::from_utf8(out).unwrap()),
704 match File::create(p) {
705 Ok(mut w) => w.write_all(&out).unwrap(),
706 Err(e) => panic!("print-print failed to open {} due to {}", p.display(), e),
712 pub fn print_after_parsing(sess: &Session,
716 ofile: Option<&Path>) {
717 let (src, src_name) = get_source(input, sess);
719 let mut out = String::new();
721 if let PpmSource(s) = ppm {
722 // Silently ignores an identified node.
724 s.call_with_pp_support(sess, None, move |annotation| {
725 debug!("pretty printing source code {:?}", s);
726 let sess = annotation.sess();
727 *out = pprust::print_crate(sess.source_map(),
739 write_output(out.into_bytes(), ofile);
742 pub fn print_after_hir_lowering<'tcx>(
747 opt_uii: Option<UserIdentifiedItem>,
748 ofile: Option<&Path>,
750 if ppm.needs_analysis() {
751 abort_on_err(print_with_analysis(
760 let (src, src_name) = get_source(input, tcx.sess);
762 let mut out = String::new();
764 match (ppm, opt_uii) {
765 (PpmSource(s), _) => {
766 // Silently ignores an identified node.
768 let src = src.clone();
769 s.call_with_pp_support(tcx.sess, Some(tcx), move |annotation| {
770 debug!("pretty printing source code {:?}", s);
771 let sess = annotation.sess();
772 *out = pprust::print_crate(sess.source_map(),
782 (PpmHir(s), None) => {
784 let src = src.clone();
785 s.call_with_pp_support_hir(tcx, move |annotation, krate| {
786 debug!("pretty printing source code {:?}", s);
787 let sess = annotation.sess();
788 *out = pprust_hir::print_crate(sess.source_map(),
797 (PpmHirTree(s), None) => {
799 s.call_with_pp_support_hir(tcx, move |_annotation, krate| {
800 debug!("pretty printing source code {:?}", s);
801 *out = format!("{:#?}", krate);
805 (PpmHir(s), Some(uii)) => {
807 let src = src.clone();
808 s.call_with_pp_support_hir(tcx, move |annotation, _| {
809 debug!("pretty printing source code {:?}", s);
810 let sess = annotation.sess();
811 let hir_map = annotation.hir_map().expect("-Z unpretty missing HIR map");
812 let mut pp_state = pprust_hir::State::new_from_input(sess.source_map(),
816 annotation.pp_ann());
817 for node_id in uii.all_matching_node_ids(hir_map) {
818 let hir_id = tcx.hir().node_to_hir_id(node_id);
819 let node = hir_map.get(hir_id);
820 pp_state.print_node(node);
822 let path = annotation.node_path(hir_id)
823 .expect("-Z unpretty missing node paths");
824 pp_state.synth_comment(path);
825 pp_state.s.hardbreak();
827 *out = pp_state.s.eof();
831 (PpmHirTree(s), Some(uii)) => {
833 s.call_with_pp_support_hir(tcx, move |_annotation, _krate| {
834 debug!("pretty printing source code {:?}", s);
835 for node_id in uii.all_matching_node_ids(tcx.hir()) {
836 let hir_id = tcx.hir().node_to_hir_id(node_id);
837 let node = tcx.hir().get(hir_id);
838 out.push_str(&format!("{:#?}", node));
846 write_output(out.into_bytes(), ofile);
849 // In an ideal world, this would be a public function called by the driver after
850 // analysis is performed. However, we want to call `phase_3_run_analysis_passes`
851 // with a different callback than the standard driver, so that isn't easy.
852 // Instead, we call that function ourselves.
853 fn print_with_analysis(
856 uii: Option<UserIdentifiedItem>,
857 ofile: Option<&Path>,
858 ) -> Result<(), ErrorReported> {
859 let nodeid = if let Some(uii) = uii {
860 debug!("pretty printing for {:?}", uii);
861 Some(uii.to_one_node_id("-Z unpretty", tcx.sess, tcx.hir()))
863 debug!("pretty printing for whole crate");
867 let mut out = Vec::new();
869 tcx.analysis(LOCAL_CRATE)?;
871 let mut print = || match ppm {
872 PpmMir | PpmMirCFG => {
873 if let Some(nodeid) = nodeid {
874 let def_id = tcx.hir().local_def_id_from_node_id(nodeid);
876 PpmMir => write_mir_pretty(tcx, Some(def_id), &mut out),
877 PpmMirCFG => write_mir_graphviz(tcx, Some(def_id), &mut out),
882 PpmMir => write_mir_pretty(tcx, None, &mut out),
883 PpmMirCFG => write_mir_graphviz(tcx, None, &mut out),
889 PpmFlowGraph(mode) => {
891 nodeid.expect("`pretty flowgraph=..` needs NodeId (int) or unique path \
893 let hir_id = tcx.hir().node_to_hir_id(nodeid);
894 let node = tcx.hir().find(hir_id).unwrap_or_else(|| {
895 tcx.sess.fatal(&format!("--pretty flowgraph couldn't find id: {}", nodeid))
898 match blocks::Code::from_node(&tcx.hir(), hir_id) {
900 let variants = gather_flowgraph_variants(tcx.sess);
902 let out: &mut dyn Write = &mut out;
904 print_flowgraph(variants, tcx, code, mode, out)
907 let message = format!("--pretty=flowgraph needs block, fn, or method; \
911 let hir_id = tcx.hir().node_to_hir_id(nodeid);
912 tcx.sess.span_fatal(tcx.hir().span(hir_id), &message)
921 write_output(out, ofile);