use rustc_data_structures::fx::FxHashMap;
use rustc::mir::AssertMessage;
+use rustc_ast::ast::Mutability;
use rustc_span::symbol::Symbol;
use rustc_span::{def_id::DefId, Span};
fn before_access_global(
memory_extra: &MemoryExtra,
- _allocation: &Allocation,
+ alloc_id: AllocId,
+ allocation: &Allocation,
def_id: Option<DefId>,
is_write: bool,
) -> InterpResult<'tcx> {
- if is_write {
+ if is_write && allocation.mutability == Mutability::Not {
+ Err(err_ub!(WriteToReadOnly(alloc_id)).into())
+ } else if is_write {
Err(ConstEvalErrKind::ModifiedGlobal.into())
} else if memory_extra.can_access_statics || def_id.is_none() {
Ok(())
#[inline]
fn before_access_global(
_memory_extra: &Self::MemoryExtra,
+ _alloc_id: AllocId,
_allocation: &Allocation,
_def_id: Option<DefId>,
_is_write: bool,
(allocation, Some(def_id))
}
};
- M::before_access_global(memory_extra, alloc, def_id, is_write)?;
+ M::before_access_global(memory_extra, id, alloc, def_id, is_write)?;
let alloc = Cow::Borrowed(alloc);
// We got tcx memory. Let the machine initialize its "extra" stuff.
let (alloc, tag) = M::init_allocation_extra(
fn before_access_global(
_memory_extra: &(),
+ _alloc_id: AllocId,
allocation: &Allocation<Self::PointerTag, Self::AllocExtra>,
_def_id: Option<DefId>,
is_write: bool,
LL | | // Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time.
LL | | unsafe {
LL | | *MUTABLE_BEHIND_RAW = 99
- | | ^^^^^^^^^^^^^^^^^^^^^^^^ modifying a static's initial value from another static's initializer
+ | | ^^^^^^^^^^^^^^^^^^^^^^^^ writing to alloc1 which is read-only
LL | | }
LL | | };
| |__-