[rust-dev] RFC: string literals as &static.str

Patrick Walton pwalton at mozilla.com
Sat Jul 28 19:38:57 PDT 2012

Hi everyone,

Currently, string literals have type str/_; e.g. "foo" has type str/3. 
This means that string literals are stored on the stack and are 
constructed anew for every function invocation with a series of mov 

While this is very occasionally useful, and it mirrors how vectors work, 
I suspect that 99% of string literals are actually intended to be stored 
in constant memory. The current behavior is a burden and an aesthetic 
problem, since in order to achieve the desired behavior, 99% of string 
literals will need to be prefixed with & or ~; e.g. println(&"Hello world!")

I'd like to propose that unadorned string literals instead have the type 
&static.str, which mirrors how it (usually) works in C and C++. To get 
the current behavior one would write "Hello world"/_. This is slightly 
inconsistent with vectors, but string literals are special anyway in C 
and C++. This will make almost all the ~" punctuation-diphthongs that 
are peppered throughout Rust code go away.



More information about the Rust-dev mailing list