That is to say, generic functions are not expanded into two seeparate functions by the compiler, am I right? If so, it would be very confusing, after all, I use c++ before.
Generic functions do expand into multiple copies (monomorphization). The difference is the static variable is actually shared between all copied. IIRC basically static variables and free functions can be defined inside functions. But that only to restricts the scope name, otherwise, in every way, they act just like if they were defined outside the function.
This also means, for example, that you cannot use generic parameters from the outer function in the nested static variable or free function
Generic functions generate one function per type, not per use. In this case, the second call uses the same once cell that was initialized on the first call.
The meaning of these scoped items is the same as if the item was declared outside the scope — it is still a static item — except that the item's path name within the module namespace is qualified by the name of the enclosing item, or is private to the enclosing item (in the case of functions).
Location of static item only affects its naming scope. Except for that, it behaves the same as if it were in the module root.