Note this is not the only promotion in Rust: even code like let x = &"abc".to_owned();works, even though "abc".to_owned() is not a constant expression and cannot be promoted into a constant. Or let x = &mut 0;, since constant promotion does not work with mutable references (rightfully). What takes place here is temporary lifetime extension, and the compiler extends the lifetime of the temporary to the whole block, like you wrote:
let__temp="abc".to_owned();letx=&__temp;dbg!(x);
Another static promotion, even preceding the static promotion RFC, is empty array static promotion: you can do &mut [], even though you cannot do that for any other type, including ZSTs (let x: &'static mut () = &mut (); is an error, but let x: &'static mut [i32; 0] = &mut [] compiles).
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Note this is not the only promotion in Rust: even code like
let x = &"abc".to_owned();
works, even though"abc".to_owned()
is not a constant expression and cannot be promoted into a constant. Orlet x = &mut 0;
, since constant promotion does not work with mutable references (rightfully). What takes place here is temporary lifetime extension, and the compiler extends the lifetime of the temporary to the whole block, like you wrote:Another static promotion, even preceding the static promotion RFC, is empty array static promotion: you can do
&mut []
, even though you cannot do that for any other type, including ZSTs (let x: &'static mut () = &mut ();
is an error, butlet x: &'static mut [i32; 0] = &mut []
compiles).