title: Cannot return a reference to an element in a lazy_static HashMap because it does not live long enough
body: <p>I have code like this:</p>
  
  <pre><code>#[macro_use]
  extern crate lazy_static;
  
  use std::collections::HashMap;
  use std::cell::RefCell;
  use std::sync::{RwLock, RwLockReadGuard, LockResult};
  
  lazy_static! {
      static ref SUBS: RwLock&lt;HashMap&lt;String, String&gt;&gt; = RwLock::new(HashMap::new());
  }
  
  pub fn get_sub(key: &amp;str) -&gt; Option&lt;&amp;String&gt; {
      let subs: LockResult&lt;RwLockReadGuard&lt;HashMap&lt;String, String&gt;&gt;&gt; = SUBS.read();
      let x: RwLockReadGuard&lt;HashMap&lt;String, String&gt;&gt; = subs.unwrap();
      x.get(key)
  }
  </code></pre>
  
  <p>And it doesn't compile:</p>
  
  <pre class="lang-none prettyprint-override"><code>error: `x` does not live long enough
    --&gt; src/main.rs:15:5
     |
  15 |     x.get(key)
     |     ^ does not live long enough
  16 | }
     | - borrowed value only lives until here
     |
  note: borrowed value must be valid for the anonymous lifetime #1 defined on the body at 12:45...
    --&gt; src/main.rs:12:46
     |
  12 |   pub fn get_sub(key: &amp;str) -&gt; Option&lt;&amp;String&gt; {
     |  ______________________________________________^ starting here...
  13 | |     let subs: LockResult&lt;RwLockReadGuard&lt;HashMap&lt;String, String&gt;&gt;&gt; = SUBS.read();
  14 | |     let x: RwLockReadGuard&lt;HashMap&lt;String, String&gt;&gt; = subs.unwrap();
  15 | |     x.get(key)
  16 | | }
     | |_^ ...ending here
  </code></pre>
  
  <p>I am completely stumped. I don't understand why this doesn't compile.</p>