@@ -351,6 +351,9 @@ pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
351
351
InternKind :: Static ( hir:: Mutability :: Mut ) => { }
352
352
// Once we get heap allocations we need to revisit whether immutable statics can
353
353
// refer to mutable (e.g. via interior mutability) allocations.
354
+ // Note: this is never the base value of the static, we can only get here for
355
+ // pointers encountered inside the base allocation, and then only for ones not at
356
+ // reference type, as that is checked by the type based main interner.
354
357
InternKind :: Static ( hir:: Mutability :: Not ) => {
355
358
alloc. mutability = Mutability :: Not ;
356
359
}
@@ -385,6 +388,17 @@ pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
385
388
// dangling pointer
386
389
throw_unsup ! ( ValidationFailure ( "encountered dangling pointer in final constant" . into( ) ) )
387
390
} else if let Some ( _) = ecx. tcx . alloc_map . lock ( ) . get ( alloc_id) {
391
+ // If we encounter an `AllocId` that points to a mutable `Allocation`,
392
+ // (directly or via relocations in its `Allocation`), we should panic,
393
+ // the static rules should prevent this.
394
+ // We may hit an `AllocId` that belongs to an already interned static,
395
+ // and are thus not interning any further.
396
+ // But since we are also checking things during interning,
397
+ // we should probably continue doing those checks no matter what we encounter.
398
+
399
+ // E.g. this should be unreachable for `InternKind::Promoted` except for allocations
400
+ // created for string and byte string literals.
401
+
388
402
// FIXME: check if the allocation is ok as per the interning rules as if we interned
389
403
// it right here.
390
404
} else {
0 commit comments