How the compiler can prove that memory safety?

It also has to do with the scope & lifetime of the memory in use here.

As a global variable in the first example, theoretically multiple concurrent use of the same variables can happen to the same object in memory.

In the second example, it is a local variable to a function so only the given function call has access to that object in memory (even if multiple calls happen concurrently - each call has its own instance), and that the inout references to different properties of said object are completely isolated.