title: Why do the lifetimes on a trait object passed as an argument require Higher Ranked Trait Bounds but a struct doesn't?
body: <p>How are lifetimes handled when there is a trait object passed to a function?</p>
  
  <pre><code>struct Planet&lt;T&gt; {
      i: T,
  }
  
  trait Spinner&lt;T&gt; {
      fn spin(&amp;self, value: T);
  }
  
  impl&lt;T&gt; Spinner&lt;T&gt; for Planet&lt;T&gt; {
      fn spin(&amp;self, value: T) {}
  }
  
  // foo2 fails: Due to lifetime of local variable being less than 'a
  fn foo2&lt;'a&gt;(t: &amp;'a Spinner&lt;&amp;'a i32&gt;) {
      let x: i32 = 10;
      t.spin(&amp;x);
  }
  
  // foo1 passes: But here also the lifetime of local variable is less than 'a?
  fn foo1&lt;'a&gt;(t: &amp;'a Planet&lt;&amp;'a i32&gt;) {
      let x: i32 = 10;
      t.spin(&amp;x);
  }
  </code></pre>
  
  <p>(<a href="https://play.rust-lang.org/?gist=933db03230161c21356523d67e8ec313&amp;version=stable&amp;mode=debug" rel="noreferrer">Playground</a>)</p>
  
  <p>This code results in this error:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0597]: `x` does not live long enough
    --&gt; src/main.rs:16:17
     |
  16 |         t.spin(&amp;x);
     |                 ^ borrowed value does not live long enough
  17 |     }
     |     - borrowed value only lives until here
     |
  note: borrowed value must be valid for the lifetime 'a as defined on the function body at 14:5...
    --&gt; src/main.rs:14:5
     |
  14 |     fn foo2&lt;'a&gt;(t: &amp;'a Spinner&lt;&amp;'a i32&gt;) {
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  </code></pre>
  
  <p>The function signature of <code>foo1</code> is nearly same as <code>foo2</code>. One receiving the reference to <em>struct</em> and the other a <em>trait object</em>.</p>
  
  <p>I read this is where Higher Ranked Trait Bounds comes in. Modifying <em>foo2</em> as <code>foo2(t: &amp;for&lt;'a&gt; Spinner&lt;&amp;'a i32&gt;)</code> compiles the code, but I don't understand why.</p>
  
  <p>Why won't <code>'a</code> shrink for <code>x</code>?</p>
  
  <p>Citing <a href="https://doc.rust-lang.org/nomicon/hrtb.html" rel="noreferrer">the Nomicon</a>: </p>
  
  <blockquote>
    <p>How on earth are we supposed to express the lifetimes on <code>F</code>'s trait bound? We need to provide some lifetime there, but the lifetime we care about can't be named until we enter the body of call! Also, that isn't some fixed lifetime; <code>call</code> works with any lifetime <code>&amp;self</code> happens to have at that point.</p>
  </blockquote>
  
  <p>Can this please be elaborated?</p>