Description
I asked stackoverflow about lifetime of variable. Original link is this : http://stackoverflow.com/questions/21226942/rust-lifetime-and-calling-member-function
** Question from link **
I have a question about lifetime of varable in Rust programming language.
createTest
function creates and returns r-value reference. and when it returns a reference, testValue
is destroyed. But test.print() doesn't lead to crash. Why?
(Is Test::print function called as static function?)
Code
struct Test;
impl Drop for Test {
fn drop (&mut self) {
println("Dropped.");
}
}
impl Test {
fn print(&self) { println!("Print!"); }
}
fn createTest() -> &Test {
let testValue = &Test;
return testValue;
}
fn main() {
let test = createTest();
test.print();
println("Test");
}
Result
Dropped.
Print!
Test
It happened with empty struct only. Is it a really bug?