EDIT: This is about modifying code in memory; the article is actually more about modifying the executable file on disk — oops (:
----
One example:
My understanding is that static initialization in C/C++ is sometimes done with self-modifying code.
Eg:
ExpensiveObject &getInstance() {
static ExpensiveObject obj;
return obj;
}
So, the first time through, the generated assembly would run some "if object is not initialized, run the constructor" conditional code. Then, it would rewrite itself to not do that check for subsequent calls.
Obviously, that's all in the "hidden behind the scenes" generated assembly code, and the rust compiler could pull similar tricks, but you might also want to allow client code to do such things, for extreme performance cases.