title: Refactoring messes up mutable borrow - why?
body: <p>I'm trying to understand why does the following refactoring result in an error, even though it should effectively have the same behaviour:</p>
  
  <p>Before:</p>
  
  <pre class="lang-rust prettyprint-override"><code>fn req_handler(req: &amp;mut Request) -&gt; IronResult&lt;Response&gt; {
      let pool = req.get::&lt;Read&lt;Database&gt;&gt;().ok().expect("database component not initialised");
      let connection = pool.get().unwrap();
  
      let maybe_id = req.extensions.get::&lt;Router&gt;().unwrap().find("id");
      ...
  </code></pre>
  
  <p>After:</p>
  
  <pre class="lang-rust prettyprint-override"><code>pub fn get_pool_connection&lt;'a, 'b, 'c&gt;(req: &amp;'a mut Request&lt;'b, 'c&gt;) -&gt; PooledConnection&lt;'a, PostgresConnectionManager&gt; {
      let pool = req.get_ref::&lt;Read&lt;Database&gt;&gt;().ok().expect("database component not initialised");
      pool.get().unwrap()
  }
  fn req_handler(req: &amp;mut Request) -&gt; IronResult&lt;Response&gt; {
      let connection = get_pool_connection(req);
      let maybe_id = req.extensions.get::&lt;Router&gt;().unwrap().find("id");
  </code></pre>
  
  <p>This results in error:</p>
  
  <pre><code>src/main.rs:64:20: 64:34 error: cannot borrow `req.extensions` as immutable because `*req` is also borrowed as mutable
  src/main.rs:64     let maybe_id = req.extensions.get::&lt;Router&gt;().unwrap().find("id");
                                    ^~~~~~~~~~~~~~
  src/main.rs:62:42: 62:45 note: previous borrow of `*req` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `*req` until the borrow ends
  src/main.rs:62     let connection = get_pool_connection(req);
                                                          ^~~
  src/main.rs:76:2: 76:2 note: previous borrow ends here
  src/main.rs:61 fn req_handler(req: &amp;mut Request) -&gt; IronResult&lt;Response&gt; {
  ...
  src/main.rs:76 }
  </code></pre>
  
  <p>So the problem is that <code>get_pool_connection</code> borrows the request and gives back <code>connection</code> which prevents further <code>req</code> use. But why does this happen? <code>req</code> is guaranteed to use at least the same lifetime as the returned <code>PooledConnection</code>. It's not moved either, it was just passed as <code>&amp;mut</code>. So what prevents the request from being used?</p>
  
  <p>And why does the error say that <code>*req</code> was borrowed, when both local <code>req</code> and the function parameter are references?</p>
  
  <p>(relevant docs: <a href="http://ironframework.io/doc/iron/request/struct.Request.html" rel="nofollow">Request</a>, <a href="https://sfackler.github.io/r2d2/doc/r2d2/struct.Pool.html" rel="nofollow">Pool</a>)</p>