From b6f7eef946d4b9830bef2a4264c4b62f880f032b Mon Sep 17 00:00:00 2001 From: Tunahan Karlibas Date: Fri, 11 Dec 2020 01:59:05 +0300 Subject: [PATCH] Remove unnecessary check and fix local_def_id parameter --- compiler/rustc_mir/src/const_eval/eval_queries.rs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_mir/src/const_eval/eval_queries.rs b/compiler/rustc_mir/src/const_eval/eval_queries.rs index 4d14e45c2e9..058a5ced2ab 100644 --- a/compiler/rustc_mir/src/const_eval/eval_queries.rs +++ b/compiler/rustc_mir/src/const_eval/eval_queries.rs @@ -7,7 +7,7 @@ }; use rustc_errors::ErrorReported; -use rustc_hir::def::DefKind; +use rustc_hir::{ConstContext, def::DefKind}; use rustc_middle::mir; use rustc_middle::mir::interpret::ErrorHandled; use rustc_middle::traits::Reveal; @@ -30,14 +30,14 @@ fn eval_body_using_ecx<'mir, 'tcx>( body: &'mir mir::Body<'tcx>, ) -> InterpResult<'tcx, MPlaceTy<'tcx>> { debug!("eval_body_using_ecx: {:?}, {:?}", cid, ecx.param_env); + let tcx = *ecx.tcx; assert!( cid.promoted.is_some() || matches!( - ecx.tcx.hir().body_const_context(def_id), + ecx.tcx.hir().body_const_context(cid.instance.def_id().expect_local()), Some(ConstContext::Const | ConstContext::Static(_)) ) ); - let tcx = *ecx.tcx; let layout = ecx.layout_of(body.return_ty().subst(tcx, cid.instance.substs))?; assert!(!layout.is_unsized()); let ret = ecx.allocate(layout, MemoryKind::Stack); @@ -47,14 +47,7 @@ fn eval_body_using_ecx<'mir, 'tcx>( let prom = cid.promoted.map_or(String::new(), |p| format!("::promoted[{:?}]", p)); trace!("eval_body_using_ecx: pushing stack frame for global: {}{}", name, prom); - // Assert all args (if any) are zero-sized types; `eval_body_using_ecx` doesn't - // make sense if the body is expecting nontrivial arguments. - // (The alternative would be to use `eval_fn_call` with an args slice.) - for arg in body.args_iter() { - let decl = body.local_decls.get(arg).expect("arg missing from local_decls"); - let layout = ecx.layout_of(decl.ty.subst(tcx, cid.instance.substs))?; - assert!(layout.is_zst()) - } + ecx.push_stack_frame( cid.instance,