title: Why does HashMap::get_mut() take ownership of the map for the rest of the scope?
body: <p>I have the following code that inserts some values into a HashMap and then gets them back out:</p>
  
  <pre><code>use std::collections::HashMap;
  
  fn things() {
      let mut map = HashMap::new();
      map.insert(5, "thing");
      map.insert(4, "world");
      map.insert(1, "hello");
      let mut thing = map.remove(&amp;5);
      let mut world = map.get_mut(&amp;4);
      let mut hello = map.get_mut(&amp;1);
  }
  </code></pre>
  
  <p>Attempting to compile this code gives the following error:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0499]: cannot borrow `map` as mutable more than once at a time
    --&gt; src/main.rs:10:21
     |
  9  |     let mut world = map.get_mut(&amp;4);
     |                     --- first mutable borrow occurs here
  10 |     let mut hello = map.get_mut(&amp;1);
     |                     ^^^ second mutable borrow occurs here
  11 | }
     | - first borrow ends here
  </code></pre>
  
  <p>After perusing the API docs for both the <code>remove()</code> and <a href="https://doc.rust-lang.org/std/collections/struct.HashMap.html#method.get_mut" rel="noreferrer"><code>get_mut()</code></a> methods (fortunately they are pretty close to each other!) there is nothing that stands out to me from the method signatures why the <code>remove()</code> method does not mutably borrow the map for the rest of the current scope while the <code>get_mut()</code> method does. </p>
  
  <p>The other piece of data that I have that also mystifies me is that this code compiles:</p>
  
  <pre><code>use std::collections::HashMap;
  
  fn things() {
      let mut map = HashMap::new();
      map.insert(5, "thing");
      map.insert(4, "world");
      map.insert(1, "hello");
      let mut thing = map.remove(&amp;5);
      map.get_mut(&amp;4);
      let mut hello = map.get_mut(&amp;1);
  }
  </code></pre>
  
  <p>Not storing the result of the first call to <code>get_mut()</code> doesn't cause the map to be mutably borrowed for the rest of the scope?  How could I have known this from looking at the documentation?  Am I missing something else?</p>