Closed
Description
openedon Mar 23, 2020
To my knowledge, the following code is intended to be legal:
fn main() {
let mut buf = String::with_capacity(11);
buf.push_str("hello");
let hello: &str = unsafe { &*(buf.as_str() as *const _) }; // laundering the lifetime -- we take care that `buf` does not reallocate, so that's okay.
buf.push_str(" world");
println!("{}", hello);
}
However, Miri currently flags this as UB.
I believe this is #60847, but for String
. Discovered while writing this post.
cc @RalfJung
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment