]> git.lizzy.rs Git - rust.git/blob - src/librustc_mir/util/pretty.rs
Rollup merge of #58301 - RalfJung:fat-ptr-eq, r=oli-obk
[rust.git] / src / librustc_mir / util / pretty.rs
1 use rustc::hir::def_id::{DefId, LOCAL_CRATE};
2 use rustc::mir::*;
3 use rustc::mir::visit::Visitor;
4 use rustc::ty::{self, TyCtxt};
5 use rustc::ty::item_path;
6 use rustc_data_structures::fx::FxHashMap;
7 use rustc_data_structures::indexed_vec::Idx;
8 use std::fmt::Display;
9 use std::fmt::Write as _;
10 use std::fs;
11 use std::io::{self, Write};
12 use std::path::{Path, PathBuf};
13 use super::graphviz::write_mir_fn_graphviz;
14 use crate::transform::MirSource;
15
16 const INDENT: &str = "    ";
17 /// Alignment for lining up comments following MIR statements
18 pub(crate) const ALIGN: usize = 40;
19
20 /// An indication of where we are in the control flow graph. Used for printing
21 /// extra information in `dump_mir`
22 pub enum PassWhere {
23     /// We have not started dumping the control flow graph, but we are about to.
24     BeforeCFG,
25
26     /// We just finished dumping the control flow graph. This is right before EOF
27     AfterCFG,
28
29     /// We are about to start dumping the given basic block.
30     BeforeBlock(BasicBlock),
31
32     /// We are just about to dump the given statement or terminator.
33     BeforeLocation(Location),
34
35     /// We just dumped the given statement or terminator.
36     AfterLocation(Location),
37
38     /// We just dumped the terminator for a block but not the closing `}`.
39     AfterTerminator(BasicBlock),
40 }
41
42 /// If the session is properly configured, dumps a human-readable
43 /// representation of the mir into:
44 ///
45 /// ```text
46 /// rustc.node<node_id>.<pass_num>.<pass_name>.<disambiguator>
47 /// ```
48 ///
49 /// Output from this function is controlled by passing `-Z dump-mir=<filter>`,
50 /// where `<filter>` takes the following forms:
51 ///
52 /// - `all` -- dump MIR for all fns, all passes, all everything
53 /// - a filter defined by a set of substrings combined with `&` and `|`
54 ///   (`&` has higher precedence). At least one of the `|`-separated groups
55 ///   must match; an `|`-separated group matches if all of its `&`-separated
56 ///   substrings are matched.
57 ///
58 /// Example:
59 ///
60 /// - `nll` == match if `nll` appears in the name
61 /// - `foo & nll` == match if `foo` and `nll` both appear in the name
62 /// - `foo & nll | typeck` == match if `foo` and `nll` both appear in the name
63 ///   or `typeck` appears in the name.
64 /// - `foo & nll | bar & typeck` == match if `foo` and `nll` both appear in the name
65 ///   or `typeck` and `bar` both appear in the name.
66 pub fn dump_mir<'a, 'gcx, 'tcx, F>(
67     tcx: TyCtxt<'a, 'gcx, 'tcx>,
68     pass_num: Option<&dyn Display>,
69     pass_name: &str,
70     disambiguator: &dyn Display,
71     source: MirSource<'tcx>,
72     mir: &Mir<'tcx>,
73     extra_data: F,
74 ) where
75     F: FnMut(PassWhere, &mut dyn Write) -> io::Result<()>,
76 {
77     if !dump_enabled(tcx, pass_name, source) {
78         return;
79     }
80
81     let node_path = item_path::with_forced_impl_filename_line(|| {
82         // see notes on #41697 below
83         tcx.item_path_str(source.def_id())
84     });
85     dump_matched_mir_node(
86         tcx,
87         pass_num,
88         pass_name,
89         &node_path,
90         disambiguator,
91         source,
92         mir,
93         extra_data,
94     );
95 }
96
97 pub fn dump_enabled<'a, 'gcx, 'tcx>(
98     tcx: TyCtxt<'a, 'gcx, 'tcx>,
99     pass_name: &str,
100     source: MirSource<'tcx>,
101 ) -> bool {
102     let filters = match tcx.sess.opts.debugging_opts.dump_mir {
103         None => return false,
104         Some(ref filters) => filters,
105     };
106     let node_path = item_path::with_forced_impl_filename_line(|| {
107         // see notes on #41697 below
108         tcx.item_path_str(source.def_id())
109     });
110     filters.split('|').any(|or_filter| {
111         or_filter.split('&').all(|and_filter| {
112             and_filter == "all" || pass_name.contains(and_filter) || node_path.contains(and_filter)
113         })
114     })
115 }
116
117 // #41697 -- we use `with_forced_impl_filename_line()` because
118 // `item_path_str()` would otherwise trigger `type_of`, and this can
119 // run while we are already attempting to evaluate `type_of`.
120
121 fn dump_matched_mir_node<'a, 'gcx, 'tcx, F>(
122     tcx: TyCtxt<'a, 'gcx, 'tcx>,
123     pass_num: Option<&dyn Display>,
124     pass_name: &str,
125     node_path: &str,
126     disambiguator: &dyn Display,
127     source: MirSource<'tcx>,
128     mir: &Mir<'tcx>,
129     mut extra_data: F,
130 ) where
131     F: FnMut(PassWhere, &mut dyn Write) -> io::Result<()>,
132 {
133     let _: io::Result<()> = try {
134         let mut file = create_dump_file(tcx, "mir", pass_num, pass_name, disambiguator, source)?;
135         writeln!(file, "// MIR for `{}`", node_path)?;
136         writeln!(file, "// source = {:?}", source)?;
137         writeln!(file, "// pass_name = {}", pass_name)?;
138         writeln!(file, "// disambiguator = {}", disambiguator)?;
139         if let Some(ref layout) = mir.generator_layout {
140             writeln!(file, "// generator_layout = {:?}", layout)?;
141         }
142         writeln!(file, "")?;
143         extra_data(PassWhere::BeforeCFG, &mut file)?;
144         write_user_type_annotations(mir, &mut file)?;
145         write_mir_fn(tcx, source, mir, &mut extra_data, &mut file)?;
146         extra_data(PassWhere::AfterCFG, &mut file)?;
147     };
148
149     if tcx.sess.opts.debugging_opts.dump_mir_graphviz {
150         let _: io::Result<()> = try {
151             let mut file =
152                 create_dump_file(tcx, "dot", pass_num, pass_name, disambiguator, source)?;
153             write_mir_fn_graphviz(tcx, source.def_id(), mir, &mut file)?;
154         };
155     }
156 }
157
158 /// Returns the path to the filename where we should dump a given MIR.
159 /// Also used by other bits of code (e.g., NLL inference) that dump
160 /// graphviz data or other things.
161 fn dump_path(
162     tcx: TyCtxt<'_, '_, '_>,
163     extension: &str,
164     pass_num: Option<&dyn Display>,
165     pass_name: &str,
166     disambiguator: &dyn Display,
167     source: MirSource<'tcx>,
168 ) -> PathBuf {
169     let promotion_id = match source.promoted {
170         Some(id) => format!("-{:?}", id),
171         None => String::new(),
172     };
173
174     let pass_num = if tcx.sess.opts.debugging_opts.dump_mir_exclude_pass_number {
175         String::new()
176     } else {
177         match pass_num {
178             None => ".-------".to_string(),
179             Some(pass_num) => format!(".{}", pass_num),
180         }
181     };
182
183     let mut file_path = PathBuf::new();
184     file_path.push(Path::new(&tcx.sess.opts.debugging_opts.dump_mir_dir));
185
186     let item_name = tcx
187         .def_path(source.def_id())
188         .to_filename_friendly_no_crate();
189     // All drop shims have the same DefId, so we have to add the type
190     // to get unique file names.
191     let shim_disambiguator = match source.instance {
192         ty::InstanceDef::DropGlue(_, Some(ty)) => {
193             // Unfortunately, pretty-printed typed are not very filename-friendly.
194             // We dome some filtering.
195             let mut s = ".".to_owned();
196             s.extend(ty.to_string()
197                 .chars()
198                 .filter_map(|c| match c {
199                     ' ' => None,
200                     ':' | '<' | '>' => Some('_'),
201                     c => Some(c)
202                 }));
203             s
204         }
205         _ => String::new(),
206     };
207
208     let file_name = format!(
209         "rustc.{}{}{}{}.{}.{}.{}",
210         item_name,
211         shim_disambiguator,
212         promotion_id,
213         pass_num,
214         pass_name,
215         disambiguator,
216         extension,
217     );
218
219     file_path.push(&file_name);
220
221     file_path
222 }
223
224 /// Attempts to open a file where we should dump a given MIR or other
225 /// bit of MIR-related data. Used by `mir-dump`, but also by other
226 /// bits of code (e.g., NLL inference) that dump graphviz data or
227 /// other things, and hence takes the extension as an argument.
228 pub(crate) fn create_dump_file(
229     tcx: TyCtxt<'_, '_, '_>,
230     extension: &str,
231     pass_num: Option<&dyn Display>,
232     pass_name: &str,
233     disambiguator: &dyn Display,
234     source: MirSource<'tcx>,
235 ) -> io::Result<fs::File> {
236     let file_path = dump_path(tcx, extension, pass_num, pass_name, disambiguator, source);
237     if let Some(parent) = file_path.parent() {
238         fs::create_dir_all(parent)?;
239     }
240     fs::File::create(&file_path)
241 }
242
243 /// Write out a human-readable textual representation for the given MIR.
244 pub fn write_mir_pretty<'a, 'gcx, 'tcx>(
245     tcx: TyCtxt<'a, 'gcx, 'tcx>,
246     single: Option<DefId>,
247     w: &mut dyn Write,
248 ) -> io::Result<()> {
249     writeln!(
250         w,
251         "// WARNING: This output format is intended for human consumers only"
252     )?;
253     writeln!(
254         w,
255         "// and is subject to change without notice. Knock yourself out."
256     )?;
257
258     let mut first = true;
259     for def_id in dump_mir_def_ids(tcx, single) {
260         let mir = &tcx.optimized_mir(def_id);
261
262         if first {
263             first = false;
264         } else {
265             // Put empty lines between all items
266             writeln!(w, "")?;
267         }
268
269         write_mir_fn(tcx, MirSource::item(def_id), mir, &mut |_, _| Ok(()), w)?;
270
271         for (i, mir) in mir.promoted.iter_enumerated() {
272             writeln!(w, "")?;
273             let src = MirSource {
274                 instance: ty::InstanceDef::Item(def_id),
275                 promoted: Some(i),
276             };
277             write_mir_fn(tcx, src, mir, &mut |_, _| Ok(()), w)?;
278         }
279     }
280     Ok(())
281 }
282
283 pub fn write_mir_fn<'a, 'gcx, 'tcx, F>(
284     tcx: TyCtxt<'a, 'gcx, 'tcx>,
285     src: MirSource<'tcx>,
286     mir: &Mir<'tcx>,
287     extra_data: &mut F,
288     w: &mut dyn Write,
289 ) -> io::Result<()>
290 where
291     F: FnMut(PassWhere, &mut dyn Write) -> io::Result<()>,
292 {
293     write_mir_intro(tcx, src, mir, w)?;
294     for block in mir.basic_blocks().indices() {
295         extra_data(PassWhere::BeforeBlock(block), w)?;
296         write_basic_block(tcx, block, mir, extra_data, w)?;
297         if block.index() + 1 != mir.basic_blocks().len() {
298             writeln!(w, "")?;
299         }
300     }
301
302     writeln!(w, "}}")?;
303     Ok(())
304 }
305
306 /// Write out a human-readable textual representation for the given basic block.
307 pub fn write_basic_block<'cx, 'gcx, 'tcx, F>(
308     tcx: TyCtxt<'cx, 'gcx, 'tcx>,
309     block: BasicBlock,
310     mir: &Mir<'tcx>,
311     extra_data: &mut F,
312     w: &mut dyn Write,
313 ) -> io::Result<()>
314 where
315     F: FnMut(PassWhere, &mut dyn Write) -> io::Result<()>,
316 {
317     let data = &mir[block];
318
319     // Basic block label at the top.
320     let cleanup_text = if data.is_cleanup { " // cleanup" } else { "" };
321     let lbl = format!("{}{:?}: {{", INDENT, block);
322     writeln!(w, "{0:1$}{2}", lbl, ALIGN, cleanup_text)?;
323
324     // List of statements in the middle.
325     let mut current_location = Location {
326         block: block,
327         statement_index: 0,
328     };
329     for statement in &data.statements {
330         extra_data(PassWhere::BeforeLocation(current_location), w)?;
331         let indented_mir = format!("{0}{0}{1:?};", INDENT, statement);
332         writeln!(
333             w,
334             "{:A$} // {:?}: {}",
335             indented_mir,
336             current_location,
337             comment(tcx, statement.source_info),
338             A = ALIGN,
339         )?;
340
341         write_extra(tcx, w, |visitor| {
342             visitor.visit_statement(current_location.block, statement, current_location);
343         })?;
344
345         extra_data(PassWhere::AfterLocation(current_location), w)?;
346
347         current_location.statement_index += 1;
348     }
349
350     // Terminator at the bottom.
351     extra_data(PassWhere::BeforeLocation(current_location), w)?;
352     let indented_terminator = format!("{0}{0}{1:?};", INDENT, data.terminator().kind);
353     writeln!(
354         w,
355         "{:A$} // {:?}: {}",
356         indented_terminator,
357         current_location,
358         comment(tcx, data.terminator().source_info),
359         A = ALIGN,
360     )?;
361
362     write_extra(tcx, w, |visitor| {
363         visitor.visit_terminator(current_location.block, data.terminator(), current_location);
364     })?;
365
366     extra_data(PassWhere::AfterLocation(current_location), w)?;
367     extra_data(PassWhere::AfterTerminator(block), w)?;
368
369     writeln!(w, "{}}}", INDENT)
370 }
371
372 /// After we print the main statement, we sometimes dump extra
373 /// information. There's often a lot of little things "nuzzled up" in
374 /// a statement.
375 fn write_extra<'cx, 'gcx, 'tcx, F>(
376     tcx: TyCtxt<'cx, 'gcx, 'tcx>,
377     write: &mut dyn Write,
378     mut visit_op: F,
379 ) -> io::Result<()>
380 where
381     F: FnMut(&mut ExtraComments<'cx, 'gcx, 'tcx>),
382 {
383     let mut extra_comments = ExtraComments {
384         _tcx: tcx,
385         comments: vec![],
386     };
387     visit_op(&mut extra_comments);
388     for comment in extra_comments.comments {
389         writeln!(write, "{:A$} // {}", "", comment, A = ALIGN)?;
390     }
391     Ok(())
392 }
393
394 struct ExtraComments<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
395     _tcx: TyCtxt<'cx, 'gcx, 'tcx>, // don't need it now, but bet we will soon
396     comments: Vec<String>,
397 }
398
399 impl<'cx, 'gcx, 'tcx> ExtraComments<'cx, 'gcx, 'tcx> {
400     fn push(&mut self, lines: &str) {
401         for line in lines.split('\n') {
402             self.comments.push(line.to_string());
403         }
404     }
405 }
406
407 impl<'cx, 'gcx, 'tcx> Visitor<'tcx> for ExtraComments<'cx, 'gcx, 'tcx> {
408     fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) {
409         self.super_constant(constant, location);
410         let Constant { span, ty, user_ty, literal } = constant;
411         self.push("mir::Constant");
412         self.push(&format!("+ span: {:?}", span));
413         self.push(&format!("+ ty: {:?}", ty));
414         if let Some(user_ty) = user_ty {
415             self.push(&format!("+ user_ty: {:?}", user_ty));
416         }
417         self.push(&format!("+ literal: {:?}", literal));
418     }
419
420     fn visit_const(&mut self, constant: &&'tcx ty::LazyConst<'tcx>, _: Location) {
421         self.super_const(constant);
422         match constant {
423             ty::LazyConst::Evaluated(constant) => {
424                 let ty::Const { ty, val, .. } = constant;
425                 self.push("ty::Const");
426                 self.push(&format!("+ ty: {:?}", ty));
427                 self.push(&format!("+ val: {:?}", val));
428             },
429             ty::LazyConst::Unevaluated(did, substs) => {
430                 self.push("ty::LazyConst::Unevaluated");
431                 self.push(&format!("+ did: {:?}", did));
432                 self.push(&format!("+ substs: {:?}", substs));
433             },
434         }
435     }
436
437     fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
438         self.super_rvalue(rvalue, location);
439         match rvalue {
440             Rvalue::Aggregate(kind, _) => match **kind {
441                 AggregateKind::Closure(def_id, substs) => {
442                     self.push("closure");
443                     self.push(&format!("+ def_id: {:?}", def_id));
444                     self.push(&format!("+ substs: {:#?}", substs));
445                 }
446
447                 AggregateKind::Generator(def_id, substs, movability) => {
448                     self.push("generator");
449                     self.push(&format!("+ def_id: {:?}", def_id));
450                     self.push(&format!("+ substs: {:#?}", substs));
451                     self.push(&format!("+ movability: {:?}", movability));
452                 }
453
454                 AggregateKind::Adt(_, _, _, Some(user_ty), _) => {
455                     self.push("adt");
456                     self.push(&format!("+ user_ty: {:?}", user_ty));
457                 }
458
459                 _ => {}
460             },
461
462             _ => {}
463         }
464     }
465 }
466
467 fn comment(tcx: TyCtxt<'_, '_, '_>, SourceInfo { span, scope }: SourceInfo) -> String {
468     format!(
469         "scope {} at {}",
470         scope.index(),
471         tcx.sess.source_map().span_to_string(span)
472     )
473 }
474
475 /// Prints user-defined variables in a scope tree.
476 ///
477 /// Returns the total number of variables printed.
478 fn write_scope_tree(
479     tcx: TyCtxt<'_, '_, '_>,
480     mir: &Mir<'_>,
481     scope_tree: &FxHashMap<SourceScope, Vec<SourceScope>>,
482     w: &mut dyn Write,
483     parent: SourceScope,
484     depth: usize,
485 ) -> io::Result<()> {
486     let indent = depth * INDENT.len();
487
488     let children = match scope_tree.get(&parent) {
489         Some(children) => children,
490         None => return Ok(()),
491     };
492
493     for &child in children {
494         let data = &mir.source_scopes[child];
495         assert_eq!(data.parent_scope, Some(parent));
496         writeln!(w, "{0:1$}scope {2} {{", "", indent, child.index())?;
497
498         // User variable types (including the user's name in a comment).
499         for local in mir.vars_iter() {
500             let var = &mir.local_decls[local];
501             let (name, source_info) = if var.source_info.scope == child {
502                 (var.name.unwrap(), var.source_info)
503             } else {
504                 // Not a variable or not declared in this scope.
505                 continue;
506             };
507
508             let mut_str = if var.mutability == Mutability::Mut {
509                 "mut "
510             } else {
511                 ""
512             };
513
514             let indent = indent + INDENT.len();
515             let mut indented_var = format!(
516                 "{0:1$}let {2}{3:?}: {4:?}",
517                 INDENT,
518                 indent,
519                 mut_str,
520                 local,
521                 var.ty
522             );
523             for user_ty in var.user_ty.projections() {
524                 write!(indented_var, " as {:?}", user_ty).unwrap();
525             }
526             indented_var.push_str(";");
527             writeln!(
528                 w,
529                 "{0:1$} // \"{2}\" in {3}",
530                 indented_var,
531                 ALIGN,
532                 name,
533                 comment(tcx, source_info)
534             )?;
535         }
536
537         write_scope_tree(tcx, mir, scope_tree, w, child, depth + 1)?;
538
539         writeln!(w, "{0:1$}}}", "", depth * INDENT.len())?;
540     }
541
542     Ok(())
543 }
544
545 /// Write out a human-readable textual representation of the MIR's `fn` type and the types of its
546 /// local variables (both user-defined bindings and compiler temporaries).
547 pub fn write_mir_intro<'a, 'gcx, 'tcx>(
548     tcx: TyCtxt<'a, 'gcx, 'tcx>,
549     src: MirSource<'tcx>,
550     mir: &Mir<'_>,
551     w: &mut dyn Write,
552 ) -> io::Result<()> {
553     write_mir_sig(tcx, src, mir, w)?;
554     writeln!(w, "{{")?;
555
556     // construct a scope tree and write it out
557     let mut scope_tree: FxHashMap<SourceScope, Vec<SourceScope>> = Default::default();
558     for (index, scope_data) in mir.source_scopes.iter().enumerate() {
559         if let Some(parent) = scope_data.parent_scope {
560             scope_tree
561                 .entry(parent)
562                 .or_default()
563                 .push(SourceScope::new(index));
564         } else {
565             // Only the argument scope has no parent, because it's the root.
566             assert_eq!(index, OUTERMOST_SOURCE_SCOPE.index());
567         }
568     }
569
570     // Print return place
571     let indented_retptr = format!("{}let mut {:?}: {};",
572                                   INDENT,
573                                   RETURN_PLACE,
574                                   mir.local_decls[RETURN_PLACE].ty);
575     writeln!(w, "{0:1$} // return place",
576              indented_retptr,
577              ALIGN)?;
578
579     write_scope_tree(tcx, mir, &scope_tree, w, OUTERMOST_SOURCE_SCOPE, 1)?;
580
581     write_temp_decls(mir, w)?;
582
583     // Add an empty line before the first block is printed.
584     writeln!(w, "")?;
585
586     Ok(())
587 }
588
589 fn write_mir_sig(
590     tcx: TyCtxt<'_, '_, '_>,
591     src: MirSource<'tcx>,
592     mir: &Mir<'_>,
593     w: &mut dyn Write,
594 ) -> io::Result<()> {
595     use rustc::hir::def::Def;
596
597     trace!("write_mir_sig: {:?}", src.instance);
598     let descr = tcx.describe_def(src.def_id());
599     let is_function = match descr {
600         Some(Def::Fn(_)) | Some(Def::Method(_)) | Some(Def::StructCtor(..)) => true,
601         _ => tcx.is_closure(src.def_id()),
602     };
603     match (descr, src.promoted) {
604         (_, Some(i)) => write!(w, "{:?} in ", i)?,
605         (Some(Def::StructCtor(..)), _) => write!(w, "struct ")?,
606         (Some(Def::Const(_)), _)
607         | (Some(Def::AssociatedConst(_)), _) => write!(w, "const ")?,
608         (Some(Def::Static(_, /*is_mutbl*/false)), _) => write!(w, "static ")?,
609         (Some(Def::Static(_, /*is_mutbl*/true)), _) => write!(w, "static mut ")?,
610         (_, _) if is_function => write!(w, "fn ")?,
611         (None, _) => {}, // things like anon const, not an item
612         _ => bug!("Unexpected def description {:?}", descr),
613     }
614
615     item_path::with_forced_impl_filename_line(|| {
616         // see notes on #41697 elsewhere
617         write!(w, "{}", tcx.item_path_str(src.def_id()))
618     })?;
619
620     if src.promoted.is_none() && is_function {
621         write!(w, "(")?;
622
623         // fn argument types.
624         for (i, arg) in mir.args_iter().enumerate() {
625             if i != 0 {
626                 write!(w, ", ")?;
627             }
628             write!(w, "{:?}: {}", Place::Local(arg), mir.local_decls[arg].ty)?;
629         }
630
631         write!(w, ") -> {}", mir.return_ty())?;
632     } else {
633         assert_eq!(mir.arg_count, 0);
634         write!(w, ": {} =", mir.return_ty())?;
635     }
636
637     if let Some(yield_ty) = mir.yield_ty {
638         writeln!(w)?;
639         writeln!(w, "yields {}", yield_ty)?;
640     }
641
642     write!(w, " ")?;
643     // Next thing that gets printed is the opening {
644
645     Ok(())
646 }
647
648 fn write_temp_decls(mir: &Mir<'_>, w: &mut dyn Write) -> io::Result<()> {
649     // Compiler-introduced temporary types.
650     for temp in mir.temps_iter() {
651         writeln!(
652             w,
653             "{}let {}{:?}: {};",
654             INDENT,
655             if mir.local_decls[temp].mutability == Mutability::Mut {"mut "} else {""},
656             temp,
657             mir.local_decls[temp].ty
658         )?;
659     }
660
661     Ok(())
662 }
663
664 fn write_user_type_annotations(mir: &Mir<'_>, w: &mut dyn Write) -> io::Result<()> {
665     if !mir.user_type_annotations.is_empty() {
666         writeln!(w, "| User Type Annotations")?;
667     }
668     for (index, annotation) in mir.user_type_annotations.iter_enumerated() {
669         writeln!(w, "| {:?}: {:?} at {:?}", index.index(), annotation.user_ty, annotation.span)?;
670     }
671     if !mir.user_type_annotations.is_empty() {
672         writeln!(w, "|")?;
673     }
674     Ok(())
675 }
676
677 pub fn dump_mir_def_ids(tcx: TyCtxt<'_, '_, '_>, single: Option<DefId>) -> Vec<DefId> {
678     if let Some(i) = single {
679         vec![i]
680     } else {
681         tcx.mir_keys(LOCAL_CRATE).iter().cloned().collect()
682     }
683 }