-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Description
This code compiles and runs but seems to allow a use-after-free:
struct Foo {
x: int
}
impl Drop for Foo {
fn drop(&mut self) {
println!("drop {}", self.x);
}
}
fn main() {
let mut ptr = ~Foo { x: 0 };
let test = |foo: &Foo| {
println!("access {}", foo.x);
ptr = ~Foo { x: ptr.x + 1 };
println!("access {}", foo.x);
};
test(ptr);
}
The output is:
access 0
drop 0
access 0
drop 1
This is with rustc 0.8. It may be related to #9853 but I'm not sure.
Metadata
Metadata
Assignees
Labels
A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.