title: Passing the contents of a RefCell<&mut T> to a function
body: <p>Calling methods on a borrowed <code>RefCell&lt;&amp;mut T&gt;</code> (That is, a <code>Ref&lt;&amp;mut T&gt;</code>) works as expected, but I can't seem to pass it to a function. Consider the following code:</p>
  
  <pre><code>use std::cell::RefCell;
  
  fn main() {
      let mut nums = vec![1, 2, 3];
      foo(&amp;mut nums);
      println!("{:?}", nums);
  }
  
  fn foo(nums: &amp;mut Vec&lt;usize&gt;) {
      let num_cell = RefCell::new(nums);
  
      num_cell.borrow_mut().push(4);
  
      push_5(*num_cell.borrow_mut());
  }
  
  fn push_5(nums: &amp;mut Vec&lt;usize&gt;) {
      nums.push(4);
  }
  </code></pre>
  
  <p><code>num_cell.borrow_mut().push(4)</code> works, but <code>push_5(*num_cell.borrow_mut())</code> errors with:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0389]: cannot borrow data mutably in a `&amp;` reference
    --&gt; src/main.rs:14:12
     |
  14 |     push_5(*num_cell.borrow_mut());
     |            ^^^^^^^^^^^^^^^^^^^^^^ assignment into an immutable reference
  </code></pre>
  
  <p>After dereferencing the <code>Ref</code>, I expected to get the mutable reference inside so the error doesn't really make sense to me. What gives?</p>