How compiler works with uninitialized memory?

That’s right overall, but one thing perhaps worth pointing out is:

Compiler blindly assumes developer always follows rules.

Not entirely blindly.

  • The safe subset of Rust is the subset that the compiler can check reliably, rather than assuming.
  • The compiler also has some checks that apply to unsafe code; they just can’t ever be complete.

Though certainly the LLVM side seems much more blind! I suppose at that point it's a bit late to be issuing diagnostics, and it's pretty bad to be issuing diagnostics that only appear with optimizations thanked ...

Does someone know why tokio casts &mut [MaybeUninit<u8>] to &mut [u8] here?

Because they're using io::Read, which doesn't yet have support for properly writing into an uninitialized buffer. They're assuming that creating a &mut u8 to initialized memory is not immediate UB. (See also.) And if I understand correctly, they're requiring the caller to uphold that the implementation doesn't read the buffer, only write to it.

You should also keep in mind that, for example a debugger can read arbitrary any memory (preferably in the scope of the debugged app) and show it as is. Nothing prevent you to implement the debugger in Rust.

That's outside the Rust AM though, at which point "uninitialized memory" has little to no meaning anymore. When you use MMIO you're effectively doing the same thing.