From f3544a707941269ec3ed9145ee1432df5a01a10a Mon Sep 17 00:00:00 2001 From: Robbie Lyman Date: Mon, 22 Jun 2026 08:49:46 -0400 Subject: [PATCH] fix: Allocator contract should allow free on single-pointer-to-array Currently, when calling `free` a slice created by slicing a pointer with comptime-known start and end, a compile-time assertion is hit, because the slicing results in `*[len]T` rather than the expected `[]T`. This commit allows `Allocator.free` to be called on such pointers as well. closes #35712 --- lib/std/mem/Allocator.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/std/mem/Allocator.zig b/lib/std/mem/Allocator.zig index bd9cde09d57383eb3d0f1ebde234c8239dc58ed1..80341ecc2fa30523ef26bf7f1f68087fea18b925 100644 --- a/lib/std/mem/Allocator.zig +++ b/lib/std/mem/Allocator.zig @@ -445,7 +445,10 @@ pub fn reallocAdvanced( /// To free a single item, see `destroy`. pub fn free(self: Allocator, memory: anytype) void { const slice_info = @typeInfo(@TypeOf(memory)).pointer; - comptime assert(slice_info.size == .slice); + if (slice_info.size != .slice) { + // slicing with comptime-known start and end results in *[len]T, which may be free'd + comptime assert(slice_info.size == .one and @typeInfo(slice_info.child) == .array); + } const bytes: []u8 = @ptrCast(@constCast(mem.absorbSentinel(memory))); if (bytes.len == 0) return; @memset(bytes, undefined); -- 2.54.0