@@ -320,12 +320,19 @@ pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
320320 // We can't call the `intern_shallow` method here, as its logic is tailored to safe
321321 // references and a `leftover_allocations` set (where we only have a todo-list here).
322322 // So we hand-roll the interning logic here again.
323- if base_intern_mode != InternMode :: Static {
324- // If it's not a static, it *must* be immutable.
325- // We cannot have mutable memory inside a constant.
326- // FIXME: ideally we would assert that they already are immutable, to double-
327- // check our static checks.
328- alloc. mutability = Mutability :: Not ;
323+ match base_intern_mode {
324+ InternMode :: Static => { }
325+ InternMode :: Const | InternMode :: ConstBase => {
326+ // If it's not a static, it *must* be immutable.
327+ // We cannot have mutable memory inside a constant.
328+ // We use `delay_span_bug` here, because this can be reached in the presence
329+ // of fancy transmutes.
330+ if alloc. mutability == Mutability :: Mut {
331+ // For better errors later, mark the allocation as immutable
332+ alloc. mutability = Mutability :: Not ;
333+ ecx. tcx . sess . delay_span_bug ( ecx. tcx . span , "mutable allocation in constant" ) ;
334+ }
335+ }
329336 }
330337 let alloc = tcx. intern_const_alloc ( alloc) ;
331338 tcx. alloc_map . lock ( ) . set_alloc_id_memory ( alloc_id, alloc) ;
@@ -337,6 +344,8 @@ pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
337344 } else if ecx. memory . dead_alloc_map . contains_key ( & alloc_id) {
338345 // dangling pointer
339346 throw_unsup ! ( ValidationFailure ( "encountered dangling pointer in final constant" . into( ) ) )
347+ } else if ecx. tcx . alloc_map . lock ( ) . get ( alloc_id) . is_none ( ) {
348+ span_bug ! ( ecx. tcx. span, "encountered unknown alloc id {:?}" , alloc_id) ;
340349 }
341350 }
342351 Ok ( ( ) )
0 commit comments