Skip to content

Commit

Permalink
fix node classification
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Feb 9, 2019
1 parent 27ce224 commit 84d75db
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
7 changes: 2 additions & 5 deletions src/librustc/hir/map/mod.rs
Expand Up @@ -371,14 +371,11 @@ impl<'hir> Map<'hir> {
let def_id = self.local_def_id(variant.node.data.id());
Some(Def::Variant(def_id))
}
Node::AnonConst(item) => {
let def_id = self.local_def_id(item.id);
Some(Def::Const(def_id))
}
Node::StructCtor(variant) => {
let def_id = self.local_def_id(variant.id());
Some(Def::Fn(def_id))
Some(Def::StructCtor(def_id, def::CtorKind::from_hir(variant)))
}
Node::AnonConst(_) |
Node::Field(_) |
Node::Expr(_) |
Node::Stmt(_) |
Expand Down
27 changes: 17 additions & 10 deletions src/librustc_mir/util/pretty.rs
Expand Up @@ -595,23 +595,28 @@ fn write_mir_sig(
use rustc::hir::def::Def;

trace!("write_mir_sig: {:?}", src.instance);
let descr = tcx.describe_def(src.def_id()).unwrap();
let descr = tcx.describe_def(src.def_id());
match (descr, src.promoted) {
(_, Some(i)) => write!(w, "{:?} in", i)?,
(Def::Fn(_), _) | (Def::Method(_), _) => 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")?,
(_, Some(i)) => write!(w, "{:?} in ", i)?,
(Some(Def::Fn(_)), _) | (Some(Def::Method(_)), _) => write!(w, "fn ")?,
(Some(Def::StructCtor(..)), _) => write!(w, "struct ")?,
(Some(Def::Const(_)), _) => write!(w, "const ")?,
(Some(Def::Static(_, /*is_mutbl*/false)), _) => write!(w, "static ")?,
(Some(Def::Static(_, /*is_mutbl*/true)), _) => write!(w, "static mut ")?,
(None, _) => {}, // things like anon const, not an item
_ => bug!("Unexpected def description {:?}", descr),
}

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

match (descr, src.promoted) {
(Def::Fn(_), None) | (Def::Method(_), None) => {
(Some(Def::Fn(_)), None) |
(Some(Def::Method(_)), None) |
(Some(Def::StructCtor(..)), None) =>
{
write!(w, "(")?;

// fn argument types.
Expand All @@ -624,18 +629,20 @@ fn write_mir_sig(

write!(w, ") -> {}", mir.return_ty())?;
}
(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 {
writeln!(w)?;
writeln!(w, "yields {}", yield_ty)?;
}

write!(w, " ")?;
// Next thing that gets printed is the opening {

Ok(())
}

Expand Down

0 comments on commit 84d75db

Please sign in to comment.