From 55840b0209a77bcf7884c8818585f792637927c2 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Sat, 30 Nov 2019 18:22:11 +0100 Subject: [PATCH] Don't repeat the `is_const_fn_raw` check --- src/librustc_mir/const_eval.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 133ab31524723..e299d4b164f1b 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -337,25 +337,23 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, ) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>> { debug!("find_mir_or_eval_fn: {:?}", instance); - // If this function is a `const fn` then as an optimization we can query this - // evaluation immediately. - // - // For the moment we only do this for functions which take no arguments - // (or all arguments are ZSTs) so that we don't memoize too much. - if ecx.tcx.is_const_fn_raw(instance.def.def_id()) && - args.iter().all(|a| a.layout.is_zst()) - { - let gid = GlobalId { instance, promoted: None }; - ecx.eval_const_fn_call(gid, ret)?; - return Ok(None); - } - // Only check non-glue functions if let ty::InstanceDef::Item(def_id) = instance.def { // Execution might have wandered off into other crates, so we cannot do a stability- // sensitive check here. But we can at least rule out functions that are not const // at all. - if !ecx.tcx.is_const_fn_raw(def_id) { + if ecx.tcx.is_const_fn_raw(def_id) { + // If this function is a `const fn` then as an optimization we can query this + // evaluation immediately. + // + // For the moment we only do this for functions which take no arguments + // (or all arguments are ZSTs) so that we don't memoize too much. + if args.iter().all(|a| a.layout.is_zst()) { + let gid = GlobalId { instance, promoted: None }; + ecx.eval_const_fn_call(gid, ret)?; + return Ok(None); + } + } else { // Some functions we support even if they are non-const -- but avoid testing // that for const fn! We certainly do *not* want to actually call the fn // though, so be sure we return here.