Skip to content

Commit 658c27b

Browse files
committed
Elaborate on comments
1 parent 10f439a commit 658c27b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/librustc_mir/interpret/intern.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
351351
InternKind::Static(hir::Mutability::Mut) => {}
352352
// Once we get heap allocations we need to revisit whether immutable statics can
353353
// 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.
354357
InternKind::Static(hir::Mutability::Not) => {
355358
alloc.mutability = Mutability::Not;
356359
}
@@ -385,6 +388,17 @@ pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
385388
// dangling pointer
386389
throw_unsup!(ValidationFailure("encountered dangling pointer in final constant".into()))
387390
} 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+
388402
// FIXME: check if the allocation is ok as per the interning rules as if we interned
389403
// it right here.
390404
} else {

0 commit comments

Comments
 (0)