Skip to content

Commit c4c51be

Browse files
committed
first test const-ness, then hook fn call
1 parent 5afd663 commit c4c51be

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/librustc_mir/const_eval.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,13 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeEvaluator {
246246
ret: Option<mir::BasicBlock>,
247247
) -> EvalResult<'tcx, Option<&'mir mir::Mir<'tcx>>> {
248248
debug!("eval_fn_call: {:?}", instance);
249-
if ecx.hook_fn(instance, args, dest)? {
250-
ecx.goto_block(ret)?; // fully evaluated and done
251-
return Ok(None);
252-
}
253249
if !ecx.tcx.is_const_fn(instance.def_id()) {
250+
// Some functions we support even if they are non-const -- but avoid testing
251+
// that for const fn!
252+
if ecx.hook_fn(instance, args, dest)? {
253+
ecx.goto_block(ret)?; // fully evaluated and done
254+
return Ok(None);
255+
}
254256
return Err(
255257
ConstEvalError::NotConst(format!("calling non-const fn `{}`", instance)).into(),
256258
);

0 commit comments

Comments
 (0)