title: `if` condition remains borrowed in body
body: <p>I just came across some behaviour in Rust (1.12) I cannot explain. I have a struct that implements lazy loading with a <code>RefCell&lt;Option&lt;i32&gt;&gt;</code> and a function to access the data:</p>
  
  <pre><code>struct Foo {
      data: RefCell&lt;Option&lt;i32&gt;&gt;
  }
  
  impl Foo {
      fn get_data(&amp;self) -&gt; i32 {
          if self.data.borrow().is_none() { // &lt;--- (a)
              let d = 1337;
              self.data.borrow_mut() = Some(d); // &lt;--- (b)
              d
          } else {
              self.data.borrow().unwrap()
          }
      }
  }
  </code></pre>
  
  <p>This compiles but yields a runtime error: The <code>RefCell</code> complains that a borrow is already active when attempting to <code>borrow_mut</code> on line <strong>(b)</strong>. The issue does not occur, however, if I change the if statement to the following:</p>
  
  <pre><code>let is_none = self.data.borrow().is_none();
  if is_none {
  </code></pre>
  
  <p><strong>Question:</strong> Why is the borrow in the if condition on line <strong>(a)</strong> still active inside the body of the if statement? Shouldn't the call to <code>is_none()</code> cause the borrow to end, since I'm only holding on to a <code>bool</code> afterwards, and not the borrowed value?</p>