about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Schneider <github35764891676564198441@oli-obk.de>2018-08-31 14:30:59 +0200
committerOliver Scherer <github35764891676564198441@oli-obk.de>2018-10-25 16:47:35 +0200
commitb4ee38ede3d6a3418103336cecdb8bd08db8e5ab (patch)
tree1506e1c7197a45ba39032dd200c2fc50feabd500
parent73e2b4662d32f517f8cb874e45f48c2a05a81456 (diff)
downloadrust-b4ee38ede3d6a3418103336cecdb8bd08db8e5ab.tar.gz
rust-b4ee38ede3d6a3418103336cecdb8bd08db8e5ab.zip
Don't extend `hir::Def` when there's already a dedicated "function-like" detector
-rw-r--r--src/librustc/hir/def.rs3
-rw-r--r--src/librustc/hir/map/blocks.rs2
-rw-r--r--src/librustc/hir/map/mod.rs7
-rw-r--r--src/librustc/ich/impls_hir.rs1
-rw-r--r--src/librustc_mir/transform/const_prop.rs27
-rw-r--r--src/librustc_save_analysis/lib.rs1
6 files changed, 18 insertions, 23 deletions
diff --git a/src/librustc/hir/def.rs b/src/librustc/hir/def.rs
index 72a45ebd8e4..5d9d4deb0ab 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 69706aabcb0..1ab1c7d3fc5 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 d36268cfe3a..f5f9bcd3b5e 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 4b64591029c..a48bd4eeb09 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 6da40aa4a11..6291d8cc80c 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 cdd25b8aa7a..4b43a1a6270 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(..) |