-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-type-systemArea: Type systemArea: Type system
Description
MWE:
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.
Metadata
Metadata
Assignees
Labels
A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-type-systemArea: Type systemArea: Type system
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
Manishearth commentedon Dec 10, 2014
Changing "hi" to a longer string leads to varying results (I guess it's allocating different-sized Strings in different areas, which sounds logical)
pcwalton commentedon Dec 10, 2014
cc @nikomatsakis
Manishearth commentedon Dec 10, 2014
More minimal MWE:
I suspect results may vary depending on your system, but fiddling with the string length works.
sfackler commentedon Dec 10, 2014
Looks like a dup of #19261
Manishearth commentedon Dec 10, 2014
Seems correct.
Merge pull request rust-lang#19704 from Veykril/push-wrvznvvpvtvp