-use rustc::hir::def_id::{DefId, LOCAL_CRATE};
-use rustc::mir::*;
+use super::graphviz::write_mir_fn_graphviz;
+use crate::transform::MirSource;
use rustc::mir::visit::Visitor;
+use rustc::mir::*;
use rustc::ty::{self, TyCtxt};
use rustc_data_structures::fx::FxHashMap;
+use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_index::vec::Idx;
use std::fmt::Display;
use std::fmt::Write as _;
use std::fs;
use std::io::{self, Write};
use std::path::{Path, PathBuf};
-use super::graphviz::write_mir_fn_graphviz;
-use crate::transform::MirSource;
const INDENT: &str = " ";
/// Alignment for lining up comments following MIR statements
let mut file_path = PathBuf::new();
file_path.push(Path::new(&tcx.sess.opts.debugging_opts.dump_mir_dir));
- let item_name = tcx
- .def_path(source.def_id())
- .to_filename_friendly_no_crate();
+ let item_name = tcx.def_path(source.def_id()).to_filename_friendly_no_crate();
// All drop shims have the same DefId, so we have to add the type
// to get unique file names.
let shim_disambiguator = match source.instance {
// Unfortunately, pretty-printed typed are not very filename-friendly.
// We dome some filtering.
let mut s = ".".to_owned();
- s.extend(ty.to_string()
- .chars()
- .filter_map(|c| match c {
- ' ' => None,
- ':' | '<' | '>' => Some('_'),
- c => Some(c)
- }));
+ s.extend(ty.to_string().chars().filter_map(|c| match c {
+ ' ' => None,
+ ':' | '<' | '>' => Some('_'),
+ c => Some(c),
+ }));
s
}
_ => String::new(),
let file_name = format!(
"rustc.{}{}{}{}.{}.{}.{}",
- item_name,
- shim_disambiguator,
- promotion_id,
- pass_num,
- pass_name,
- disambiguator,
- extension,
+ item_name, shim_disambiguator, promotion_id, pass_num, pass_name, disambiguator, extension,
);
file_path.push(&file_name);
single: Option<DefId>,
w: &mut dyn Write,
) -> io::Result<()> {
- writeln!(
- w,
- "// WARNING: This output format is intended for human consumers only"
- )?;
- writeln!(
- w,
- "// and is subject to change without notice. Knock yourself out."
- )?;
+ writeln!(w, "// WARNING: This output format is intended for human consumers only")?;
+ writeln!(w, "// and is subject to change without notice. Knock yourself out.")?;
let mut first = true;
for def_id in dump_mir_def_ids(tcx, single) {
for (i, body) in tcx.promoted_mir(def_id).iter_enumerated() {
writeln!(w, "")?;
- let src = MirSource {
- instance: ty::InstanceDef::Item(def_id),
- promoted: Some(i),
- };
+ let src = MirSource { instance: ty::InstanceDef::Item(def_id), promoted: Some(i) };
write_mir_fn(tcx, src, body, &mut |_, _| Ok(()), w)?;
}
}
writeln!(w, "{}{:?}{}: {{", INDENT, block, cleanup_text)?;
// List of statements in the middle.
- let mut current_location = Location {
- block: block,
- statement_index: 0,
- };
+ let mut current_location = Location { block: block, statement_index: 0 };
for statement in &data.statements {
extra_data(PassWhere::BeforeLocation(current_location), w)?;
let indented_body = format!("{0}{0}{1:?};", INDENT, statement);
where
F: FnMut(&mut ExtraComments<'tcx>),
{
- let mut extra_comments = ExtraComments {
- _tcx: tcx,
- comments: vec![],
- };
+ let mut extra_comments = ExtraComments { _tcx: tcx, comments: vec![] };
visit_op(&mut extra_comments);
for comment in extra_comments.comments {
writeln!(write, "{:A$} // {}", "", comment, A = ALIGN)?;
}
fn comment(tcx: TyCtxt<'_>, SourceInfo { span, scope }: SourceInfo) -> String {
- format!(
- "scope {} at {}",
- scope.index(),
- tcx.sess.source_map().span_to_string(span)
- )
+ format!("scope {} at {}", scope.index(), tcx.sess.source_map().span_to_string(span))
}
/// Prints local variables in a scope tree.
let indented_debug_info = format!(
"{0:1$}debug {2} => {3:?};",
- INDENT,
- indent,
- var_debug_info.name,
- var_debug_info.place,
+ INDENT, indent, var_debug_info.name, var_debug_info.place,
);
writeln!(
// Local variable types (including the user's name in a comment).
for (local, local_decl) in body.local_decls.iter_enumerated() {
- if (1..body.arg_count+1).contains(&local.index()) {
+ if (1..body.arg_count + 1).contains(&local.index()) {
// Skip over argument locals, they're printed in the signature.
continue;
}
continue;
}
- let mut_str = if local_decl.mutability == Mutability::Mut {
- "mut "
- } else {
- ""
- };
+ let mut_str = if local_decl.mutability == Mutability::Mut { "mut " } else { "" };
- let mut indented_decl = format!(
- "{0:1$}let {2}{3:?}: {4:?}",
- INDENT,
- indent,
- mut_str,
- local,
- local_decl.ty
- );
+ let mut indented_decl =
+ format!("{0:1$}let {2}{3:?}: {4:?}", INDENT, indent, mut_str, local, local_decl.ty);
for user_ty in local_decl.user_ty.projections() {
write!(indented_decl, " as {:?}", user_ty).unwrap();
}
indented_decl.push_str(";");
- let local_name = if local == RETURN_PLACE {
- format!(" return place")
- } else {
- String::new()
- };
+ let local_name =
+ if local == RETURN_PLACE { " return place".to_string() } else { String::new() };
writeln!(
w,
let mut scope_tree: FxHashMap<SourceScope, Vec<SourceScope>> = Default::default();
for (index, scope_data) in body.source_scopes.iter().enumerate() {
if let Some(parent) = scope_data.parent_scope {
- scope_tree
- .entry(parent)
- .or_default()
- .push(SourceScope::new(index));
+ scope_tree.entry(parent).or_default().push(SourceScope::new(index));
} else {
// Only the argument scope has no parent, because it's the root.
assert_eq!(index, OUTERMOST_SOURCE_SCOPE.index());
body: &Body<'_>,
w: &mut dyn Write,
) -> io::Result<()> {
- use rustc::hir::def::DefKind;
+ use rustc_hir::def::DefKind;
trace!("write_mir_sig: {:?}", src.instance);
let kind = tcx.def_kind(src.def_id());
let is_function = match kind {
- Some(DefKind::Fn)
- | Some(DefKind::Method)
- | Some(DefKind::Ctor(..)) => true,
+ Some(DefKind::Fn) | Some(DefKind::Method) | Some(DefKind::Ctor(..)) => true,
_ => tcx.is_closure(src.def_id()),
};
match (kind, src.promoted) {
(_, Some(i)) => write!(w, "{:?} in ", i)?,
- (Some(DefKind::Const), _)
- | (Some(DefKind::AssocConst), _) => write!(w, "const ")?,
- (Some(DefKind::Static), _) =>
- write!(w, "static {}", if tcx.is_mutable_static(src.def_id()) { "mut " } else { "" })?,
+ (Some(DefKind::Const), _) | (Some(DefKind::AssocConst), _) => write!(w, "const ")?,
+ (Some(DefKind::Static), _) => {
+ write!(w, "static {}", if tcx.is_mutable_static(src.def_id()) { "mut " } else { "" })?
+ }
(_, _) if is_function => write!(w, "fn ")?,
- (None, _) => {}, // things like anon const, not an item
+ (None, _) => {} // things like anon const, not an item
_ => bug!("Unexpected def kind {:?}", kind),
}
}
pub fn dump_mir_def_ids(tcx: TyCtxt<'_>, single: Option<DefId>) -> Vec<DefId> {
- if let Some(i) = single {
- vec![i]
- } else {
- tcx.mir_keys(LOCAL_CRATE).iter().cloned().collect()
- }
+ if let Some(i) = single { vec![i] } else { tcx.mir_keys(LOCAL_CRATE).iter().cloned().collect() }
}