<p dir="auto">This may be a duplicate, but I haven't seen this resolved anywhere in the similar-looking issues. With the current nightly, the following borrow is not allowed:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="let mut a = 2u;
let mut p = &amp;mut a;
p = &amp;mut a; // Error here: &quot;a already borrowed&quot;"><pre class="notranslate"><code class="notranslate">let mut a = 2u;
let mut p = &amp;mut a;
p = &amp;mut a; // Error here: "a already borrowed"
</code></pre></div>
<p dir="auto">In terms of lifetimes, the first borrow should end by the time <code class="notranslate">p</code> is being reassigned to. However, in the current version of Rust, the borrow is considered to be taken out as long as <code class="notranslate">p</code> is alive.</p>
<p dir="auto">What is the current state of this, and are there plans to change the semantics of assignment to be able to end borrows?</p>
<p dir="auto">If you borrow immutably in an <code class="notranslate">if</code> test, the borrow lasts for the whole <code class="notranslate">if</code> expression. This means that mutable borrows in the clauses will cause the borrow checker to fail.</p>
<p dir="auto">This can also happen when borrowing in the match expression, and needing a mutable borrow in one of the arms.</p>
<p dir="auto">See here for an example where the if borrows boxes, which causes the nearest upwards <code class="notranslate">@mut</code> to freeze. Then <code class="notranslate">remove_child()</code> which needs to borrow mutably conflicts.</p>
<p dir="auto"><a href="https://github.com/mozilla/servo/blob/master/src/servo/layout/box_builder.rs#L387-L411">https://github.com/mozilla/servo/blob/master/src/servo/layout/box_builder.rs#L387-L411</a></p>
<p dir="auto"><em>Updated example from <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/Wyverald/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/Wyverald">@Wyverald</a></em></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fn main() {
    let mut vec = vec!();
    
    match vec.first() {
        None =&gt; vec.push(5),
        Some(v) =&gt; unreachable!(),
    }
}"><pre class="notranslate"><code class="notranslate">fn main() {
    let mut vec = vec!();
    
    match vec.first() {
        None =&gt; vec.push(5),
        Some(v) =&gt; unreachable!(),
    }
}
</code></pre></div>