-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Cloning &str
s doesn't trigger borrow checker
#19704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Comments
Changing "hi" to a longer string leads to varying results (I guess it's allocating different-sized Strings in different areas, which sounds logical) |
More minimal MWE: fn main() {
let y = {
// "hello world" allocated
"hello world".to_string().as_slice().clone()
// "hello world" deallocated
};
// new string allocated in same spot
let z = "something".to_string();
println!("{}", y)
// prints "somethingld"
} I suspect results may vary depending on your system, but fiddling with the string length works. |
Looks like a dup of #19261 |
Seems correct. |
lnicola
pushed a commit
to lnicola/rust
that referenced
this issue
May 5, 2025
Add expression fill mode variant for filling with underscore expressions
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
MWE:
The last thing it prints out should be "hi". Instead it prints out "99" -- it it looks like the
String
x is deallocated in the match, but the pointer to the freed memory lives on.The text was updated successfully, but these errors were encountered: