But I am uncertain if the correctness of this is always 100% safe as I think it is.
My rationalisation is that since the value of the pointer is never taken, no actual "dereference" occurs, and thus I did not dereference an invalid pointer; I'm not sure if it's valid because of an optimisation (bad) or language semantics (good!).
It can be a macro, doesn’t have to be a function (yes, Rust doesn’t have a way to express this as a generic fn without some stringly API). My main point is this ought to be a builtin, with whatever syntax/expression chosen (separate bikeshed). I mostly wanted to see if any thought had been given to this by core lang team, and if so, what the thinking is.
As it stands, one can rely on LLVM optimizing out the “stack dummy” approach (but maybe it’ll fail to do so under some circumstances), a bit of unsafe code (granted, contained but there should be nothing unsafe about getting this value), but we don’t get const context goodness (as an example).