diff options
| author | Michael Woerister <michaelwoerister@posteo> | 2017-07-20 14:10:50 +0200 |
|---|---|---|
| committer | Michael Woerister <michaelwoerister@posteo> | 2017-07-20 22:10:36 +0200 |
| commit | f6e5416a2f98685870ca6912beea42c00a446802 (patch) | |
| tree | 65fa7b6eb0c917b51eec570790f21f1835bec1d6 /src | |
| parent | 226bc92b646f905f43b8cab0d89e681709be9ede (diff) | |
| download | rust-f6e5416a2f98685870ca6912beea42c00a446802.tar.gz rust-f6e5416a2f98685870ca6912beea42c00a446802.zip | |
trans: Make the collector search const fn invocations.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_trans/collector.rs | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/librustc_trans/collector.rs b/src/librustc_trans/collector.rs index 6a573b76eec..b31295f4022 100644 --- a/src/librustc_trans/collector.rs +++ b/src/librustc_trans/collector.rs @@ -594,14 +594,25 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { match *kind { mir::TerminatorKind::Call { ref func, .. } => { let callee_ty = func.ty(self.mir, tcx); + let callee_ty = tcx.trans_apply_param_substs(self.param_substs, &callee_ty); - let skip_const = self.const_context && match callee_ty.sty { - ty::TyFnDef(def_id, _) => self.scx.tcx().is_const_fn(def_id), - _ => false + let constness = match (self.const_context, &callee_ty.sty) { + (true, &ty::TyFnDef(def_id, substs)) if self.scx.tcx().is_const_fn(def_id) => { + let instance = monomorphize::resolve(self.scx, def_id, substs); + Some(instance) + } + _ => None }; - if !skip_const { - let callee_ty = tcx.trans_apply_param_substs(self.param_substs, &callee_ty); + if let Some(const_fn_instance) = constness { + // If this is a const fn, called from a const context, we + // have to visit its body in order to find any fn reifications + // it might contain. + collect_neighbours(self.scx, + const_fn_instance, + true, + self.output); + } else { visit_fn_use(self.scx, callee_ty, true, &mut self.output); } } |
