Skip to content

Instantly share code, notes, and snippets.

@yegor-alexeyev
Created February 22, 2014 12:06
Show Gist options
  • Save yegor-alexeyev/9152969 to your computer and use it in GitHub Desktop.
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
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