Skip to content

Commit 3bcba11

Browse files
committed
reject deallocation of read-only allocations
1 parent 6e92fb4 commit 3bcba11

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

compiler/rustc_mir/src/interpret/memory.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
321321
}
322322
};
323323

324+
if alloc.mutability == Mutability::Not {
325+
throw_ub_format!("deallocating immutable allocation {}", ptr.alloc_id);
326+
}
324327
if alloc_kind != kind {
325328
throw_ub_format!(
326329
"deallocating {}, which is {} memory, using {} deallocation operation",

0 commit comments

Comments
 (0)