title: Reference does not live long enough in nested structure
body: <p>I'm creating a series of data structures containing mutable references to lower level structures. I've been fairly happily working with <code>A</code>, <code>B</code>, and <code>C</code> below but I've attempted to add a new layer <code>D</code>. <code>A</code>, <code>B</code>, <code>C</code>, <code>D</code> are actually the states of a state machine for protocol decoding, but I've deleted all of that here:</p>
  
  <pre><code>struct A {}
  
  fn init_A() -&gt; A {
      A {}
  }
  
  struct B&lt;'l&gt; {
      ed: &amp;'l mut A,
  }
  
  fn init_B(mut e: &amp;mut A) -&gt; B {
      B { ed: e }
  }
  
  struct C&lt;'l&gt; {
      pd: &amp;'l mut B&lt;'l&gt;,
  }
  
  fn init_C&lt;'l&gt;(mut p: &amp;'l mut B&lt;'l&gt;) -&gt; C&lt;'l&gt; {
      C { pd: p }
  }
  
  struct D&lt;'lifetime&gt; {
      sd: &amp;'lifetime mut C&lt;'lifetime&gt;,
  }
  
  fn init_D&lt;'l&gt;(mut p: &amp;'l mut C&lt;'l&gt;) -&gt; D&lt;'l&gt; {
      D { sd: p }
  }
  
  fn main() {
      let mut a = init_A();
      let mut b = init_B(&amp;mut a);
      let mut c = init_C(&amp;mut b);
  
      // COMMENT OUT THE BELOW LINE FOR SUCCESSFUL COMPILE
      let mut d = init_D(&amp;mut c);
  }
  </code></pre>
  
  <p>I get an error:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0597]: `c` does not live long enough
    --&gt; src/main.rs:38:1
     |
  37 |     let mut d = init_D(&amp;mut c);
     |                             - borrow occurs here
  38 | }
     | ^ `c` dropped here while still borrowed
     |
     = note: values in a scope are dropped in the opposite order they are created
  </code></pre>
  
  <p>I'm completely lacking understanding of what is happening differently for <code>D</code> compared to <code>C</code> as far as lifetimes go: I don't understand what the lifetime mismatch is.</p>