Skip to content

Commit 55840b0

Browse files
committed
Don't repeat the is_const_fn_raw check
1 parent f15197e commit 55840b0

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/librustc_mir/const_eval.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -337,25 +337,23 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
337337
) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>> {
338338
debug!("find_mir_or_eval_fn: {:?}", instance);
339339

340-
// If this function is a `const fn` then as an optimization we can query this
341-
// evaluation immediately.
342-
//
343-
// For the moment we only do this for functions which take no arguments
344-
// (or all arguments are ZSTs) so that we don't memoize too much.
345-
if ecx.tcx.is_const_fn_raw(instance.def.def_id()) &&
346-
args.iter().all(|a| a.layout.is_zst())
347-
{
348-
let gid = GlobalId { instance, promoted: None };
349-
ecx.eval_const_fn_call(gid, ret)?;
350-
return Ok(None);
351-
}
352-
353340
// Only check non-glue functions
354341
if let ty::InstanceDef::Item(def_id) = instance.def {
355342
// Execution might have wandered off into other crates, so we cannot do a stability-
356343
// sensitive check here. But we can at least rule out functions that are not const
357344
// at all.
358-
if !ecx.tcx.is_const_fn_raw(def_id) {
345+
if ecx.tcx.is_const_fn_raw(def_id) {
346+
// If this function is a `const fn` then as an optimization we can query this
347+
// evaluation immediately.
348+
//
349+
// For the moment we only do this for functions which take no arguments
350+
// (or all arguments are ZSTs) so that we don't memoize too much.
351+
if args.iter().all(|a| a.layout.is_zst()) {
352+
let gid = GlobalId { instance, promoted: None };
353+
ecx.eval_const_fn_call(gid, ret)?;
354+
return Ok(None);
355+
}
356+
} else {
359357
// Some functions we support even if they are non-const -- but avoid testing
360358
// that for const fn! We certainly do *not* want to actually call the fn
361359
// though, so be sure we return here.

0 commit comments

Comments
 (0)