title: Rust cannot return value referencing local variable on HashMap get
body: <p>I have a code looks like this:</p>
  <pre><code>use std::collections::HashMap;
  
  fn main() {
      let x = get_hash_map();
      println!(&quot;{:?}&quot;, x);
  }
  
  fn get_hash_map() -&gt; Option&lt;&amp;'static Vec&lt;i32&gt;&gt; {
      let mut hm = HashMap::new();
      let mut vec = Vec::new();
      vec.push(1);
      hm.insert(&quot;1&quot;.to_string(), vec);
      return hm.get(&quot;1&quot;);
  }
  </code></pre>
  <p>But I got this error:</p>
  <pre><code>error[E0515]: cannot return value referencing local variable `hm`
    --&gt; src/main.rs:13:12
     |
  13 |     return hm.get(&quot;1&quot;);
     |            --^^^^^^^^^
     |            |
     |            returns a value referencing data owned by the current function
     |            `hm` is borrowed here
  </code></pre>
  <p>Here is the rust playground: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=7605176aee2dd3ff77a0cfd04a89db55" rel="nofollow noreferrer">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=7605176aee2dd3ff77a0cfd04a89db55</a></p>
  <p>Can anyone suggest the alternatives to fix this problem minimally? Thanks!</p>