Created
February 22, 2014 12:06
-
-
Save yegor-alexeyev/9152969 to your computer and use it in GitHub Desktop.
It is possible to call object member function after object had been dropped
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait X { | |
fn get_i(&self) -> int; | |
} | |
struct B { | |
i: int | |
} | |
impl X for B { | |
fn get_i(&self) -> int { | |
self.i | |
} | |
} | |
impl Drop for B { | |
fn drop(&mut self) { | |
std::io::stdio::println("drop"); | |
} | |
} | |
struct A<'r> { | |
p: &'r X | |
} | |
fn make_a<'r>(p:&'r X) -> A<'r> { | |
A{p:p} | |
} | |
fn make_make_a() -> A{ | |
let b: ~B = ~B {i:1}; | |
let bb: & B = b; | |
make_a(bb) | |
} | |
fn main() { | |
let a = make_make_a(); | |
let i = a.p.get_i(); | |
std::io::stdio::println(format!("{:d}", i)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment