<p dir="auto">With rust 0.6, the following code produces a segfault. Indeed, at the time of println, *y is no longer a managed pointer to a string, but an arbitrary value crafted by the closure.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="enum A { B(@str), C(int) }
fn main() -&gt; () {
  let mut x = B(@&quot;&quot;);
  let f = || { x = C(0); };
  match x {
    B(ref y) =&gt; { f(); println(*y) },
    C(*) =&gt; ()
  }
}"><pre class="notranslate"><code class="notranslate">enum A { B(@str), C(int) }
fn main() -&gt; () {
  let mut x = B(@"");
  let f = || { x = C(0); };
  match x {
    B(ref y) =&gt; { f(); println(*y) },
    C(*) =&gt; ()
  }
}
</code></pre></div>
<p dir="auto"><strong>UPDATE:</strong></p>
<p dir="auto">This is a meta-bug now for tracking the work on completing closures. Now that <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="14880798" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/6801" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/6801/hovercard" href="https://github.com/rust-lang/rust/issues/6801">#6801</a> has landed, the remaining pieces of work are:</p>
<ul dir="auto">
<li>Issue <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="7411300" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/3696" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/3696/hovercard" href="https://github.com/rust-lang/rust/issues/3696">#3696</a>: Define region hierarchy for closures</li>
<li>Issue <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="22861577" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/10553" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/10553/hovercard" href="https://github.com/rust-lang/rust/issues/10553">#10553</a>: We should not be accepting <code class="notranslate">'a ||</code> as syntax</li>
<li>Issue <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="18257171" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/8622" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/8622/hovercard" href="https://github.com/rust-lang/rust/issues/8622">#8622</a>: Unboxed closures -- for the purposes of <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="4118650" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/2202" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/2202/hovercard" href="https://github.com/rust-lang/rust/issues/2202">#2202</a>, just having a design and ensuring our treatment of closures is compatible with it is enough.</li>
<li>Issue <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="27489311" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/12224" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/12224/hovercard" href="https://github.com/rust-lang/rust/issues/12224">#12224</a>: Calling a closure is a kind of borrow.</li>
<li>Issue <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="31839741" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/13621" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/13621/hovercard" href="https://github.com/rust-lang/rust/issues/13621">#13621</a>: Explain closures much better in the tutorial</li>
</ul>
<p dir="auto"><strong>ORIGINAL FOLLOWS:</strong><br>
We need to revamp function types in light of regions.  I think <code class="notranslate">fn()</code> (the "any" function) will go away, and <code class="notranslate">fn@()</code> and <code class="notranslate">fn~()</code> will be coercable to <code class="notranslate">fn&amp;()</code>, just as with poiners/vectors/slices/etc.  Also, <code class="notranslate">fn&amp;()</code> becomes <code class="notranslate">fn&amp;r()</code> (that is, r is a region), though the user won't typically need to write it.  We can probably leave the representation as is, though we could also tweak <code class="notranslate">fn&amp;()</code> to not have a ref count since there will be an explicit borrowing that occurs.</p>