Skip to content

Commit de1cd4b

Browse files
author
Tunahan Karlibas
committed
Extra assertions in eval_body_using_ecx to disallow queries for
functions that does allocations
1 parent 7cb74ed commit de1cd4b

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

compiler/rustc_middle/src/mir/interpret/mod.rs

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

compiler/rustc_mir/src/const_eval/eval_queries.rs

+7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ fn eval_body_using_ecx<'mir, 'tcx>(
3030
body: &'mir mir::Body<'tcx>,
3131
) -> InterpResult<'tcx, MPlaceTy<'tcx>> {
3232
debug!("eval_body_using_ecx: {:?}, {:?}", cid, ecx.param_env);
33+
assert!(
34+
cid.promoted.is_some()
35+
|| matches!(
36+
ecx.tcx.hir().body_const_context(def_id),
37+
Some(ConstContext::Const | ConstContext::Static(_))
38+
)
39+
);
3340
let tcx = *ecx.tcx;
3441
let layout = ecx.layout_of(body.return_ty().subst(tcx, cid.instance.substs))?;
3542
assert!(!layout.is_unsized());

0 commit comments

Comments
 (0)