Open ghost opened 5 years ago
This should be documented here: https://ziglang.org/documentation/master/#Pointers-to-Zero-Bit-Types
Types that have only 1 possible value have no address, and pointers to them are zero bit types themselves. Implicitly casting a value which has only 1 possible value to a mutable pointer of it is allowed since it's safe and has an obvious result.
I don't remember the motivation for this, but it's not just academic - there was something that implementing this solved and made cleaner in the compiler.
Ok. It does seem really particular that this is the only situation where incompatible-seeming types are allowed to coerce. *EmptyStruct
to EmptyStruct
doesn't compile, neither does any combination of two different structs (e.g. EmptyStruct
to *AnotherEmptyStruct
), nor a struct and another zero-bit type like u0
.
I'm not sure this is a bug. It's probably harmless, but it seems wrong.
If the struct has fields, it is an error.