title: Why is the lifetime important for slice::from_raw_parts?
body: <p>The docs for <code>slice::from_raw_parts</code> warn the programmer to annotate the slice with the correct lifetime.  I assume that, given some lifetime <code>'a</code>, I can perform this annotation with </p>
  
  <pre><code>let myslice: &amp;'a mut [i32] = std::slice::from_raw_parts_mut(ptr, sz)
  </code></pre>
  
  <p>I also assume that</p>
  
  <ul>
  <li>Since <code>myslice</code> is a reference, it has nothing to do with the allocation/deallocation of the underlying data pointed to by ptr. The lifetime annotation doesn't affect the memory management of the data.</li>
  <li>There's nothing tricky about memory management for <code>myslice</code> itself (i.e. a struct containing a pointer and a size).  It's just like any other struct or <code>i32</code>.  If I put it in a <code>Box</code>, then the <code>std::raw::slice</code> struct will get deallocated when the <code>Box</code> dies. The data referred to by the slice will not get deallocated, of course.  The lifetime doesn't affect the memory management for the slice.</li>
  </ul>
  
  <p>Why is it important that I get the lifetime correct?  Is use-after-free the only danger to fear when setting the slice lifetime?</p>