@@ -360,18 +360,18 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter {
360
360
} else {
361
361
// Read access. These are usually allowed, with some exceptions.
362
362
if memory_extra. can_access_statics {
363
- // This is allowed to read from anything.
363
+ // Machine configuration allows us read from anything (e.g., `static` initializer) .
364
364
Ok ( ( ) )
365
- } else if allocation. mutability == Mutability :: Mut || static_def_id. is_some ( ) {
366
- // This is a potentially dangerous read.
367
- // We *must* error on any access to a mutable global here, as the content of
368
- // this allocation may be different now and at run-time, so if we permit reading
369
- // now we might return the wrong value.
370
- // We conservatively also reject all statics here, but that could be relaxed
371
- // in the future.
365
+ } else if static_def_id. is_some ( ) {
366
+ // Machine configuration does not allow us to read statics
367
+ // (e.g., `const` initializer).
372
368
Err ( ConstEvalErrKind :: ConstAccessesStatic . into ( ) )
373
369
} else {
374
370
// Immutable global, this read is fine.
371
+ // But make sure we never accept a read from something mutable, that would be
372
+ // unsound. The reason is that as the content of this allocation may be different
373
+ // now and at run-time, so if we permit reading now we might return the wrong value.
374
+ assert_eq ! ( allocation. mutability, Mutability :: Not ) ;
375
375
Ok ( ( ) )
376
376
}
377
377
}
0 commit comments