title: Rust lifetime and calling member function
body: <p>I have a question about lifetime of varable in Rust programming language.</p>
  
  <p><code>createTest</code> function creates and returns r-value reference. and when it returns a reference, <code>testValue</code> is destroyed. But test.print() doesn't lead to crash. Why?</p>
  
  <p>(Is Test::print function called as static function?)</p>
  
  <p><strong>Code</strong></p>
  
  <pre class="lang-rust prettyprint-override"><code>struct Test;                                                         
  impl Drop for Test {                                                       
    fn drop (&amp;mut self) {                                                    
      println("Dropped.");                                                   
    }                                                                        
  }                                                                          
  
  impl Test {                                                                
    fn print(&amp;self) { println!("Print!"); }                                  
  }                                                                          
  
  fn createTest() -&gt; &amp;Test {                                                 
    let testValue = &amp;Test;                                                   
    return testValue;                                                        
  }                                                                          
  
  fn main() {                                                                
    let test = createTest();                                             
    test.print();                                                            
    println("Test");                                                         
  }
  </code></pre>
  
  <p><strong>Result</strong></p>
  
  <pre><code>Dropped.
  Print!
  Test
  </code></pre>