Slice type coercion

  1. This is roughly the definition of a subtype: every possible value of type A is still valid under the semantics of type B, so it’s okay to coerce from A to B.
    Subtypes allow information loss. E.g., losing mutability information when coercing from *T to *const T. Losing actual alignment information when coercing from *align(64) T to *align(1) T. Losing the actual range of values when coercing from u32 to u64.

But I agree, allowing a coercion from []T to [*]T is a bit far-fetched and unnecessary. slice.ptr feels more explicit and better to me, and I’ve actually never used this coercion, so I wouldn’t mind if it were removed.

  1. Comptime []T is considered equivalent to [N]T, #35328 might help a bit in understanding this. The post I recently discussed about [_]T also happens to mention the use of slices at comptime, which might eventually be used to completely replace the [_]T syntax.
2 Likes