<p dir="auto">I tried this code:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="enum Foo {
    NotLast(Box&lt;Foo&gt;),
    Last(u32)
}

fn x(tree: &amp;mut Foo) {
    let mut current = tree;

    loop {
        match current {
            &amp;mut Foo::NotLast(ref mut inner) =&gt; {
                current = &amp;mut *inner;
            },
            &amp;mut Foo::Last(ref mut val) =&gt; {
                *val = 1;
            },
        }
    }
}

fn main() {}"><pre class="notranslate"><span class="pl-k">enum</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
    <span class="pl-v">NotLast</span><span class="pl-kos">(</span><span class="pl-smi">Box</span><span class="pl-kos">&lt;</span><span class="pl-smi">Foo</span><span class="pl-kos">&gt;</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
    <span class="pl-v">Last</span><span class="pl-kos">(</span><span class="pl-smi">u32</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span>

<span class="pl-k">fn</span> <span class="pl-en">x</span><span class="pl-kos">(</span><span class="pl-s1">tree</span><span class="pl-kos">:</span> <span class="pl-c1">&amp;</span><span class="pl-k">mut</span> <span class="pl-smi">Foo</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">let</span> <span class="pl-k">mut</span> current = tree<span class="pl-kos">;</span>

    <span class="pl-k">loop</span> <span class="pl-kos">{</span>
        <span class="pl-k">match</span> current <span class="pl-kos">{</span>
            <span class="pl-c1">&amp;</span><span class="pl-k">mut</span> <span class="pl-smi">Foo</span><span class="pl-kos">::</span><span class="pl-v">NotLast</span><span class="pl-kos">(</span><span class="pl-k">ref</span> <span class="pl-k">mut</span> inner<span class="pl-kos">)</span> =&gt; <span class="pl-kos">{</span>
                current = <span class="pl-c1">&amp;</span><span class="pl-k">mut</span> <span class="pl-c1">*</span>inner<span class="pl-kos">;</span>
            <span class="pl-kos">}</span><span class="pl-kos">,</span>
            <span class="pl-c1">&amp;</span><span class="pl-k">mut</span> <span class="pl-smi">Foo</span><span class="pl-kos">::</span><span class="pl-v">Last</span><span class="pl-kos">(</span><span class="pl-k">ref</span> <span class="pl-k">mut</span> val<span class="pl-kos">)</span> =&gt; <span class="pl-kos">{</span>
                <span class="pl-c1">*</span>val = <span class="pl-c1">1</span><span class="pl-kos">;</span>
            <span class="pl-kos">}</span><span class="pl-kos">,</span>
        <span class="pl-kos">}</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-k">fn</span> <span class="pl-en">main</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span><span class="pl-kos">}</span></pre></div>
<p dir="auto">And got the following message:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="error.rs:11:31: 11:44 error: cannot borrow `current.0` as mutable more than once at a time
error.rs:11             &amp;mut Foo::NotLast(ref mut inner) =&gt; {
                                          ^~~~~~~~~~~~~
error.rs:11:31: 11:44 note: previous borrow of `current.0` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `current.0` until the borrow ends
error.rs:11             &amp;mut Foo::NotLast(ref mut inner) =&gt; {
                                          ^~~~~~~~~~~~~
error.rs:19:2: 19:2 note: previous borrow ends here
error.rs:6 fn x(tree: &amp;mut Foo) {
...
error.rs:19 }
            ^
error.rs:12:17: 12:38 error: cannot assign to `current` because it is borrowed
error.rs:12                 current = &amp;mut *inner;
                            ^~~~~~~~~~~~~~~~~~~~~
error.rs:11:31: 11:44 note: borrow of `current` occurs here
error.rs:11             &amp;mut Foo::NotLast(ref mut inner) =&gt; {
                                          ^~~~~~~~~~~~~
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'assertion failed: `(left == right) &amp;&amp; (right == left)` (left: `TyS { sty: ty_uint(u32), flags: 0, region_depth: 0 }`, right: `TyS { sty: ty_uniq(TyS { sty: ty_enum(DefId { krate: 0, node: 4 }, Substs { types: VecPerParamSpace {TypeSpace: [], SelfSpace: [], FnSpace: [], }, regions: NonerasedRegions(VecPerParamSpace {TypeSpace: [], SelfSpace: [], FnSpace: [], }) }), flags: 0, region_depth: 0 }), flags: 0, region_depth: 0 }`)', /tmp/portage/dev-lang/rust-1.0.0_alpha2/work/rustc-1.0.0-alpha.2/src/librustc_borrowck/borrowck/mod.rs:402"><pre class="notranslate"><code class="notranslate">error.rs:11:31: 11:44 error: cannot borrow `current.0` as mutable more than once at a time
error.rs:11             &amp;mut Foo::NotLast(ref mut inner) =&gt; {
                                          ^~~~~~~~~~~~~
error.rs:11:31: 11:44 note: previous borrow of `current.0` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `current.0` until the borrow ends
error.rs:11             &amp;mut Foo::NotLast(ref mut inner) =&gt; {
                                          ^~~~~~~~~~~~~
error.rs:19:2: 19:2 note: previous borrow ends here
error.rs:6 fn x(tree: &amp;mut Foo) {
...
error.rs:19 }
            ^
error.rs:12:17: 12:38 error: cannot assign to `current` because it is borrowed
error.rs:12                 current = &amp;mut *inner;
                            ^~~~~~~~~~~~~~~~~~~~~
error.rs:11:31: 11:44 note: borrow of `current` occurs here
error.rs:11             &amp;mut Foo::NotLast(ref mut inner) =&gt; {
                                          ^~~~~~~~~~~~~
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'assertion failed: `(left == right) &amp;&amp; (right == left)` (left: `TyS { sty: ty_uint(u32), flags: 0, region_depth: 0 }`, right: `TyS { sty: ty_uniq(TyS { sty: ty_enum(DefId { krate: 0, node: 4 }, Substs { types: VecPerParamSpace {TypeSpace: [], SelfSpace: [], FnSpace: [], }, regions: NonerasedRegions(VecPerParamSpace {TypeSpace: [], SelfSpace: [], FnSpace: [], }) }), flags: 0, region_depth: 0 }), flags: 0, region_depth: 0 }`)', /tmp/portage/dev-lang/rust-1.0.0_alpha2/work/rustc-1.0.0-alpha.2/src/librustc_borrowck/borrowck/mod.rs:402
</code></pre></div>
<p dir="auto">The snippet is probably wrong, but the assert should not fail</p>
<h2 dir="auto">Meta</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="rustc 1.0.0-dev (built 2015-02-28)
binary: rustc
commit-hash: unknown
commit-date: unknown
build-date: 2015-02-28
host: x86_64-unknown-linux-gnu
release: 1.0.0-dev"><pre class="notranslate"><code class="notranslate">rustc 1.0.0-dev (built 2015-02-28)
binary: rustc
commit-hash: unknown
commit-date: unknown
build-date: 2015-02-28
host: x86_64-unknown-linux-gnu
release: 1.0.0-dev
</code></pre></div>
<p dir="auto">Backtrace:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   1:     0x7fe4742d3c20 - sys::backtrace::write::h6db1343660ca93a2KlC
   2:     0x7fe4742f9900 - &lt;unknown&gt;
   3:     0x7fe474244d80 - rt::unwind::begin_unwind_inner::h734e583390472682RBL
   4:     0x7fe474245220 - rt::unwind::begin_unwind_fmt::hdaef33c302b47274nAL
   5:     0x7fe473478670 - &lt;unknown&gt;
   6:     0x7fe473476f70 - &lt;unknown&gt;
   7:     0x7fe473476e90 - &lt;unknown&gt;
   8:     0x7fe473463640 - borrowck::check_loans::CheckLoanCtxt&lt;'a, 'tcx&gt;.euv..Delegate&lt;'tcx&gt;::borrow::h2a13ad241eee66d6cja
   9:     0x7fe47346e160 - &lt;unknown&gt;
  10:     0x7fe47346e160 - &lt;unknown&gt;
  11:     0x7fe47346e160 - &lt;unknown&gt;
  12:     0x7fe47346dff0 - &lt;unknown&gt;
  13:     0x7fe473472670 - &lt;unknown&gt;
  14:     0x7fe4734761d0 - &lt;unknown&gt;
  15:     0x7fe473472670 - &lt;unknown&gt;
  16:     0x7fe4734761d0 - &lt;unknown&gt;
  17:     0x7fe47348e560 - &lt;unknown&gt;
  18:     0x7fe47348fa00 - &lt;unknown&gt;
  19:     0x7fe47348f450 - borrowck::check_crate::hdf41b3c11cb3508fzRe
  20:     0x7fe4748df1b0 - driver::phase_3_run_analysis_passes::h025b35dbe058134fgHa
  21:     0x7fe4748c5610 - driver::compile_input::ha5d27daf21872ba2Gba
  22:     0x7fe474993b50 - run_compiler::he50deb5aedf688fcZbc
  23:     0x7fe474992480 - &lt;unknown&gt;
  24:     0x7fe474991370 - &lt;unknown&gt;
  25:     0x7fe474356bc0 - &lt;unknown&gt;
  26:     0x7fe474356bb0 - rust_try
  27:     0x7fe474991670 - &lt;unknown&gt;
  28:     0x7fe4742e7650 - &lt;unknown&gt;
  29:     0x7fe46ef4bf40 - &lt;unknown&gt;
  30:     0x7fe473eca7d9 - clone
  31:                0x0 - &lt;unknown&gt;"><pre class="notranslate"><code class="notranslate">   1:     0x7fe4742d3c20 - sys::backtrace::write::h6db1343660ca93a2KlC
   2:     0x7fe4742f9900 - &lt;unknown&gt;
   3:     0x7fe474244d80 - rt::unwind::begin_unwind_inner::h734e583390472682RBL
   4:     0x7fe474245220 - rt::unwind::begin_unwind_fmt::hdaef33c302b47274nAL
   5:     0x7fe473478670 - &lt;unknown&gt;
   6:     0x7fe473476f70 - &lt;unknown&gt;
   7:     0x7fe473476e90 - &lt;unknown&gt;
   8:     0x7fe473463640 - borrowck::check_loans::CheckLoanCtxt&lt;'a, 'tcx&gt;.euv..Delegate&lt;'tcx&gt;::borrow::h2a13ad241eee66d6cja
   9:     0x7fe47346e160 - &lt;unknown&gt;
  10:     0x7fe47346e160 - &lt;unknown&gt;
  11:     0x7fe47346e160 - &lt;unknown&gt;
  12:     0x7fe47346dff0 - &lt;unknown&gt;
  13:     0x7fe473472670 - &lt;unknown&gt;
  14:     0x7fe4734761d0 - &lt;unknown&gt;
  15:     0x7fe473472670 - &lt;unknown&gt;
  16:     0x7fe4734761d0 - &lt;unknown&gt;
  17:     0x7fe47348e560 - &lt;unknown&gt;
  18:     0x7fe47348fa00 - &lt;unknown&gt;
  19:     0x7fe47348f450 - borrowck::check_crate::hdf41b3c11cb3508fzRe
  20:     0x7fe4748df1b0 - driver::phase_3_run_analysis_passes::h025b35dbe058134fgHa
  21:     0x7fe4748c5610 - driver::compile_input::ha5d27daf21872ba2Gba
  22:     0x7fe474993b50 - run_compiler::he50deb5aedf688fcZbc
  23:     0x7fe474992480 - &lt;unknown&gt;
  24:     0x7fe474991370 - &lt;unknown&gt;
  25:     0x7fe474356bc0 - &lt;unknown&gt;
  26:     0x7fe474356bb0 - rust_try
  27:     0x7fe474991670 - &lt;unknown&gt;
  28:     0x7fe4742e7650 - &lt;unknown&gt;
  29:     0x7fe46ef4bf40 - &lt;unknown&gt;
  30:     0x7fe473eca7d9 - clone
  31:                0x0 - &lt;unknown&gt;
</code></pre></div>
<p dir="auto">Code to reproduce here: <a href="https://github.com/toffaletti/borrow-crash">https://github.com/toffaletti/borrow-crash</a></p>
<p dir="auto"><code class="notranslate">rustc 1.2.0 (082e47636 2015-08-03)</code></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="stack backtrace:
   1:        0x103eb47b5 - sys::backtrace::write::hf5ea20500b66cd24uns
   2:        0x103ebd013 - panicking::on_panic::hbe02cb0d925cad49iGw
   3:        0x103e78dd2 - rt::unwind::begin_unwind_inner::h12ba0ba9dffdecc2uow
   4:        0x103e79b29 - rt::unwind::begin_unwind_fmt::hadf0dbf11d345ebfAnw
   5:        0x100c3568e - borrowck::LoanPath&lt;'tcx&gt;::common::h38c8ca06e07ec084irf
   6:        0x100c3366d - borrowck::check_loans::CheckLoanCtxt&lt;'a, 'tcx&gt;::report_error_if_loan_conflicts_with_restriction::h9e6281b29cbce21azGa
   7:        0x100c334fa - borrowck::check_loans::CheckLoanCtxt&lt;'a, 'tcx&gt;::report_error_if_loans_conflict::h9db6e8829e2a1ce8fEa
   8:        0x100c23250 - borrowck::check_loans::CheckLoanCtxt&lt;'a, 'tcx&gt;.euv..Delegate&lt;'tcx&gt;::borrow::hda5797bef3402e59Ria
   9:        0x100c2ad2c - middle::mem_categorization::MemCategorizationContext&lt;'t, TYPER&gt;::cat_pattern_::h14467536489201103802
  10:        0x100c2b5eb - middle::mem_categorization::MemCategorizationContext&lt;'t, TYPER&gt;::cat_pattern_::h14467536489201103802
  11:        0x100c2b12a - middle::mem_categorization::MemCategorizationContext&lt;'t, TYPER&gt;::cat_pattern_::h14467536489201103802
  12:        0x100c2a6e5 - middle::expr_use_visitor::ExprUseVisitor&lt;'d, 't, 'tcx, TYPER&gt;::walk_pat::h9458671995004733122
  13:        0x100c2f403 - middle::expr_use_visitor::ExprUseVisitor&lt;'d, 't, 'tcx, TYPER&gt;::walk_expr::h982213050074646850
  14:        0x100c326a2 - middle::expr_use_visitor::ExprUseVisitor&lt;'d, 't, 'tcx, TYPER&gt;::consume_expr::h8840565628159227535
  15:        0x100c2f649 - middle::expr_use_visitor::ExprUseVisitor&lt;'d, 't, 'tcx, TYPER&gt;::walk_expr::h982213050074646850
  16:        0x100c326a2 - middle::expr_use_visitor::ExprUseVisitor&lt;'d, 't, 'tcx, TYPER&gt;::consume_expr::h8840565628159227535
  17:        0x100c2f62e - middle::expr_use_visitor::ExprUseVisitor&lt;'d, 't, 'tcx, TYPER&gt;::walk_expr::h982213050074646850
  18:        0x100c326a2 - middle::expr_use_visitor::ExprUseVisitor&lt;'d, 't, 'tcx, TYPER&gt;::consume_expr::h8840565628159227535
  19:        0x100c2f433 - middle::expr_use_visitor::ExprUseVisitor&lt;'d, 't, 'tcx, TYPER&gt;::walk_expr::h982213050074646850
  20:        0x100c326a2 - middle::expr_use_visitor::ExprUseVisitor&lt;'d, 't, 'tcx, TYPER&gt;::consume_expr::h8840565628159227535
  21:        0x100c4cb45 - borrowck::borrowck_fn::h1de21a9e0166e8daEPe
  22:        0x100c4c1d9 - borrowck::BorrowckCtxt&lt;'a, 'tcx&gt;.Visitor&lt;'v&gt;::visit_fn::h93ef453410da10bc2Ge
  23:        0x100c4eb14 - visit::walk_impl_item::h15300236788859175913
  24:        0x100c4f7ca - visit::walk_item::h3483642570553201847
  25:        0x100c4ec68 - borrowck::check_crate::h138dee6ce4dd468bHJe
  26:        0x1007998a1 - driver::phase_3_run_analysis_passes::closure.15766
  27:        0x100796204 - middle::ty::with_ctxt::h14728011725879770170
  28:        0x10079100a - driver::phase_3_run_analysis_passes::h16713467199444562124
  29:        0x100774107 - driver::compile_input::hb6d2be5b0fa2247fTba
  30:        0x10085013f - run_compiler::h21d74b88eec3fe3bx7b
  31:        0x10084d9f3 - boxed::F.FnBox&lt;A&gt;::call_box::h1689969825914258414
  32:        0x10084d1b7 - rt::unwind::try::try_fn::h11273853850686318048
  33:        0x103f47cc8 - rust_try_inner
  34:        0x103f47cb5 - rust_try
  35:        0x103ea6c95 - rt::unwind::try::inner_try::h480e3107f6a4b5b9nkw
  36:        0x10084d3e8 - boxed::F.FnBox&lt;A&gt;::call_box::h888215220722514405
  37:        0x103ebba9d - sys::thread::Thread::new::thread_start::hdb3d925f69c5da4aHIv
  38:     0x7fff8f7f8059 - _pthread_body
  39:     0x7fff8f7f7fd6 - _pthread_start"><pre class="notranslate"><code class="notranslate">stack backtrace:
   1:        0x103eb47b5 - sys::backtrace::write::hf5ea20500b66cd24uns
   2:        0x103ebd013 - panicking::on_panic::hbe02cb0d925cad49iGw
   3:        0x103e78dd2 - rt::unwind::begin_unwind_inner::h12ba0ba9dffdecc2uow
   4:        0x103e79b29 - rt::unwind::begin_unwind_fmt::hadf0dbf11d345ebfAnw
   5:        0x100c3568e - borrowck::LoanPath&lt;'tcx&gt;::common::h38c8ca06e07ec084irf
   6:        0x100c3366d - borrowck::check_loans::CheckLoanCtxt&lt;'a, 'tcx&gt;::report_error_if_loan_conflicts_with_restriction::h9e6281b29cbce21azGa
   7:        0x100c334fa - borrowck::check_loans::CheckLoanCtxt&lt;'a, 'tcx&gt;::report_error_if_loans_conflict::h9db6e8829e2a1ce8fEa
   8:        0x100c23250 - borrowck::check_loans::CheckLoanCtxt&lt;'a, 'tcx&gt;.euv..Delegate&lt;'tcx&gt;::borrow::hda5797bef3402e59Ria
   9:        0x100c2ad2c - middle::mem_categorization::MemCategorizationContext&lt;'t, TYPER&gt;::cat_pattern_::h14467536489201103802
  10:        0x100c2b5eb - middle::mem_categorization::MemCategorizationContext&lt;'t, TYPER&gt;::cat_pattern_::h14467536489201103802
  11:        0x100c2b12a - middle::mem_categorization::MemCategorizationContext&lt;'t, TYPER&gt;::cat_pattern_::h14467536489201103802
  12:        0x100c2a6e5 - middle::expr_use_visitor::ExprUseVisitor&lt;'d, 't, 'tcx, TYPER&gt;::walk_pat::h9458671995004733122
  13:        0x100c2f403 - middle::expr_use_visitor::ExprUseVisitor&lt;'d, 't, 'tcx, TYPER&gt;::walk_expr::h982213050074646850
  14:        0x100c326a2 - middle::expr_use_visitor::ExprUseVisitor&lt;'d, 't, 'tcx, TYPER&gt;::consume_expr::h8840565628159227535
  15:        0x100c2f649 - middle::expr_use_visitor::ExprUseVisitor&lt;'d, 't, 'tcx, TYPER&gt;::walk_expr::h982213050074646850
  16:        0x100c326a2 - middle::expr_use_visitor::ExprUseVisitor&lt;'d, 't, 'tcx, TYPER&gt;::consume_expr::h8840565628159227535
  17:        0x100c2f62e - middle::expr_use_visitor::ExprUseVisitor&lt;'d, 't, 'tcx, TYPER&gt;::walk_expr::h982213050074646850
  18:        0x100c326a2 - middle::expr_use_visitor::ExprUseVisitor&lt;'d, 't, 'tcx, TYPER&gt;::consume_expr::h8840565628159227535
  19:        0x100c2f433 - middle::expr_use_visitor::ExprUseVisitor&lt;'d, 't, 'tcx, TYPER&gt;::walk_expr::h982213050074646850
  20:        0x100c326a2 - middle::expr_use_visitor::ExprUseVisitor&lt;'d, 't, 'tcx, TYPER&gt;::consume_expr::h8840565628159227535
  21:        0x100c4cb45 - borrowck::borrowck_fn::h1de21a9e0166e8daEPe
  22:        0x100c4c1d9 - borrowck::BorrowckCtxt&lt;'a, 'tcx&gt;.Visitor&lt;'v&gt;::visit_fn::h93ef453410da10bc2Ge
  23:        0x100c4eb14 - visit::walk_impl_item::h15300236788859175913
  24:        0x100c4f7ca - visit::walk_item::h3483642570553201847
  25:        0x100c4ec68 - borrowck::check_crate::h138dee6ce4dd468bHJe
  26:        0x1007998a1 - driver::phase_3_run_analysis_passes::closure.15766
  27:        0x100796204 - middle::ty::with_ctxt::h14728011725879770170
  28:        0x10079100a - driver::phase_3_run_analysis_passes::h16713467199444562124
  29:        0x100774107 - driver::compile_input::hb6d2be5b0fa2247fTba
  30:        0x10085013f - run_compiler::h21d74b88eec3fe3bx7b
  31:        0x10084d9f3 - boxed::F.FnBox&lt;A&gt;::call_box::h1689969825914258414
  32:        0x10084d1b7 - rt::unwind::try::try_fn::h11273853850686318048
  33:        0x103f47cc8 - rust_try_inner
  34:        0x103f47cb5 - rust_try
  35:        0x103ea6c95 - rt::unwind::try::inner_try::h480e3107f6a4b5b9nkw
  36:        0x10084d3e8 - boxed::F.FnBox&lt;A&gt;::call_box::h888215220722514405
  37:        0x103ebba9d - sys::thread::Thread::new::thread_start::hdb3d925f69c5da4aHIv
  38:     0x7fff8f7f8059 - _pthread_body
  39:     0x7fff8f7f7fd6 - _pthread_start
</code></pre></div>