mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
get back the more precise error message
This commit is contained in:
parent
f70af91e51
commit
69cf211d06
@ -8,6 +8,7 @@ use std::hash::Hash;
|
||||
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};
|
||||
|
||||
@ -347,11 +348,14 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter {
|
||||
|
||||
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(())
|
||||
|
@ -212,6 +212,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
|
||||
#[inline]
|
||||
fn before_access_global(
|
||||
_memory_extra: &Self::MemoryExtra,
|
||||
_alloc_id: AllocId,
|
||||
_allocation: &Allocation,
|
||||
_def_id: Option<DefId>,
|
||||
_is_write: bool,
|
||||
|
@ -456,7 +456,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
|
||||
(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(
|
||||
|
@ -272,6 +272,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine {
|
||||
|
||||
fn before_access_global(
|
||||
_memory_extra: &(),
|
||||
_alloc_id: AllocId,
|
||||
allocation: &Allocation<Self::PointerTag, Self::AllocExtra>,
|
||||
_def_id: Option<DefId>,
|
||||
is_write: bool,
|
||||
|
@ -11,7 +11,7 @@ LL | / const MUTATING_BEHIND_RAW: () = {
|
||||
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 | | };
|
||||
| |__-
|
||||
|
Loading…
Reference in New Issue
Block a user