title: Cannot infer an appropriate lifetime for autoref due to conflicting requirements
body: <p>I'm having lifetime issues with a particular function in my code.  I'm following a tutorial in an attempt to learn Rust and SDL.  The tutorial was slightly older and the SDL library has changed since its been written, so I'm following along while also adapting it towards the latest version of Rust-SDL.</p>
  
  <p>The lifetime problem is in this function:</p>
  
  <pre><code>pub fn ttf_str_sprite(&amp;mut self, text: &amp;str, font_path: &amp;'static str, size: i32, color: Color) -&gt; Option&lt;Sprite&gt; {
      if let Some(font) = self.cached_fonts.get(&amp;(font_path, size)) {
          return font.render(text).blended(color).ok()
              .and_then(|surface| self.renderer.create_texture_from_surface(&amp;surface).ok())
              .map(Sprite::new)
      }
      //::sdl2_ttf::Font::from_file(Path::new(font_path), size).ok()
      self.ttf_context.load_font(Path::new(font_path), size as u16).ok()
          .and_then(|font| {
              self.cached_fonts.insert((font_path, size), font);
              self.ttf_str_sprite(text, font_path, size, color)
      })
  }
  </code></pre>
  
  <p>particularly with the line <code>self.ttf_context.load_font(Path::new(font_path), size as u16).ok()</code>.  The commented line above it is the old SDL version's font loading method.</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0495]: cannot infer an appropriate lifetime for autoref due to conflicting requirements
    --&gt; src\phi/mod.rs:57:26
     |
  57 |         self.ttf_context.load_font(Path::new(font_path), size as u16).ok()
     |                          ^^^^^^^^^
     |
  help: consider using an explicit lifetime parameter as shown: fn ttf_str_sprite(&amp;'window mut self, text: &amp;str, font_path: &amp;'static str,
                size: i32, color: Color) -&gt; Option&lt;Sprite&gt;
  </code></pre>
  
  <p>The struct object for that implementation looks like this:</p>
  
  <pre><code>pub struct Phi&lt;'window&gt; {
      pub events: Events,
      pub renderer: Renderer&lt;'window&gt;,
      pub ttf_context: Sdl2TtfContext,
  
      cached_fonts: HashMap&lt;(&amp;'static str, i32), ::sdl2_ttf::Font&lt;'window&gt;&gt;
  }
  </code></pre>
  
  <p>The method is trying to load a font from Phi's <code>ttf_context</code> and load it into the hashmap.  The Rust compiler suggested I add a lifetime to <code>self</code> in the function parameters, which, when I did that, caused a cascading effect to adding lifetimes to every method calling the original one, all the way down to <code>main()</code> and didn't help anything.</p>
  
  <p>Since I'm still new to Rust, I'm not sure where the lifetime conflict resides or why this is happening.  As a guess, I'm thinking that the <code>Font</code> object that is being generated is supposed to die with the end of that method but instead it's being loaded into a hashmap with a lifetime of <code>'window</code> and those two conflict.  I don't know enough about Rust to fix that, though, or if that's even correct.</p>