title: Impl trait with generic associated type in return position causes lifetime error
body: <p>I need to store a <code>fn(I) -&gt; O</code> (where <code>I</code> &amp; <code>O</code> can be references) in a <code>'static</code> struct. <code>O</code> needs to be a trait with an <code>'static</code> generic associated type, that associated type is also stored in the struct. Neither <code>I</code> nor <code>O</code> itself get stored inside of the struct, so their lifetime shouldn't matter. But the compiler is still complaining about <code>I</code> not living long enough.</p>
  <pre class="lang-rust prettyprint-override"><code>trait IntoState {
      type State: 'static;
  
      fn into_state(self) -&gt; Self::State;
  }
  
  impl IntoState for &amp;str {
      type State = String;
  
      fn into_state(self) -&gt; Self::State {
          self.to_string()
      }
  }
  
  struct Container&lt;F, S&gt; {
      func: F,
      state: S,
  }
  
  impl&lt;I, O&gt; Container&lt;fn(I) -&gt; O, O::State&gt;
  where
      O: IntoState,
  {
      fn new(input: I, func: fn(I) -&gt; O) -&gt; Self {
          // I &amp; O lives only in the next line of code. O gets converted into
          // a `'static` (`String`), that is stored in `Container`.
          let state = func(input).into_state();
          Container { func, state }
      }
  }
  
  fn map(i: &amp;str) -&gt; impl '_ + IntoState {
      i
  }
  
  fn main() {
      let _ = {
          // create a temporary value
          let s = &quot;foo&quot;.to_string();
  
          // the temporary actually only needs to live in `new`. It is
          // never stored in `Container`.
          Container::new(s.as_str(), map)
          // ERR:        ^ borrowed value does not live long enough
      };
      // ERR: `s` dropped here while still borrowed
  }
  </code></pre>
  <p><a href="https://play.integer32.com/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=dfdcc654ba061dd660f6eb466a34b086" rel="nofollow noreferrer">playground</a></p>