std: deprecate some incorrect default initializations

In favour of newly-added decls, which can be used via decl literals.
This commit is contained in:
mlugg
2024-08-31 02:50:11 +01:00
parent 6e3e23a941
commit 0b9fccf508
4 changed files with 36 additions and 0 deletions

View File

@@ -618,6 +618,8 @@ pub fn ArrayListUnmanaged(comptime T: type) type {
/// Functions that potentially allocate memory accept an `Allocator` parameter.
/// Initialize directly or with `initCapacity`, and deinitialize with `deinit`
/// or use `toOwnedSlice`.
///
/// Default initialization of this struct is deprecated; use `.empty` instead.
pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) type {
if (alignment) |a| {
if (a == @alignOf(T)) {
@@ -638,6 +640,12 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
/// additional memory.
capacity: usize = 0,
/// An ArrayList containing no elements.
pub const empty: Self = .{
.items = &.{},
.capacity = 0,
};
pub const Slice = if (alignment) |a| ([]align(a) T) else []T;
pub fn SentinelSlice(comptime s: T) type {