<p dir="auto">While trying to figure out how to properly implement <code class="notranslate">FnMut</code> for this struct I ran into this ICE. I still don't know how to properly implement it, chances are I was doing it wrong, but I imagine that an ICE isn't expected in any case so I decided to post this up in case it hasn't been brought up.</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#![feature(unboxed_closures)]

struct VecEnv&lt;'a&gt; {
    vec: Vec&lt;i32&gt;,
}

impl&lt;'a&gt; FnMut(&amp;mut i32, &amp;i32) -&gt; i32 for VecEnv&lt;'a&gt; {
    extern &quot;rust-call&quot; fn call_mut(&amp;mut self, (output, text): (&amp;mut i32, &amp;i32)) -&gt; i32 {
        println!(&quot;CLOSURE&quot;);
        1i32
    }
}

fn main() {}"><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">struct</span> <span class="pl-smi">VecEnv</span><span class="pl-kos">&lt;</span><span class="pl-c1">'</span><span class="pl-ent">a</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-c1">vec</span><span class="pl-kos">:</span> <span class="pl-smi">Vec</span><span class="pl-kos">&lt;</span><span class="pl-smi">i32</span><span class="pl-kos">&gt;</span><span class="pl-kos">,</span>
<span class="pl-kos">}</span>

<span class="pl-k">impl</span><span class="pl-kos">&lt;</span><span class="pl-c1">'</span><span class="pl-ent">a</span><span class="pl-kos">&gt;</span> <span class="pl-smi">FnMut</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-k">mut</span> <span class="pl-smi">i32</span><span class="pl-kos">,</span> <span class="pl-c1">&amp;</span><span class="pl-smi">i32</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">i32</span> for <span class="pl-smi">VecEnv</span><span class="pl-kos">&lt;</span><span class="pl-c1">'</span><span class="pl-ent">a</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">extern</span> <span class="pl-s">"rust-call"</span> <span class="pl-k">fn</span> <span class="pl-en">call_mut</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-k">mut</span> <span class="pl-smi">self</span><span class="pl-kos">,</span> <span class="pl-kos">(</span>output<span class="pl-kos">,</span> text<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">i32</span><span class="pl-kos">,</span> <span class="pl-c1">&amp;</span><span class="pl-smi">i32</span><span class="pl-kos">)</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">i32</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">"CLOSURE"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-c1">1i32</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>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'assertion failed: !generic_bounds.has_escaping_regions()', /build/rust-git/src/rust/src/librustc_typeck/check/mod.rs:1784"><pre class="notranslate"><code class="notranslate">error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'assertion failed: !generic_bounds.has_escaping_regions()', /build/rust-git/src/rust/src/librustc_typeck/check/mod.rs:1784
</code></pre></div>
<p dir="auto"><a href="http://is.gd/AwHrNx" rel="nofollow">playpen</a></p>
<p dir="auto">Adding a sized constraint to a trait caused an internal compile error.</p>
<p dir="auto">I tried this code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="trait A: Sized {
    type N:One;
    fn new(x:Self::N) -&gt; Self;

    fn x() -&gt; Self&lt;N=Self::N&gt; {
        Self::new(Self::N::one())
    }
}

trait One {
    fn one() -&gt; Self;
}

impl One for i32 {
    fn one() -&gt; i32 {
        1i32
    }
}

impl A for B {
    type N = i32;
     fn new(x:i32) -&gt; B {
        B { x: x }
    }
}

struct B {
    x:i32
}

fn main() {
    let b = B::new(5i32);
    println!(&quot;b.x: {}&quot;, b.x )
}"><pre class="notranslate"><code class="notranslate">trait A: Sized {
    type N:One;
    fn new(x:Self::N) -&gt; Self;

    fn x() -&gt; Self&lt;N=Self::N&gt; {
        Self::new(Self::N::one())
    }
}

trait One {
    fn one() -&gt; Self;
}

impl One for i32 {
    fn one() -&gt; i32 {
        1i32
    }
}

impl A for B {
    type N = i32;
     fn new(x:i32) -&gt; B {
        B { x: x }
    }
}

struct B {
    x:i32
}

