Imagine we have the following code:
fn main() {
for _ in 0..10 {
let _ = get_static_ref();
}
}
struct SomeStruct {
value: usize
}
fn get_static_ref() -> &'static SomeStruct {
static MY_STRUCT: SomeStruct = SomeStruct { value: 1 };
&MY_STRUCT
}
Does the MY_STRUCT gets reassigned on every get_static_ref call, or does the compiler just remove this assignment from function body?
Because if it gets reassigned, then it kind of breaks the rule, that non-mut static items are immutable, so it follows that those reassignments shouldn't happen, but that's just my guess.
I was unable to find an explicit explanation for this situation in Rust docs.