@@ -361,6 +361,9 @@ pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
361
361
// everything as immutable. Creating a promoted with interior mutability is UB, but
362
362
// there's no way we can check whether the user is using raw pointers correctly.
363
363
// So all we can do is mark this as immutable here.
364
+ // It is UB to mutate through a raw pointer obtained via an immutable reference.
365
+ // Since all references and pointers inside a promoted must by their very definition
366
+ // be created from an immutable reference, mutating though them would be UB.
364
367
InternKind :: Promoted => {
365
368
alloc. mutability = Mutability :: Not ;
366
369
}
@@ -388,19 +391,27 @@ pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
388
391
// dangling pointer
389
392
throw_unsup ! ( ValidationFailure ( "encountered dangling pointer in final constant" . into( ) ) )
390
393
} 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,
394
+ // We have hit an `AllocId` that belongs to an already interned static,
395
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
396
399
397
// E.g. this should be unreachable for `InternKind::Promoted` except for allocations
400
- // created for string and byte string literals.
398
+ // created for string and byte string literals, since these are interned immediately
399
+ // at creation time.
401
400
402
- // FIXME: check if the allocation is ok as per the interning rules as if we interned
403
- // it right here.
401
+ // FIXME(oli-obk): Since we are also checking things during interning,
402
+ // we should probably continue doing those checks no matter what we encounter.
403
+ // So we basically have to check if the allocation is ok as per the interning rules as
404
+ // if we interned it right here.
405
+ // This should be as simple as
406
+ /*
407
+ for &(_, ((), reloc)) in alloc.relocations().iter() {
408
+ if leftover_allocations.insert(reloc) {
409
+ todo.push(reloc);
410
+ }
411
+ }
412
+ */
413
+ // But I (oli-obk) haven't thought about the ramnificatons yet. This also would cause
414
+ // compile-time regressions, so we should think about caching these.
404
415
} else {
405
416
span_bug ! ( ecx. tcx. span, "encountered unknown alloc id {:?}" , alloc_id) ;
406
417
}
0 commit comments