<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#![feature(std_misc)]

use std::cell::RefCell;

fn main() {
  let b = RefCell::new(Some(5));
  if let Some(x) = b.borrow().clone() {
  }
}"><pre class="notranslate"><span class="pl-c1">#!<span class="pl-kos">[</span>feature<span class="pl-kos">(</span>std_misc<span class="pl-kos">)</span><span class="pl-kos">]</span></span>

<span class="pl-k">use</span> std<span class="pl-kos">::</span>cell<span class="pl-kos">::</span><span class="pl-v">RefCell</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-k">let</span> b = <span class="pl-smi">RefCell</span><span class="pl-kos">::</span><span class="pl-en">new</span><span class="pl-kos">(</span><span class="pl-v">Some</span><span class="pl-kos">(</span><span class="pl-c1">5</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-k">if</span> <span class="pl-k">let</span> <span class="pl-v">Some</span><span class="pl-kos">(</span>x<span class="pl-kos">)</span> = b<span class="pl-kos">.</span><span class="pl-en">borrow</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">clone</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></pre></div>
<p dir="auto">And the error is:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="error: `b` does not live long enough"><pre class="notranslate"><code class="notranslate">error: `b` does not live long enough
</code></pre></div>
<p dir="auto">Spawned off of <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="54076219" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/21022" data-hovercard-type="pull_request" data-hovercard-url="/rust-lang/rust/pull/21022/hovercard" href="https://github.com/rust-lang/rust/pull/21022">#21022</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="56708388" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/21972" data-hovercard-type="pull_request" data-hovercard-url="/rust-lang/rust/pull/21972/hovercard" href="https://github.com/rust-lang/rust/pull/21972">#21972</a></p>
<p dir="auto">There are a number of situations where a trailing expression like a for-loop ends up being treated by the region lifetime inferencer as requiring a much longer lifetime assignment than what you would intuitively expect.</p>
<p dir="auto">A lot of the relevant cases have been addressed. In fact, its gotten to the point that I want to have a summary comment up here that specifies the status for each example. Each demo should link to  a playpen (using AST-borrowck when that has a checkmark, and NLL when AST-borrowck does not have a checkmark). Some rows also include a link to the comment where it was pointed out.</p>
<ul dir="auto">
<li>A checkmark (<g-emoji class="g-emoji" alias="white_check_mark" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2705.png">✅</g-emoji>) is used for cases where either 1. code is now accepted, or 2. code is (still) rejected but has a clear diagnostic explaining why.</li>
<li>The column marked 2018 is testing here the 2018 edition, where migration mode gets <em>most</em> of the benefits from NLL. They will also eventually trickle down to the 2015 edition when we switch that to use NLL as well.</li>
<li>The magnifying glass (<g-emoji class="g-emoji" alias="mag" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f50d.png">🔍</g-emoji>) is for cases where we issue a diagnostic suggesting that one add a local binding or a semi-colon (depending on whether the value is needed or not), explaining that the temporaries (under the current language semantics) are being dropped too late without it. This sort of case is, to my eye, acceptable.</li>
<li>The column marked NLL is for cases where you need to opt into <code class="notranslate">#![feature(nll)]</code> (or use the synonymous command line options <code class="notranslate">-Z borrowck=mir -Z two-phase-borrows</code>) to get the nicest output. In most cases the 2018 output is the same, so I didn't fill in the column in those cases.</li>
</ul>
<table role="table">
<thead>
<tr>
<th>Example on playpen</th>
<th>2015</th>
<th>2018</th>
<th>NLL</th>
<th>source</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2015&amp;gist=ed2d96f950b9ee7cb27efe2d6f861386" rel="nofollow">io::stdin demo 1</a></td>
<td><g-emoji class="g-emoji" alias="white_check_mark" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2705.png">✅</g-emoji></td>
<td><g-emoji class="g-emoji" alias="white_check_mark" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2705.png">✅</g-emoji></td>
<td></td>
<td></td>
</tr>
<tr>
<td><a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=7aaf4635c187dd9db58776859fbabd2a" rel="nofollow">io::stdin demo 2</a></td>
<td><g-emoji class="g-emoji" alias="nauseated_face" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f922.png">🤢</g-emoji></td>
<td><g-emoji class="g-emoji" alias="white_check_mark" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2705.png">✅</g-emoji></td>
<td></td>
<td></td>
</tr>
<tr>
<td><a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2015&amp;gist=e2ec7e2845822b53a7dfc037758724ba" rel="nofollow">alloc::rc demo</a></td>
<td>✅</td>
<td><g-emoji class="g-emoji" alias="white_check_mark" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2705.png">✅</g-emoji></td>
<td></td>
<td></td>
</tr>
<tr>
<td><a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=43b2bfa79979015adadbaed80d438cbb" rel="nofollow">ebfull drain demo</a></td>
<td><g-emoji class="g-emoji" alias="nauseated_face" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f922.png">🤢</g-emoji></td>
<td>✅</td>
<td></td>
<td><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="54255470" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/21114" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/21114/hovercard?comment_id=74242619&amp;comment_type=issue_comment" href="https://github.com/rust-lang/rust/issues/21114#issuecomment-74242619">#21114 (comment)</a></td>
</tr>
<tr>
<td><a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=96ecfaf797bfb8dab23f6a0fa566f584" rel="nofollow">felispere stdio demo</a></td>
<td><g-emoji class="g-emoji" alias="nauseated_face" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f922.png">🤢</g-emoji></td>
<td><g-emoji class="g-emoji" alias="white_check_mark" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2705.png">✅</g-emoji></td>
<td></td>
<td><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="54255470" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/21114" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/21114/hovercard?comment_id=74300312&amp;comment_type=issue_comment" href="https://github.com/rust-lang/rust/issues/21114#issuecomment-74300312">#21114 (comment)</a></td>
</tr>
<tr>
<td><a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2015&amp;gist=57cc22508735c359603e8849ff54efd2" rel="nofollow">drbawb demo</a></td>
<td><g-emoji class="g-emoji" alias="white_check_mark" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2705.png">✅</g-emoji></td>
<td><g-emoji class="g-emoji" alias="white_check_mark" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2705.png">✅</g-emoji></td>
<td></td>
<td><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="54255470" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/21114" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/21114/hovercard?comment_id=74438455&amp;comment_type=issue_comment" href="https://github.com/rust-lang/rust/issues/21114#issuecomment-74438455">#21114 (comment)</a></td>
</tr>
<tr>
<td><a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=722bfa4840f78d15b38e625e16f11eba" rel="nofollow">niconii demo</a></td>
<td><g-emoji class="g-emoji" alias="nauseated_face" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f922.png">🤢</g-emoji></td>
<td>🔍</td>
<td></td>
<td><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="54255470" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/21114" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/21114/hovercard?comment_id=228331214&amp;comment_type=issue_comment" href="https://github.com/rust-lang/rust/issues/21114#issuecomment-228331214">#21114 (comment)</a></td>
</tr>
<tr>
<td><a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=4dd142514a64f72aaec3f63cdf6886e2" rel="nofollow">kixunil demo</a></td>
<td><g-emoji class="g-emoji" alias="nauseated_face" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f922.png">🤢</g-emoji></td>
<td><g-emoji class="g-emoji" alias="white_check_mark" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2705.png">✅</g-emoji></td>
<td></td>
<td><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="54255470" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/21114" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/21114/hovercard?comment_id=312447832&amp;comment_type=issue_comment" href="https://github.com/rust-lang/rust/issues/21114#issuecomment-312447832">#21114 (comment)</a></td>
</tr>
<tr>
<td><a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=d37416a2c2e4458b13ecea1af52cc616" rel="nofollow">thiez demo 1</a></td>
<td><g-emoji class="g-emoji" alias="nauseated_face" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f922.png">🤢</g-emoji></td>
<td><g-emoji class="g-emoji" alias="white_check_mark" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2705.png">✅</g-emoji></td>
<td></td>
<td><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="54255470" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/21114" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/21114/hovercard?comment_id=321158567&amp;comment_type=issue_comment" href="https://github.com/rust-lang/rust/issues/21114#issuecomment-321158567">#21114 (comment)</a></td>
</tr>
<tr>
<td><a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=8277a810e6e20becbc190366ebd60aa8" rel="nofollow">thiez demo 2</a></td>
<td>🤢</td>
<td><g-emoji class="g-emoji" alias="mag" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f50d.png">🔍</g-emoji></td>
<td></td>
<td><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="54255470" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/21114" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/21114/hovercard?comment_id=321158567&amp;comment_type=issue_comment" href="https://github.com/rust-lang/rust/issues/21114#issuecomment-321158567">#21114 (comment)</a></td>
</tr>
<tr>
<td><a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=01cb342d5eb6ffca31bc2f096b297ca8" rel="nofollow">shepmaster demo</a></td>
<td>🤢</td>
<td><g-emoji class="g-emoji" alias="white_check_mark" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2705.png">✅</g-emoji></td>
<td></td>
<td><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="54255470" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/21114" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/21114/hovercard?comment_id=357400013&amp;comment_type=issue_comment" href="https://github.com/rust-lang/rust/issues/21114#issuecomment-357400013">#21114 (comment)</a></td>
</tr>
<tr>
<td><a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=366c0fb4a21ffacdf98008fa60d30c38" rel="nofollow">jonas-schievink demo</a></td>
<td>🤢</td>
<td><g-emoji class="g-emoji" alias="nauseated_face" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f922.png">🤢</g-emoji></td>
<td><g-emoji class="g-emoji" alias="white_check_mark" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2705.png">✅</g-emoji></td>
<td><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="234958213" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/42574" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/42574/hovercard" href="https://github.com/rust-lang/rust/issues/42574">#42574</a></td>
</tr>
<tr>
<td><a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=a92017dbd39332967b70f5fe4cb2557c" rel="nofollow">stephaneyfx demo 1</a></td>
<td><g-emoji class="g-emoji" alias="nauseated_face" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f922.png">🤢</g-emoji></td>
<td><g-emoji class="g-emoji" alias="mag" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f50d.png">🔍</g-emoji></td>
<td></td>
<td><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="278286308" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/46413" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/46413/hovercard?comment_id=352113056&amp;comment_type=issue_comment" href="https://github.com/rust-lang/rust/issues/46413#issuecomment-352113056">#46413 (comment)</a></td>
</tr>
<tr>
<td><a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=ed8abe64be080c951a072c0fd5bf855d" rel="nofollow">stephaneyfx demo 2</a></td>
<td>🤢</td>
<td><g-emoji class="g-emoji" alias="mag" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f50d.png">🔍</g-emoji></td>
<td></td>
<td><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="278286308" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/46413" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/46413/hovercard?comment_id=378353931&amp;comment_type=issue_comment" href="https://github.com/rust-lang/rust/issues/46413#issuecomment-378353931">#46413 (comment)</a></td>
</tr>
</tbody>
</table>
<h2 dir="auto">More details for issue follow.</h2>
<p dir="auto">A simple example of this (from examples embedded in the docs for <code class="notranslate">io::stdio</code>):</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    use std::io;

    let mut stdin = io::stdin();
    for line in stdin.lock().lines() {
        println!(&quot;{}&quot;, line.unwrap());
    };"><pre class="notranslate">    <span class="pl-k">use</span> std<span class="pl-kos">::</span>io<span class="pl-kos">;</span>

    <span class="pl-k">let</span> <span class="pl-k">mut</span> stdin = io<span class="pl-kos">::</span><span class="pl-en">stdin</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">for</span> line <span class="pl-k">in</span> stdin<span class="pl-kos">.</span><span class="pl-en">lock</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">lines</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"{}"</span>, line.unwrap<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></pre></div>
<p dir="auto">Another example, this time from an example for <code class="notranslate">alloc::rc</code> (where this time I took the time to add a comment explaining what I encountered):</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="fn main() {
     let gadget_owner : Rc&lt;Owner&gt; = Rc::new(
            Owner {
                name: &quot;Gadget Man&quot;.to_string(),
                gadgets: RefCell::new(Vec::new())
            }
    );

    let gadget1 = Rc::new(Gadget{id: 1, owner: gadget_owner.clone()});
    let gadget2 = Rc::new(Gadget{id: 2, owner: gadget_owner.clone()});

    gadget_owner.gadgets.borrow_mut().push(gadget1.clone().downgrade());
    gadget_owner.gadgets.borrow_mut().push(gadget2.clone().downgrade());

    for gadget_opt in gadget_owner.gadgets.borrow().iter() {
        let gadget = gadget_opt.upgrade().unwrap();
        println!(&quot;Gadget {} owned by {}&quot;, gadget.id, gadget.owner.name);
    }

    // This is an unfortunate wart that is a side-effect of the implmentation
    // of new destructor semantics: if the above for-loop is the final expression
    // in the function, the borrow-checker treats the gadget_owner as needing to
    // live past the destruction scope of the function (which of course it does not).
    // To work around this, for now I am inserting a dummy value just so the above
    // for-loop is no longer the final expression in the block.
    ()
}"><pre class="notranslate"><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-k">let</span> gadget_owner <span class="pl-kos">:</span> <span class="pl-smi">Rc</span><span class="pl-kos">&lt;</span><span class="pl-smi">Owner</span><span class="pl-kos">&gt;</span> = <span class="pl-smi">Rc</span><span class="pl-kos">::</span><span class="pl-en">new</span><span class="pl-kos">(</span>
            <span class="pl-smi">Owner</span> <span class="pl-kos">{</span>
                <span class="pl-c1">name</span><span class="pl-kos">:</span> <span class="pl-s">"Gadget Man"</span><span class="pl-kos">.</span><span class="pl-en">to_string</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
                <span class="pl-c1">gadgets</span><span class="pl-kos">:</span> <span class="pl-smi">RefCell</span><span class="pl-kos">::</span><span class="pl-en">new</span><span class="pl-kos">(</span><span class="pl-smi">Vec</span><span class="pl-kos">::</span><span class="pl-en">new</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">let</span> gadget1 = <span class="pl-smi">Rc</span><span class="pl-kos">::</span><span class="pl-en">new</span><span class="pl-kos">(</span><span class="pl-smi">Gadget</span><span class="pl-kos">{</span><span class="pl-c1">id</span><span class="pl-kos">:</span> <span class="pl-c1">1</span><span class="pl-kos">,</span> <span class="pl-c1">owner</span><span class="pl-kos">:</span> gadget_owner<span class="pl-kos">.</span><span class="pl-en">clone</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">let</span> gadget2 = <span class="pl-smi">Rc</span><span class="pl-kos">::</span><span class="pl-en">new</span><span class="pl-kos">(</span><span class="pl-smi">Gadget</span><span class="pl-kos">{</span><span class="pl-c1">id</span><span class="pl-kos">:</span> <span class="pl-c1">2</span><span class="pl-kos">,</span> <span class="pl-c1">owner</span><span class="pl-kos">:</span> gadget_owner<span class="pl-kos">.</span><span class="pl-en">clone</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>

    gadget_owner<span class="pl-kos">.</span><span class="pl-c1">gadgets</span><span class="pl-kos">.</span><span class="pl-en">borrow_mut</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">push</span><span class="pl-kos">(</span>gadget1<span class="pl-kos">.</span><span class="pl-en">clone</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">downgrade</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    gadget_owner<span class="pl-kos">.</span><span class="pl-c1">gadgets</span><span class="pl-kos">.</span><span class="pl-en">borrow_mut</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">push</span><span class="pl-kos">(</span>gadget2<span class="pl-kos">.</span><span class="pl-en">clone</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">downgrade</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">for</span> gadget_opt <span class="pl-k">in</span> gadget_owner<span class="pl-kos">.</span><span class="pl-c1">gadgets</span><span class="pl-kos">.</span><span class="pl-en">borrow</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">iter</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">let</span> gadget = gadget_opt<span class="pl-kos">.</span><span class="pl-en">upgrade</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">unwrap</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"Gadget {} owned by {}"</span>, gadget.id, gadget.owner.name<span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>

    <span class="pl-c">// This is an unfortunate wart that is a side-effect of the implmentation</span>
    <span class="pl-c">// of new destructor semantics: if the above for-loop is the final expression</span>
    <span class="pl-c">// in the function, the borrow-checker treats the gadget_owner as needing to</span>
    <span class="pl-c">// live past the destruction scope of the function (which of course it does not).</span>
    <span class="pl-c">// To work around this, for now I am inserting a dummy value just so the above</span>
    <span class="pl-c">// for-loop is no longer the final expression in the block.</span>
    <span class="pl-kos">(</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Luckily for <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="54076219" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/21022" data-hovercard-type="pull_request" data-hovercard-url="/rust-lang/rust/pull/21022/hovercard" href="https://github.com/rust-lang/rust/pull/21022">#21022</a>, the coincidence of factors here is not very frequent, which is why I'm not planning on blocking <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="54076219" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/21022" data-hovercard-type="pull_request" data-hovercard-url="/rust-lang/rust/pull/21022/hovercard" href="https://github.com/rust-lang/rust/pull/21022">#21022</a> on resolving this, but instead leaving it as something to address after issues for the alpha have been addressed.</p>
<p dir="auto">(I'm filing this bug before landing the PR so that I can annotation each of the corresponding cases with a FIXME so that I can go back and address them after I get a chance to investigate this properly.)</p>