diff --git a/src/librustc/hir/def.rs b/src/librustc/hir/def.rs index 72a45ebd8e4c..5d9d4deb0abc 100644 --- a/src/librustc/hir/def.rs +++ b/src/librustc/hir/def.rs @@ -74,7 +74,6 @@ pub enum Def { SelfCtor(DefId /* impl */), // DefId refers to the impl Method(DefId), AssociatedConst(DefId), - Closure(hir::BodyId), Local(ast::NodeId), Upvar(ast::NodeId, // node id of closed over local @@ -282,7 +281,6 @@ impl Def { id } - Def::Closure(_) | Def::Local(..) | Def::Upvar(..) | Def::Label(..) | @@ -321,7 +319,6 @@ impl Def { Def::Trait(..) => "trait", Def::ForeignTy(..) => "foreign type", Def::Method(..) => "method", - Def::Closure(_) => "closure", Def::Const(..) => "constant", Def::AssociatedConst(..) => "associated constant", Def::TyParam(..) => "type parameter", diff --git a/src/librustc/hir/map/blocks.rs b/src/librustc/hir/map/blocks.rs index 69706aabcb05..1ab1c7d3fc5c 100644 --- a/src/librustc/hir/map/blocks.rs +++ b/src/librustc/hir/map/blocks.rs @@ -43,7 +43,7 @@ pub struct FnLikeNode<'a> { node: Node<'a> } /// MaybeFnLike wraps a method that indicates if an object /// corresponds to some FnLikeNode. -pub trait MaybeFnLike { fn is_fn_like(&self) -> bool; } +trait MaybeFnLike { fn is_fn_like(&self) -> bool; } impl MaybeFnLike for ast::Item { fn is_fn_like(&self) -> bool { diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index d36268cfe3a4..f5f9bcd3b5ea 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -340,14 +340,9 @@ impl<'hir> Map<'hir> { let def_id = self.local_def_id(variant.node.data.id()); Some(Def::Variant(def_id)) } - Node::Expr(expr) => { - match expr.node { - ExprKind::Closure(_, _, body_id, _, _) => Some(Def::Closure(body_id)), - _ => None, - } - } Node::Field(_) | Node::AnonConst(_) | + Node::Expr(_) | Node::Stmt(_) | Node::Ty(_) | Node::TraitRef(_) | diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 4b64591029c3..a48bd4eeb09a 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -1044,7 +1044,6 @@ impl_stable_hash_for!(enum hir::def::Def { SelfCtor(impl_def_id), VariantCtor(def_id, ctor_kind), Method(def_id), - Closure(body_id), AssociatedConst(def_id), Local(def_id), Upvar(def_id, index, expr_id), diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 6da40aa4a116..6291d8cc80cb 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -44,19 +44,24 @@ impl MirPass for ConstProp { if source.promoted.is_some() { return; } - match tcx.describe_def(source.def_id) { - // Only run const prop on functions, methods, closures and associated constants - | Some(Def::Fn(_)) - | Some(Def::Method(_)) - | Some(Def::AssociatedConst(_)) - | Some(Def::Closure(_)) - => {} + + use rustc::hir::map::blocks::FnLikeNode; + let node_id = tcx.hir.as_local_node_id(source.def_id) + .expect("Non-local call to local provider is_const_fn"); + + let is_fn_like = FnLikeNode::from_node(tcx.hir.get(node_id)).is_some(); + let is_assoc_const = match tcx.describe_def(source.def_id) { + Some(Def::AssociatedConst(_)) => true, + _ => false, + }; + + // Only run const prop on functions, methods, closures and associated constants + if !is_fn_like && !is_assoc_const { // skip anon_const/statics/consts because they'll be evaluated by miri anyway - def => { - trace!("ConstProp skipped for {:?} ({:?})", source.def_id, def); - return - }, + trace!("ConstProp skipped for {:?}", source.def_id); + return } + trace!("ConstProp starting for {:?}", source.def_id); // FIXME(oli-obk, eddyb) Optimize locals (or even local paths) to hold diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index cdd25b8aa7ac..4b43a1a6270f 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -827,7 +827,6 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { ref_id: id_from_def_id(def_id), }) } - HirDef::Closure(_) | HirDef::PrimTy(..) | HirDef::SelfTy(..) | HirDef::Label(..) |