about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2019-02-02 16:59:20 +0100
committerRalf Jung <post@ralfj.de>2019-02-09 12:11:12 +0100
commit276219e0e2ead9dfbe38c4f80ce53f078d25cd63 (patch)
treea5643493c5beaccabd24d3e272cb76bb732be6f3
parentf5bbcf3818285abd253930554da90fc97cba3690 (diff)
downloadrust-276219e0e2ead9dfbe38c4f80ce53f078d25cd63.tar.gz
rust-276219e0e2ead9dfbe38c4f80ce53f078d25cd63.zip
fix dumping MIR from another crate
-rw-r--r--src/librustc_mir/util/pretty.rs29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs
index 2e1fc756833..bef880ad386 100644
--- a/src/librustc_mir/util/pretty.rs
+++ b/src/librustc_mir/util/pretty.rs
@@ -1,4 +1,3 @@
-use rustc::hir;
 use rustc::hir::def_id::{DefId, LOCAL_CRATE};
 use rustc::mir::*;
 use rustc::mir::visit::Visitor;
@@ -184,7 +183,7 @@ fn dump_path(
     let mut file_path = PathBuf::new();
     file_path.push(Path::new(&tcx.sess.opts.debugging_opts.dump_mir_dir));
 
-    let item_name = tcx.hir()
+    let item_name = tcx
         .def_path(source.def_id)
         .to_filename_friendly_no_crate();
 
@@ -574,15 +573,17 @@ fn write_mir_sig(
     mir: &Mir<'_>,
     w: &mut dyn Write,
 ) -> io::Result<()> {
-    let id = tcx.hir().as_local_node_id(src.def_id).unwrap();
-    let body_owner_kind = tcx.hir().body_owner_kind(id);
-    match (body_owner_kind, src.promoted) {
+    use rustc::hir::def::Def;
+
+    debug!("write_mir_sig: {:?}", src.def_id);
+    let descr = tcx.describe_def(src.def_id).unwrap();
+    match (descr, src.promoted) {
         (_, Some(i)) => write!(w, "{:?} in", i)?,
-        (hir::BodyOwnerKind::Closure, _) |
-        (hir::BodyOwnerKind::Fn, _) => write!(w, "fn")?,
-        (hir::BodyOwnerKind::Const, _) => write!(w, "const")?,
-        (hir::BodyOwnerKind::Static(hir::MutImmutable), _) => write!(w, "static")?,
-        (hir::BodyOwnerKind::Static(hir::MutMutable), _) => write!(w, "static mut")?,
+        (Def::Fn(_), _) => write!(w, "fn")?,
+        (Def::Const(_), _) => write!(w, "const")?,
+        (Def::Static(_, /*is_mutbl*/false), _) => write!(w, "static")?,
+        (Def::Static(_, /*is_mutbl*/true), _) => write!(w, "static mut")?,
+        _ => bug!("Unexpected def description {:?}", descr),
     }
 
     item_path::with_forced_impl_filename_line(|| {
@@ -590,9 +591,8 @@ fn write_mir_sig(
         write!(w, " {}", tcx.item_path_str(src.def_id))
     })?;
 
-    match (body_owner_kind, src.promoted) {
-        (hir::BodyOwnerKind::Closure, None) |
-        (hir::BodyOwnerKind::Fn, None) => {
+    match (descr, src.promoted) {
+        (Def::Fn(_), None) => {
             write!(w, "(")?;
 
             // fn argument types.
@@ -605,10 +605,11 @@ fn write_mir_sig(
 
             write!(w, ") -> {}", mir.return_ty())?;
         }
-        (hir::BodyOwnerKind::Const, _) | (hir::BodyOwnerKind::Static(_), _) | (_, Some(_)) => {
+        (Def::Const(_), _) | (Def::Static(_, _), _) | (_, Some(_)) => {
             assert_eq!(mir.arg_count, 0);
             write!(w, ": {} =", mir.return_ty())?;
         }
+        _ => bug!("Unexpected def description {:?}", descr),
     }
 
     if let Some(yield_ty) = mir.yield_ty {