Skip to content

Commit f6e5416

Browse files
trans: Make the collector search const fn invocations.
1 parent 226bc92 commit f6e5416

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/librustc_trans/collector.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -594,14 +594,25 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
594594
match *kind {
595595
mir::TerminatorKind::Call { ref func, .. } => {
596596
let callee_ty = func.ty(self.mir, tcx);
597+
let callee_ty = tcx.trans_apply_param_substs(self.param_substs, &callee_ty);
597598

598-
let skip_const = self.const_context && match callee_ty.sty {
599-
ty::TyFnDef(def_id, _) => self.scx.tcx().is_const_fn(def_id),
600-
_ => false
599+
let constness = match (self.const_context, &callee_ty.sty) {
600+
(true, &ty::TyFnDef(def_id, substs)) if self.scx.tcx().is_const_fn(def_id) => {
601+
let instance = monomorphize::resolve(self.scx, def_id, substs);
602+
Some(instance)
603+
}
604+
_ => None
601605
};
602606

603-
if !skip_const {
604-
let callee_ty = tcx.trans_apply_param_substs(self.param_substs, &callee_ty);
607+
if let Some(const_fn_instance) = constness {
608+
// If this is a const fn, called from a const context, we
609+
// have to visit its body in order to find any fn reifications
610+
// it might contain.
611+
collect_neighbours(self.scx,
612+
const_fn_instance,
613+
true,
614+
self.output);
615+
} else {
605616
visit_fn_use(self.scx, callee_ty, true, &mut self.output);
606617
}
607618
}

0 commit comments

Comments
 (0)