<p dir="auto"><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/bstrie/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/bstrie">@bstrie</a>  So, this code raises an assertion in llvm when compiling with -g. Without -g it works fine.</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#![feature(unboxed_closures)]

pub struct A;

impl A {
    pub fn foo(&amp;self, f: Box&lt;Fn&lt;(), ()&gt; + 'static&gt;) -&gt;
            Box&lt;Fn&lt;(), ()&gt; + 'static&gt; {
        (box move |&amp;:| {
            (*f).call(())
        })
    }
}"><pre class="notranslate"><span class="pl-c1">#!<span class="pl-kos">[</span>feature<span class="pl-kos">(</span>unboxed_closures<span class="pl-kos">)</span><span class="pl-kos">]</span></span>

<span class="pl-k">pub</span> <span class="pl-k">struct</span> <span class="pl-smi">A</span><span class="pl-kos">;</span>

<span class="pl-k">impl</span> <span class="pl-smi">A</span> <span class="pl-kos">{</span>
    <span class="pl-k">pub</span> <span class="pl-k">fn</span> <span class="pl-en">foo</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-smi">self</span><span class="pl-kos">,</span> <span class="pl-s1">f</span><span class="pl-kos">:</span> <span class="pl-smi">Box</span><span class="pl-kos">&lt;</span><span class="pl-smi">Fn</span><span class="pl-kos">&lt;</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">&gt;</span> + <span class="pl-c1">'</span><span class="pl-ent">static</span><span class="pl-kos">&gt;</span><span class="pl-kos">)</span> -&gt;
            <span class="pl-smi">Box</span><span class="pl-kos">&lt;</span><span class="pl-smi">Fn</span><span class="pl-kos">&lt;</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">&gt;</span> + <span class="pl-c1">'</span><span class="pl-ent">static</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
        <span class="pl-kos">(</span>box <span class="pl-k">move</span> |<span class="pl-c1">&amp;</span><span class="pl-kos">:</span>| <span class="pl-kos">{</span>
            <span class="pl-kos">(</span><span class="pl-c1">*</span>f<span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">call</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-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Raised assertion is</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="rustc: /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/llvm/lib/IR/Instructions.cpp:1086: void llvm::StoreInst::AssertOK(): Assertion `getOperand(0)-&gt;getType() == cast&lt;PointerType&gt;(getOperand(1)-&gt;getType())-&gt;getElementType() &amp;&amp; &quot;Ptr must be a pointer to Val type!&quot;' failed.
[1]    1800 abort (core dumped)  rustc --crate-type lib test.rs -g"><pre class="notranslate"><code class="notranslate">rustc: /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/llvm/lib/IR/Instructions.cpp:1086: void llvm::StoreInst::AssertOK(): Assertion `getOperand(0)-&gt;getType() == cast&lt;PointerType&gt;(getOperand(1)-&gt;getType())-&gt;getElementType() &amp;&amp; "Ptr must be a pointer to Val type!"' failed.
[1]    1800 abort (core dumped)  rustc --crate-type lib test.rs -g
</code></pre></div>
<p dir="auto">Edit: reduced code more</p>
<p dir="auto">rust version: rustc 0.12.0-pre-nightly (<a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/rust-lang/rust/commit/09abbbdafc08654b78c8529c1a0c03d628bb2d91/hovercard" href="https://github.com/rust-lang/rust/commit/09abbbdafc08654b78c8529c1a0c03d628bb2d91"><tt>09abbbd</tt></a> 2014-09-11 00:05:41 +0000)</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Assertion failed: (getOperand(0)-&gt;getType() == cast&lt;PointerType&gt;(getOperand(1)-&gt;getType())-&gt;getElementType() &amp;&amp; &quot;Ptr must be a pointer to Val type!&quot;), function AssertOK, file /Users/rustbuild/src/rust-buildbot/slave/nightly-mac/build/src/llvm/lib/IR/Instructions.cpp, line 1085."><pre class="notranslate"><code class="notranslate">Assertion failed: (getOperand(0)-&gt;getType() == cast&lt;PointerType&gt;(getOperand(1)-&gt;getType())-&gt;getElementType() &amp;&amp; "Ptr must be a pointer to Val type!"), function AssertOK, file /Users/rustbuild/src/rust-buildbot/slave/nightly-mac/build/src/llvm/lib/IR/Instructions.cpp, line 1085.
</code></pre></div>
<p dir="auto">code to reproduce:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="trait Tr: Clone {
  fn clone_to_tobj(&amp;self) -&gt; Box&lt;Tr&gt; {
    return box self.clone()
  }
}

#[deriving(Clone)]
struct A;
impl Tr for A {
}


fn main() {
   let a: Box&lt;Tr&gt; = box A;
}"><pre class="notranslate"><code class="notranslate">trait Tr: Clone {
  fn clone_to_tobj(&amp;self) -&gt; Box&lt;Tr&gt; {
    return box self.clone()
  }
}

#[deriving(Clone)]
struct A;
impl Tr for A {
}


fn main() {
   let a: Box&lt;Tr&gt; = box A;
}
</code></pre></div>
<p dir="auto">but this compiles fine</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="trait Tr: Clone {
  fn clone_to_tobj(&amp;self) -&gt; Box&lt;Tr&gt; {
    box self.clone()
  }
}

#[deriving(Clone)]
struct A;
impl Tr for A {
}


fn main() {
   let a: Box&lt;Tr&gt; = box A;
}"><pre class="notranslate"><code class="notranslate">trait Tr: Clone {
  fn clone_to_tobj(&amp;self) -&gt; Box&lt;Tr&gt; {
    box self.clone()
  }
}

#[deriving(Clone)]
struct A;
impl Tr for A {
}


fn main() {
   let a: Box&lt;Tr&gt; = box A;
}
</code></pre></div>