Extra assertions in eval_body_using_ecx to disallow queries for

functions that does allocations
This commit is contained in:
Tunahan Karlibas 2020-12-09 14:53:35 +03:00
parent 7cb74ed191
commit de1cd4b36d
No known key found for this signature in database
GPG Key ID: ECC4968DC9D453DE
2 changed files with 7 additions and 1 deletions

View File

@ -132,7 +132,6 @@ pub use self::pointer::{Pointer, PointerArithmetic};
/// Uniquely identifies one of the following:
/// - A constant
/// - A static
/// - A const fn where all arguments (if any) are zero-sized types
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, TyEncodable, TyDecodable)]
#[derive(HashStable, Lift)]
pub struct GlobalId<'tcx> {

View File

@ -30,6 +30,13 @@ 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);
assert!(
cid.promoted.is_some()
|| matches!(
ecx.tcx.hir().body_const_context(def_id),
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());