Skip to content

Commit 276219e

Browse files
committed
fix dumping MIR from another crate
1 parent f5bbcf3 commit 276219e

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/librustc_mir/util/pretty.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc::hir;
21
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
32
use rustc::mir::*;
43
use rustc::mir::visit::Visitor;
@@ -184,7 +183,7 @@ fn dump_path(
184183
let mut file_path = PathBuf::new();
185184
file_path.push(Path::new(&tcx.sess.opts.debugging_opts.dump_mir_dir));
186185

187-
let item_name = tcx.hir()
186+
let item_name = tcx
188187
.def_path(source.def_id)
189188
.to_filename_friendly_no_crate();
190189

@@ -574,25 +573,26 @@ fn write_mir_sig(
574573
mir: &Mir<'_>,
575574
w: &mut dyn Write,
576575
) -> io::Result<()> {
577-
let id = tcx.hir().as_local_node_id(src.def_id).unwrap();
578-
let body_owner_kind = tcx.hir().body_owner_kind(id);
579-
match (body_owner_kind, src.promoted) {
576+
use rustc::hir::def::Def;
577+
578+
debug!("write_mir_sig: {:?}", src.def_id);
579+
let descr = tcx.describe_def(src.def_id).unwrap();
580+
match (descr, src.promoted) {
580581
(_, Some(i)) => write!(w, "{:?} in", i)?,
581-
(hir::BodyOwnerKind::Closure, _) |
582-
(hir::BodyOwnerKind::Fn, _) => write!(w, "fn")?,
583-
(hir::BodyOwnerKind::Const, _) => write!(w, "const")?,
584-
(hir::BodyOwnerKind::Static(hir::MutImmutable), _) => write!(w, "static")?,
585-
(hir::BodyOwnerKind::Static(hir::MutMutable), _) => write!(w, "static mut")?,
582+
(Def::Fn(_), _) => write!(w, "fn")?,
583+
(Def::Const(_), _) => write!(w, "const")?,
584+
(Def::Static(_, /*is_mutbl*/false), _) => write!(w, "static")?,
585+
(Def::Static(_, /*is_mutbl*/true), _) => write!(w, "static mut")?,
586+
_ => bug!("Unexpected def description {:?}", descr),
586587
}
587588

588589
item_path::with_forced_impl_filename_line(|| {
589590
// see notes on #41697 elsewhere
590591
write!(w, " {}", tcx.item_path_str(src.def_id))
591592
})?;
592593

593-
match (body_owner_kind, src.promoted) {
594-
(hir::BodyOwnerKind::Closure, None) |
595-
(hir::BodyOwnerKind::Fn, None) => {
594+
match (descr, src.promoted) {
595+
(Def::Fn(_), None) => {
596596
write!(w, "(")?;
597597

598598
// fn argument types.
@@ -605,10 +605,11 @@ fn write_mir_sig(
605605

606606
write!(w, ") -> {}", mir.return_ty())?;
607607
}
608-
(hir::BodyOwnerKind::Const, _) | (hir::BodyOwnerKind::Static(_), _) | (_, Some(_)) => {
608+
(Def::Const(_), _) | (Def::Static(_, _), _) | (_, Some(_)) => {
609609
assert_eq!(mir.arg_count, 0);
610610
write!(w, ": {} =", mir.return_ty())?;
611611
}
612+
_ => bug!("Unexpected def description {:?}", descr),
612613
}
613614

614615
if let Some(yield_ty) = mir.yield_ty {

0 commit comments

Comments
 (0)