UB means that there has been a contract violation with the compiler
No, it means that behavior is not strictly defined and compiler can assume whatever it wants.
Since Rust is not strictly standardized as C or C++ it would be difficult to find definition of UB in Rust, but I doubt that UB would be different from UB in C or C++ (since it uses LLVM)
Whose fault is that? The programmer’s.
Yes, so what?
If programmer used UB then he knew what he wanted
But the code shown above is able to create values of type
Impractical examples are not the best to use.
If value size is 0 then obviously compiler wouldn’t write anything and actually should optimize away usage of such array at all (aside from when it’s side effects are used i.e. looping)
I of course don’t know how compiler behaves with arrays of T where
size_of::<T>() == 0
Nevertheless, it doesn’t I don’t mind deprecated
uninitialized which I use by habit instead of
MaybeUninit, but my point is that UB and unsafe are fine if you know what to do
I’m perfectly well aware of Rust differences when it comes to unsafe.
Not to mention I use Rust since it’s first stable release.
But such common things as uninitialized value is all the same as in C++ (well ok excluding zero sized values)