You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fn get() -> Option<String> {
Some("hi".to_string())
}
fn main() {
let y = match get() {
Some(x) => x.as_slice().clone(),
None => "hello"
};
let mut z = "something".to_string();
for i in range(1,1000u) {
z = format!("{}", i);
println!("{}", z)
}
println!("{}", y)
}
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:
fnmain(){let y = {// "hello world" allocated"hello world".to_string().as_slice().clone()// "hello world" deallocated};// new string allocated in same spotlet z = "something".to_string();println!("{}", y)// prints "somethingld"}
I suspect results may vary depending on your system, but fiddling with the string length works.
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: