diff --git a/src/librustc_trans/common.rs b/src/librustc_trans/common.rs index a0fac9cc6599e..df70a6e81166b 100644 --- a/src/librustc_trans/common.rs +++ b/src/librustc_trans/common.rs @@ -18,6 +18,7 @@ use llvm::{ValueRef, BasicBlockRef, BuilderRef, ContextRef, TypeKind}; use llvm::{True, False, Bool, OperandBundleDef}; use rustc::hir::def::Def; use rustc::hir::def_id::DefId; +use rustc::hir::map::DefPathData; use rustc::infer::TransNormalize; use rustc::mir::Mir; use rustc::util::common::MemoizationMap; @@ -1100,3 +1101,7 @@ pub fn ty_fn_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, _ => bug!("unexpected type {:?} to ty_fn_sig", ty) } } + +pub fn is_closure(tcx: TyCtxt, def_id: DefId) -> bool { + tcx.def_key(def_id).disambiguated_data.data == DefPathData::ClosureExpr +} diff --git a/src/librustc_trans/trans_item.rs b/src/librustc_trans/trans_item.rs index 94a68de7f8670..7fa59127704dc 100644 --- a/src/librustc_trans/trans_item.rs +++ b/src/librustc_trans/trans_item.rs @@ -18,6 +18,7 @@ use attributes; use base; use consts; use context::{CrateContext, SharedCrateContext}; +use common; use declare; use glue::DropGlueKind; use llvm; @@ -245,6 +246,7 @@ impl<'a, 'tcx> TransItem<'tcx> { TransItem::Fn(ref instance) => { !instance.def.is_local() || instance.substs.types().next().is_some() || + common::is_closure(tcx, instance.def) || attr::requests_inline(&tcx.get_attrs(instance.def)[..]) } TransItem::DropGlue(..) => true,