From 3bcba11c353c15f3e8d95d330cb1fa98bacc652d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 23 May 2021 11:53:23 +0200 Subject: [PATCH] reject deallocation of read-only allocations --- compiler/rustc_mir/src/interpret/memory.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/rustc_mir/src/interpret/memory.rs b/compiler/rustc_mir/src/interpret/memory.rs index d45ea352028c..c20607b39a16 100644 --- a/compiler/rustc_mir/src/interpret/memory.rs +++ b/compiler/rustc_mir/src/interpret/memory.rs @@ -321,6 +321,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { } }; + if alloc.mutability == Mutability::Not { + throw_ub_format!("deallocating immutable allocation {}", ptr.alloc_id); + } if alloc_kind != kind { throw_ub_format!( "deallocating {}, which is {} memory, using {} deallocation operation",