-
Couldn't load subscription status.
- Fork 13.9k
Closed
Labels
A-collectionsArea: `std::collections`Area: `std::collections`C-bugCategory: This is a bug.Category: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Description
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
Metadata
Metadata
Assignees
Labels
A-collectionsArea: `std::collections`Area: `std::collections`C-bugCategory: This is a bug.Category: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.