<p dir="auto">Following Code "suddenly" (TM) gives a compiler panick:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="use std::iter::Iterator;

fn map&lt;T, U, I: Iterator&lt;T&gt;&gt;(fun: |T| -&gt; U, mut iter: I) -&gt; Vec&lt;U&gt; {
    let mut acc = vec![];
    for elt in iter {
        acc.push(fun(elt));
    }
    acc
}

fn main() {
    let x = map(|&amp;x| x + 2, vec![1u,2,3].iter());
    println!(&quot;{}&quot;, x);
}"><pre class="notranslate"><span class="pl-k">use</span> std<span class="pl-kos">::</span>iter<span class="pl-kos">::</span><span class="pl-v">Iterator</span><span class="pl-kos">;</span>

<span class="pl-k">fn</span> <span class="pl-en">map</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">,</span> <span class="pl-smi">U</span><span class="pl-kos">,</span> <span class="pl-smi">I</span><span class="pl-kos">:</span> <span class="pl-smi">Iterator</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span><span class="pl-kos">&gt;</span><span class="pl-kos">(</span>fun<span class="pl-kos">:</span> |<span class="pl-v">T</span>| -&gt; <span class="pl-v">U</span><span class="pl-kos">,</span> <span class="pl-k">mut</span> <span class="pl-s1">iter</span><span class="pl-kos">:</span> <span class="pl-smi">I</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">Vec</span><span class="pl-kos">&lt;</span><span class="pl-smi">U</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">let</span> <span class="pl-k">mut</span> acc = <span class="pl-en">vec</span><span class="pl-en">!</span><span class="pl-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
    <span class="pl-k">for</span> elt <span class="pl-k">in</span> iter <span class="pl-kos">{</span>
        acc<span class="pl-kos">.</span><span class="pl-en">push</span><span class="pl-kos">(</span><span class="pl-en">fun</span><span class="pl-kos">(</span>elt<span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
    acc
<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> x = <span class="pl-en">map</span><span class="pl-kos">(</span>|<span class="pl-c1">&amp;</span>x| x + <span class="pl-c1">2</span><span class="pl-kos">,</span> <span class="pl-en">vec</span><span class="pl-en">!</span><span class="pl-kos">[</span><span class="pl-c1">1</span>u,<span class="pl-c1">2</span>,<span class="pl-c1">3</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-kos">;</span>
    <span class="pl-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"{}"</span>, x<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="RUST_BACKTRACE=1 rustc main.rs
main.rs:12:15: 12:17 error: internal compiler error: Explicit deref of non-derefable type: _
main.rs:12  let x = map(|&amp;x| x + 2, vec![1u,2,3].iter());
                         ^~
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 'Box&lt;Any&gt;', /Users/rustbuild/src/rust-buildbot/slave/nightly-mac/build/src/libsyntax/diagnostic.rs:123

stack backtrace:
   1:        0x10748ec68 - sys::backtrace::write::h2d77a7138a20fe1euut
   2:        0x1074af7c3 - failure::on_fail::h2cc73921e1a3525egKz
   3:        0x10741aeaa - rt::unwind::begin_unwind_inner::h532a687405d73115Hrz
   4:        0x10531bd17 - rt::unwind::begin_unwind::h15459044600925994434
   5:        0x10531bcb0 - rt::unwind::begin_unwind::h15459044600925994434
   6:        0x10479129d - session::Session::span_bug::h716f9146fd05af890mn
   7:        0x104212102 - middle::mem_categorization::MemCategorizationContext&lt;$u{27}t$C$$u{20}TYPER$GT$::cat_pattern::h11154186174841680722
   8:        0x1042022eb - check::regionck::link_pattern::h3d88852e6995969cnte
   9:        0x1041f731d - check::regionck::Rcx&lt;$u{27}a$C$$u{20}$u{27}tcx$GT$::visit_fn_body::h3531a5331ab5d017eRc
  10:        0x1041fd2ae - check::regionck::visit_expr::hb02321dca5467066bgd
  11:        0x104201700 - visit::walk_expr::h3328713682639576950
  12:        0x1041fe1b7 - check::regionck::visit_expr::hb02321dca5467066bgd
  13:        0x1041ff87d - check::regionck::visit_local::hb9b4f9d3743633d9cdd
  14:        0x1041ff975 - visit::walk_block::h8586344471945380718
  15:        0x1041f7349 - check::regionck::Rcx&lt;$u{27}a$C$$u{20}$u{27}tcx$GT$::visit_fn_body::h3531a5331ab5d017eRc
  16:        0x10429aa2b - check::check_bare_fn::h0d1902e379bc0448Vck
  17:        0x104292a13 - check::check_item::h8ef5214e6b2fce2clwk
  18:        0x10450c700 - check_crate::unboxed_closure.43369
  19:        0x104507ead - check_crate::h1dd3d2699b8432207Zy
  20:        0x103c0f1de - driver::phase_3_run_analysis_passes::he4e2174c0e224f23Ita
  21:        0x103bf211e - driver::compile_input::h344438f314911396vba
  22:        0x103d6a9d6 - thunk::F.Invoke&lt;A,$u{20}R$GT$::invoke::h2961138960758151848
  23:        0x103d672d9 - rt::unwind::try::try_fn::h13787826984171194494
  24:        0x107515d29 - rust_try_inner
  25:        0x107515d16 - rust_try
  26:        0x103d679d7 - thunk::F.Invoke&lt;A,$u{20}R$GT$::invoke::h9959509829464533531
  27:        0x10749ec84 - sys::thread::thread_start::h772e1e477575f4beXpw
  28:        0x107d8f2fc - _pthread_body
  29:        0x107d8f279 - _pthread_body"><pre class="notranslate"><code class="notranslate">RUST_BACKTRACE=1 rustc main.rs
main.rs:12:15: 12:17 error: internal compiler error: Explicit deref of non-derefable type: _
main.rs:12  let x = map(|&amp;x| x + 2, vec![1u,2,3].iter());
                         ^~
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 'Box&lt;Any&gt;', /Users/rustbuild/src/rust-buildbot/slave/nightly-mac/build/src/libsyntax/diagnostic.rs:123

stack backtrace:
   1:        0x10748ec68 - sys::backtrace::write::h2d77a7138a20fe1euut
   2:        0x1074af7c3 - failure::on_fail::h2cc73921e1a3525egKz
   3:        0x10741aeaa - rt::unwind::begin_unwind_inner::h532a687405d73115Hrz
   4:        0x10531bd17 - rt::unwind::begin_unwind::h15459044600925994434
   5:        0x10531bcb0 - rt::unwind::begin_unwind::h15459044600925994434
   6:        0x10479129d - session::Session::span_bug::h716f9146fd05af890mn
   7:        0x104212102 - middle::mem_categorization::MemCategorizationContext&lt;$u{27}t$C$$u{20}TYPER$GT$::cat_pattern::h11154186174841680722
   8:        0x1042022eb - check::regionck::link_pattern::h3d88852e6995969cnte
   9:        0x1041f731d - check::regionck::Rcx&lt;$u{27}a$C$$u{20}$u{27}tcx$GT$::visit_fn_body::h3531a5331ab5d017eRc
  10:        0x1041fd2ae - check::regionck::visit_expr::hb02321dca5467066bgd
  11:        0x104201700 - visit::walk_expr::h3328713682639576950
  12:        0x1041fe1b7 - check::regionck::visit_expr::hb02321dca5467066bgd
  13:        0x1041ff87d - check::regionck::visit_local::hb9b4f9d3743633d9cdd
  14:        0x1041ff975 - visit::walk_block::h8586344471945380718
  15:        0x1041f7349 - check::regionck::Rcx&lt;$u{27}a$C$$u{20}$u{27}tcx$GT$::visit_fn_body::h3531a5331ab5d017eRc
  16:        0x10429aa2b - check::check_bare_fn::h0d1902e379bc0448Vck
  17:        0x104292a13 - check::check_item::h8ef5214e6b2fce2clwk
  18:        0x10450c700 - check_crate::unboxed_closure.43369
  19:        0x104507ead - check_crate::h1dd3d2699b8432207Zy
  20:        0x103c0f1de - driver::phase_3_run_analysis_passes::he4e2174c0e224f23Ita
  21:        0x103bf211e - driver::compile_input::h344438f314911396vba
  22:        0x103d6a9d6 - thunk::F.Invoke&lt;A,$u{20}R$GT$::invoke::h2961138960758151848
  23:        0x103d672d9 - rt::unwind::try::try_fn::h13787826984171194494
  24:        0x107515d29 - rust_try_inner
  25:        0x107515d16 - rust_try
  26:        0x103d679d7 - thunk::F.Invoke&lt;A,$u{20}R$GT$::invoke::h9959509829464533531
  27:        0x10749ec84 - sys::thread::thread_start::h772e1e477575f4beXpw
  28:        0x107d8f2fc - _pthread_body
  29:        0x107d8f279 - _pthread_body
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="rustc --version --verbose
rustc 0.13.0-nightly (cc19e3380 2014-12-20 20:00:36 +0000)
binary: rustc
commit-hash: cc19e3380b4b7c63b6f1f79d1dfc213ea00e16cf
commit-date: 2014-12-20 20:00:36 +0000
host: x86_64-apple-darwin
release: 0.13.0-nightly"><pre class="notranslate"><code class="notranslate">rustc --version --verbose
rustc 0.13.0-nightly (cc19e3380 2014-12-20 20:00:36 +0000)
binary: rustc
commit-hash: cc19e3380b4b7c63b6f1f79d1dfc213ea00e16cf
commit-date: 2014-12-20 20:00:36 +0000
host: x86_64-apple-darwin
release: 0.13.0-nightly
</code></pre></div>
<p dir="auto">(probably a duplicate but the other code did not look similar to the one here in my eyes)</p>
<p dir="auto">The following code causes the compiler to fail.  Conversation on IRC suggests this is a known issue, but I could not find this specific error by searching tickets for "Cannot encode region variables" nor any of the hits for "region variables".</p>
<p dir="auto">I apologize if this is a duplicate.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ cat ./vecpeek.rs
extern mod std; // Only for tests.


fn vec_peek&lt;T&gt;(v: &amp;r/[T]) -&gt; Option&lt; (&amp;r/T, &amp;r/[T]) &gt; {
    if v.len() == 0 {
        None
    } else {
        let head = &amp;v[0];
        let tail = v.view(1, v.len());
        Some( (head, tail) )
    }
}


mod tests {
    /* Testing the different storage locations covers features which
     * should be completely orthogonal (ie: that regions work with any
     * storage area, but the language is young, so we do test just
     * in case.
     */
    #[test]
    fn test_peek_empty_stack() {
        let v : &amp;[int] = &amp;[];
        assert (None == vec_peek(v));
    }

    #[test]
    fn test_peek_empty_unique() {
        let v : ~[int] = ~[];
        assert (None == vec_peek(v));
    }

    #[test]
    fn test_peek_empty_managed() {
        let v : @[int] = @[];
        assert (None == vec_peek(v));
    }

    /*
    #[test]
    fn test_peek_full_stack() {
        let v: &amp;[int] = &amp;[1, 2, 3];
        let head: &amp;int = &amp;v[0];
        let tail: &amp;[int] = v.view(1, v.len());

        match

        assert (None == vec_peek(v));
    }
    */
}

$ rustc --test ./vecpeek.rs
error: internal compiler error: Cannot encode region variables

$ rustc --version
rustc 0.5 (07edf90 2012-10-13 05:57:13 -0700)
host: x86_64-unknown-linux-gnu"><pre class="notranslate"><code class="notranslate">$ cat ./vecpeek.rs
extern mod std; // Only for tests.


fn vec_peek&lt;T&gt;(v: &amp;r/[T]) -&gt; Option&lt; (&amp;r/T, &amp;r/[T]) &gt; {
    if v.len() == 0 {
        None
    } else {
        let head = &amp;v[0];
        let tail = v.view(1, v.len());
        Some( (head, tail) )
    }
}


mod tests {
    /* Testing the different storage locations covers features which
     * should be completely orthogonal (ie: that regions work with any
     * storage area, but the language is young, so we do test just
     * in case.
     */
    #[test]
    fn test_peek_empty_stack() {
        let v : &amp;[int] = &amp;[];
        assert (None == vec_peek(v));
    }

    #[test]
    fn test_peek_empty_unique() {
        let v : ~[int] = ~[];
        assert (None == vec_peek(v));
    }

    #[test]
    fn test_peek_empty_managed() {
        let v : @[int] = @[];
        assert (None == vec_peek(v));
    }

    /*
    #[test]
    fn test_peek_full_stack() {
        let v: &amp;[int] = &amp;[1, 2, 3];
        let head: &amp;int = &amp;v[0];
        let tail: &amp;[int] = v.view(1, v.len());

        match

        assert (None == vec_peek(v));
    }
    */
}

$ rustc --test ./vecpeek.rs
error: internal compiler error: Cannot encode region variables

$ rustc --version
rustc 0.5 (07edf90 2012-10-13 05:57:13 -0700)
host: x86_64-unknown-linux-gnu
</code></pre></div>