fn main() {
    let b = B::new(5i32);
    println!("b.x: {}", b.x )
}
</code></pre></div>
<p dir="auto">Removing the sized constraint from <code class="notranslate">A</code> no longer as a internal compile error, and fails to compile with the error</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="sized_trait.rs:5:15: 5:30 error: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
sized_trait.rs:5     fn x() -&gt; Self&lt;N=Self::N&gt; {
^
sized_trait.rs:5:15: 5:30 note: `Self` does not have a constant size known at compile-time
sized_trait.rs:5     fn x() -&gt; Self&lt;N=Self::N&gt; {
^
error: aborting due to previous error"><pre class="notranslate"><code class="notranslate">sized_trait.rs:5:15: 5:30 error: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
sized_trait.rs:5     fn x() -&gt; Self&lt;N=Self::N&gt; {
^
sized_trait.rs:5:15: 5:30 note: `Self` does not have a constant size known at compile-time
sized_trait.rs:5     fn x() -&gt; Self&lt;N=Self::N&gt; {
^
error: aborting due to previous error
</code></pre></div>
<p dir="auto">Removing <code class="notranslate">fn x() -&gt; Self&lt;N=Self::N&gt;</code> from <code class="notranslate">trait A</code> causes a successful compile.</p>
<h2 dir="auto">Meta</h2>
<p dir="auto"><code class="notranslate">rustc --version --verbose</code>:<br>
rustc 1.0.0-beta.2 (<a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/rust-lang/rust/commit/e9080ec39d9a44eb0773d648b348575b19f655e5/hovercard" href="https://github.com/rust-lang/rust/commit/e9080ec39d9a44eb0773d648b348575b19f655e5"><tt>e9080ec</tt></a> 2015-04-16) (built 2015-04-16)<br>
binary: rustc<br>
commit-hash: <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/rust-lang/rust/commit/e9080ec39d9a44eb0773d648b348575b19f655e5/hovercard" href="https://github.com/rust-lang/rust/commit/e9080ec39d9a44eb0773d648b348575b19f655e5"><tt>e9080ec</tt></a><br>
commit-date: 2015-04-16<br>
build-date: 2015-04-16<br>
host: x86_64-unknown-linux-gnu<br>
release: 1.0.0-beta.2</p>
<p dir="auto">Backtrace:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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 'path not fully resolved: PathResolution { base_def: DefSelfTy(Some(DefId { krate: 0, node: 4 }), None), last_private: LastMod(AllPublic), depth: 1 }', /home/rustbuild/src/rust-buildbot/slave/beta-dist-rustc-linux/build/src/librustc/middle/def.rs:80"><pre class="notranslate"><code class="notranslate">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 'path not fully resolved: PathResolution { base_def: DefSelfTy(Some(DefId { krate: 0, node: 4 }), None), last_private: LastMod(AllPublic), depth: 1 }', /home/rustbuild/src/rust-buildbot/slave/beta-dist-rustc-linux/build/src/librustc/middle/def.rs:80
</code></pre></div>
<p dir="auto">stack backtrace:<br>
1:     0x7f4ce4435439 - sys::backtrace::write::he2e34ba2c33dc0e30Us<br>
2:     0x7f4ce443d0f6 - panicking::on_panic::hc9625174f6ab8ee8fix<br>
3:     0x7f4ce43fb182 - rt::unwind::begin_unwind_inner::h3ab4e1f5d89ab81bpXw<br>
4:     0x7f4ce43fb44c - rt::unwind::begin_unwind_fmt::haff11c8aa28ec8b23Vw<br>
5:     0x7f4ce2271db6 - middle::def::PathResolution::full_def::h74a01ccebde3cb12mZl<br>
6:     0x7f4ce3897e4e - PrivacyVisitor&lt;'a, 'tcx&gt;::check_path::h7dab5d16c75af8c4X4a<br>
7:     0x7f4ce3898ed7 - PrivacyVisitor&lt;'a, 'tcx&gt;.Visitor&lt;'v&gt;::visit_path::hb9a2f24773dbb8d9ctb<br>
8:     0x7f4ce3899022 - visit::walk_path::h7066235731909768411<br>
9:     0x7f4ce389aa99 - visit::Visitor::visit_fn::h17785043978168098476<br>
10:     0x7f4ce389b5da - visit::walk_trait_item::h1977003431506782162<br>
11:     0x7f4ce3898d7f - PrivacyVisitor&lt;'a, 'tcx&gt;.Visitor&lt;'v&gt;::visit_item::hf1bd234520341cbexdb<br>
12:     0x7f4ce389f7fb - check_crate::hb8e3f1bb5ec19bf6EVb<br>
13:     0x7f4ce499bfc3 - driver::phase_3_run_analysis_passes::h5a432074c589df71nGa<br>
14:     0x7f4ce497ccf5 - driver::compile_input::h534dde66bedcbe27Qba<br>
15:     0x7f4ce4a3d561 - run_compiler::hcc529c6d73620eadz4b<br>
16:     0x7f4ce4a3b1b2 - boxed::F.FnBox::call_box::h8768627190356120502<br>
17:     0x7f4ce4a3a6e9 - rt::unwind::try::try_fn::h4698797487832078877<br>
18:     0x7f4ce44b4018 - rust_try_inner<br>
19:     0x7f4ce44b4005 - rust_try<br>
20:     0x7f4ce4a3a998 - boxed::F.FnBox::call_box::h562643224173615142<br>
21:     0x7f4ce443bfe1 - sys:<g-emoji class="g-emoji" alias="thread" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f9f5.png">🧵</g-emoji>:create::thread_start::he373f01c0b872a8fwgw<br>
22:     0x7f4cdeccc181 - start_thread<br>
23:     0x7f4ce407547c - __clone<br>
24:                0x0 - </p>