<p dir="auto">In the playpen (Mode: Debug, Channel: Nightly)</p>
<p dir="auto">I was playing with associated constants when this code made the compiler panic:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#![feature(associated_consts)]

use ::std::marker::PhantomData;

trait Num {
    const VAL: usize;
    fn val() -&gt; usize;
}

struct N1;
impl Num for N1 {
    const VAL: usize = 1;
    fn val() -&gt; usize { N1::VAL }
}

struct Arr&lt;S: Num&gt; {
    ty: PhantomData&lt;S&gt;,
    data: [i32; S::VAL]
}


fn main() {
}"><pre class="notranslate"><span class="pl-c1">#!<span class="pl-kos">[</span>feature<span class="pl-kos">(</span>associated_consts<span class="pl-kos">)</span><span class="pl-kos">]</span></span>

<span class="pl-k">use</span> <span class="pl-kos">::</span>std<span class="pl-kos">::</span>marker<span class="pl-kos">::</span><span class="pl-v">PhantomData</span><span class="pl-kos">;</span>

<span class="pl-k">trait</span> <span class="pl-smi">Num</span> <span class="pl-kos">{</span>
    <span class="pl-k">const</span> <span class="pl-v">VAL</span><span class="pl-kos">:</span> <span class="pl-smi">usize</span><span class="pl-kos">;</span>
    <span class="pl-k">fn</span> <span class="pl-en">val</span><span class="pl-kos">(</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">usize</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">struct</span> <span class="pl-smi">N1</span><span class="pl-kos">;</span>
<span class="pl-k">impl</span> <span class="pl-smi">Num</span> <span class="pl-k">for</span> <span class="pl-smi">N1</span> <span class="pl-kos">{</span>
    <span class="pl-k">const</span> <span class="pl-v">VAL</span><span class="pl-kos">:</span> <span class="pl-smi">usize</span> = <span class="pl-c1">1</span><span class="pl-kos">;</span>
    <span class="pl-k">fn</span> <span class="pl-en">val</span><span class="pl-kos">(</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">usize</span> <span class="pl-kos">{</span> <span class="pl-smi">N1</span><span class="pl-kos">::</span><span class="pl-v">VAL</span> <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-k">struct</span> <span class="pl-smi">Arr</span><span class="pl-kos">&lt;</span><span class="pl-smi">S</span><span class="pl-kos">:</span> <span class="pl-smi">Num</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-c1">ty</span><span class="pl-kos">:</span> <span class="pl-smi">PhantomData</span><span class="pl-kos">&lt;</span><span class="pl-smi">S</span><span class="pl-kos">&gt;</span><span class="pl-kos">,</span>
    <span class="pl-c1">data</span><span class="pl-kos">:</span> <span class="pl-kos">[</span><span class="pl-smi">i32</span><span class="pl-kos">;</span> <span class="pl-smi">S</span><span class="pl-kos">::</span><span class="pl-v">VAL</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>
<p dir="auto">With error message:</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: DefTyParam(TypeSpace, 0, DefId { krate: 0, node: 35 }, &quot;S&quot;(72)), last_private: LastMod(AllPublic), depth: 1 }', ../src/librustc/middle/def.rs:81


playpen: application terminated with error code 101"><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: DefTyParam(TypeSpace, 0, DefId { krate: 0, node: 35 }, "S"(72)), last_private: LastMod(AllPublic), depth: 1 }', ../src/librustc/middle/def.rs:81


playpen: application terminated with error code 101
</code></pre></div>
<p dir="auto">Playpen link: <a href="http://is.gd/dE8jbq" rel="nofollow">http://is.gd/dE8jbq</a></p>
<p dir="auto">The line which confuses the compiler is this one:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    data: [i32; S::VAL]"><pre class="notranslate">    data<span class="pl-kos">:</span> <span class="pl-kos">[</span>i32<span class="pl-kos">;</span> <span class="pl-smi">S</span><span class="pl-kos">::</span><span class="pl-v">VAL</span><span class="pl-kos">]</span><span class="pl-kos"></span></pre></div>
<p dir="auto">Without it, the program compiles just fine.</p>
<p dir="auto">The following code causes an ICE using the latest nightly.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" #![feature(associated_consts)] 

pub trait Test {
    const LENGTH: usize;

    fn method(array: [i32; Self::LENGTH]) {    }

}

fn main() { }"><pre class="notranslate"><code class="notranslate"> #![feature(associated_consts)] 

pub trait Test {
    const LENGTH: usize;

    fn method(array: [i32; Self::LENGTH]) {    }

}

fn main() { }
</code></pre></div>
<p dir="auto">Running with RUST_BACKTRACE=1 gives</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="thread 'rustc' panicked at 'path not fully resolved: PathResolution { base_def: DefSelfTy(Some(DefId { krate: 0, node: 4 }Test), None), last_private: LastMod(AllPublic), depth: 1 }', ../src/librustc/middle/def.rs:81

stack backtrace:
   1:     0x7fcb00fecdde - sys::backtrace::write::h69183b7c98049b30wqs
   2:     0x7fcb00ff4a44 - panicking::on_panic::h2c3150d5b218c447i8w
   3:     0x7fcb00fb77ee - rt::unwind::begin_unwind_inner::hf9bdd075490425c8WNw
   4:     0x7fcb00fb851c - rt::unwind::begin_unwind_fmt::h6a9238aa2a13c0892Mw
   5:     0x7fcaff01d717 - middle::const_eval::eval_const_expr_with_substs::h14003455026798805522
   6:     0x7fcafefca59b - middle::const_eval::eval_const_expr_partial::hfb624d4880a32ba3IGk
   7:     0x7fcb007d5cf2 - astconv::ast_ty_to_ty::heeb2edb80837d1162Qv
   8:     0x7fcb008317ee - vec::Vec&lt;T&gt;.FromIterator&lt;T&gt;::from_iter::h3785597557409810636
   9:     0x7fcb00830d56 - astconv::ty_of_method_or_bare_fn::h7fc2677ba2149d77I6v
  10:     0x7fcb00849e9b - collect::convert_method::h2213f9f8b79b70d9Fsx
  11:     0x7fcb00838e74 - collect::convert_item::hbcf9d38ceb0aafd0cIx
  12:     0x7fcb00833917 - collect::collect_item_types::hacdb13c97b5df6d8zPw
  13:     0x7fcb00880a59 - check_crate::h0321f1e753acbcf9WWC
  14:     0x7fcb01555cd9 - driver::phase_3_run_analysis_passes::closure.15875
  15:     0x7fcb0155461b - middle::ty::ctxt&lt;'tcx&gt;::create_and_enter::h9079099211582893073
  16:     0x7fcb0154f5c1 - driver::phase_3_run_analysis_passes::h12132907910932298086
  17:     0x7fcb0152e83c - driver::compile_input::h3a475b0b9259362fTba
  18:     0x7fcb01614bd3 - run_compiler::h2cc1d87c2af5b2f0A7b
  19:     0x7fcb016125ae - boxed::F.FnBox&lt;A&gt;::call_box::h6791803627395147597
  20:     0x7fcb01611df9 - rt::unwind::try::try_fn::h10416075533806878094
  21:     0x7fcb0106f738 - rust_try_inner
  22:     0x7fcb0106f725 - rust_try
  23:     0x7fcb00fe00f7 - rt::unwind::try::inner_try::h6181b0bb7448f551PJw
  24:     0x7fcb0161200b - boxed::F.FnBox&lt;A&gt;::call_box::h6862050082343839214
  25:     0x7fcb00ff36a1 - sys::thread::Thread::new::thread_start::hadfe7238e1724c34CTv
  26:     0x7fcafac580a3 - start_thread
  27:     0x7fcb00c3e04c - clone
  28:                0x0 - &lt;unknown&gt;"><pre class="notranslate"><code class="notranslate">thread 'rustc' panicked at 'path not fully resolved: PathResolution { base_def: DefSelfTy(Some(DefId { krate: 0, node: 4 }Test), None), last_private: LastMod(AllPublic), depth: 1 }', ../src/librustc/middle/def.rs:81

stack backtrace:
   1:     0x7fcb00fecdde - sys::backtrace::write::h69183b7c98049b30wqs
   2:     0x7fcb00ff4a44 - panicking::on_panic::h2c3150d5b218c447i8w
   3:     0x7fcb00fb77ee - rt::unwind::begin_unwind_inner::hf9bdd075490425c8WNw
   4:     0x7fcb00fb851c - rt::unwind::begin_unwind_fmt::h6a9238aa2a13c0892Mw
   5:     0x7fcaff01d717 - middle::const_eval::eval_const_expr_with_substs::h14003455026798805522
   6:     0x7fcafefca59b - middle::const_eval::eval_const_expr_partial::hfb624d4880a32ba3IGk
   7:     0x7fcb007d5cf2 - astconv::ast_ty_to_ty::heeb2edb80837d1162Qv
   8:     0x7fcb008317ee - vec::Vec&lt;T&gt;.FromIterator&lt;T&gt;::from_iter::h3785597557409810636
   9:     0x7fcb00830d56 - astconv::ty_of_method_or_bare_fn::h7fc2677ba2149d77I6v
  10:     0x7fcb00849e9b - collect::convert_method::h2213f9f8b79b70d9Fsx
  11:     0x7fcb00838e74 - collect::convert_item::hbcf9d38ceb0aafd0cIx
  12:     0x7fcb00833917 - collect::collect_item_types::hacdb13c97b5df6d8zPw
  13:     0x7fcb00880a59 - check_crate::h0321f1e753acbcf9WWC
  14:     0x7fcb01555cd9 - driver::phase_3_run_analysis_passes::closure.15875
  15:     0x7fcb0155461b - middle::ty::ctxt&lt;'tcx&gt;::create_and_enter::h9079099211582893073
  16:     0x7fcb0154f5c1 - driver::phase_3_run_analysis_passes::h12132907910932298086
  17:     0x7fcb0152e83c - driver::compile_input::h3a475b0b9259362fTba
  18:     0x7fcb01614bd3 - run_compiler::h2cc1d87c2af5b2f0A7b
  19:     0x7fcb016125ae - boxed::F.FnBox&lt;A&gt;::call_box::h6791803627395147597
  20:     0x7fcb01611df9 - rt::unwind::try::try_fn::h10416075533806878094
  21:     0x7fcb0106f738 - rust_try_inner
  22:     0x7fcb0106f725 - rust_try
  23:     0x7fcb00fe00f7 - rt::unwind::try::inner_try::h6181b0bb7448f551PJw
  24:     0x7fcb0161200b - boxed::F.FnBox&lt;A&gt;::call_box::h6862050082343839214
  25:     0x7fcb00ff36a1 - sys::thread::Thread::new::thread_start::hadfe7238e1724c34CTv
  26:     0x7fcafac580a3 - start_thread
  27:     0x7fcb00c3e04c - clone
  28:                0x0 - &lt;unknown&gt;
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ rustc --version --verbose
rustc 1.3.0-nightly (16f64c388 2015-07-09)
binary: rustc
commit-hash: 16f64c38803e820fc20a669987395e663ced1387
commit-date: 2015-07-09
host: x86_64-unknown-linux-gnu
release: 1.3.0-nightly"><pre class="notranslate"><code class="notranslate">$ rustc --version --verbose
rustc 1.3.0-nightly (16f64c388 2015-07-09)
binary: rustc
commit-hash: 16f64c38803e820fc20a669987395e663ced1387
commit-date: 2015-07-09
host: x86_64-unknown-linux-gnu
release: 1.3.0-nightly
</code></pre></div>
<p dir="auto">This might be a duplicate of <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="71846185" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/24938" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/24938/hovercard" href="https://github.com/rust-lang/rust/issues/24938">#24938</a> (although that issue is now closed) or <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="89335604" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/26402" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/26402/hovercard" href="https://github.com/rust-lang/rust/issues/26402">#26402</a>.</p>