Skip to content

Commit b4ee38e

Browse files
committed
Don't extend hir::Def when there's already a dedicated "function-like" detector
1 parent 73e2b46 commit b4ee38e

File tree

6 files changed

+18
-23
lines changed

6 files changed

+18
-23
lines changed

src/librustc/hir/def.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ pub enum Def {
7474
SelfCtor(DefId /* impl */), // DefId refers to the impl
7575
Method(DefId),
7676
AssociatedConst(DefId),
77-
Closure(hir::BodyId),
7877

7978
Local(ast::NodeId),
8079
Upvar(ast::NodeId, // node id of closed over local
@@ -282,7 +281,6 @@ impl Def {
282281
id
283282
}
284283

285-
Def::Closure(_) |
286284
Def::Local(..) |
287285
Def::Upvar(..) |
288286
Def::Label(..) |
@@ -321,7 +319,6 @@ impl Def {
321319
Def::Trait(..) => "trait",
322320
Def::ForeignTy(..) => "foreign type",
323321
Def::Method(..) => "method",
324-
Def::Closure(_) => "closure",
325322
Def::Const(..) => "constant",
326323
Def::AssociatedConst(..) => "associated constant",
327324
Def::TyParam(..) => "type parameter",

src/librustc/hir/map/blocks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub struct FnLikeNode<'a> { node: Node<'a> }
4343

4444
/// MaybeFnLike wraps a method that indicates if an object
4545
/// corresponds to some FnLikeNode.
46-
pub trait MaybeFnLike { fn is_fn_like(&self) -> bool; }
46+
trait MaybeFnLike { fn is_fn_like(&self) -> bool; }
4747

4848
impl MaybeFnLike for ast::Item {
4949
fn is_fn_like(&self) -> bool {

src/librustc/hir/map/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,9 @@ impl<'hir> Map<'hir> {
340340
let def_id = self.local_def_id(variant.node.data.id());
341341
Some(Def::Variant(def_id))
342342
}
343-
Node::Expr(expr) => {
344-
match expr.node {
345-
ExprKind::Closure(_, _, body_id, _, _) => Some(Def::Closure(body_id)),
346-
_ => None,
347-
}
348-
}
349343
Node::Field(_) |
350344
Node::AnonConst(_) |
345+
Node::Expr(_) |
351346
Node::Stmt(_) |
352347
Node::Ty(_) |
353348
Node::TraitRef(_) |

src/librustc/ich/impls_hir.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,6 @@ impl_stable_hash_for!(enum hir::def::Def {
10441044
SelfCtor(impl_def_id),
10451045
VariantCtor(def_id, ctor_kind),
10461046
Method(def_id),
1047-
Closure(body_id),
10481047
AssociatedConst(def_id),
10491048
Local(def_id),
10501049
Upvar(def_id, index, expr_id),

src/librustc_mir/transform/const_prop.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,24 @@ impl MirPass for ConstProp {
4444
if source.promoted.is_some() {
4545
return;
4646
}
47-
match tcx.describe_def(source.def_id) {
48-
// Only run const prop on functions, methods, closures and associated constants
49-
| Some(Def::Fn(_))
50-
| Some(Def::Method(_))
51-
| Some(Def::AssociatedConst(_))
52-
| Some(Def::Closure(_))
53-
=> {}
47+
48+
use rustc::hir::map::blocks::FnLikeNode;
49+
let node_id = tcx.hir.as_local_node_id(source.def_id)
50+
.expect("Non-local call to local provider is_const_fn");
51+
52+
let is_fn_like = FnLikeNode::from_node(tcx.hir.get(node_id)).is_some();
53+
let is_assoc_const = match tcx.describe_def(source.def_id) {
54+
Some(Def::AssociatedConst(_)) => true,
55+
_ => false,
56+
};
57+
58+
// Only run const prop on functions, methods, closures and associated constants
59+
if !is_fn_like && !is_assoc_const {
5460
// skip anon_const/statics/consts because they'll be evaluated by miri anyway
55-
def => {
56-
trace!("ConstProp skipped for {:?} ({:?})", source.def_id, def);
57-
return
58-
},
61+
trace!("ConstProp skipped for {:?}", source.def_id);
62+
return
5963
}
64+
6065
trace!("ConstProp starting for {:?}", source.def_id);
6166

6267
// FIXME(oli-obk, eddyb) Optimize locals (or even local paths) to hold

src/librustc_save_analysis/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,6 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
827827
ref_id: id_from_def_id(def_id),
828828
})
829829
}
830-
HirDef::Closure(_) |
831830
HirDef::PrimTy(..) |
832831
HirDef::SelfTy(..) |
833832
HirDef::Label(..) |

0 commit comments

Comments
 (0)