title: Are raw pointers to temporaries ok in Rust?
body: <p>I have a function like this:</p>
  
  <pre><code>extern {
      fn foo(layout: *const RawLayout) -&gt; libc::uint8_t;
  }
  
  fn bar(layout: Layout) -&gt; bool {
      unsafe {
          foo(&amp;layout.into() as *const _) != 0
      }
  }
  </code></pre>
  
  <p>Where <code>Layout</code> is a copyable type that can be converted <code>.into()</code> a <code>RawLayout</code>.</p>
  
  <p>I want to make sure I understand what is happening as it is unsafe. As I understand it, <code>layout.into()</code> creates a temporary <code>RawLayout</code>, then <code>&amp;</code> takes a reference to it, and <code>as *const _</code> converts it to a raw pointer (<code>*const RawLayout</code>). Then the <code>foo()</code> function is called and returns, and finally the temporary <code>RawLayout</code> is dropped.</p>
  
  <p>Is that correct? Or is there some tricky reason why I shouldn't do this?</p>