<p dir="auto">I have two similar pieces of code that I would expect to behave in a similar fashion.  The first piece of code compiles and functions properly:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="trait HasId {
    fn id() -&gt; i32;
}

trait Foo {}

impl HasId for Foo {
    fn id() -&gt; i32 { 1 }
}

trait Bar {}

impl HasId for Bar {
    fn id() -&gt; i32 { 2 }
}

fn print_id&lt;T: HasId + ?Sized&gt;() {
    println!(&quot;{}&quot;, &lt;T as HasId&gt;::id());
}

fn main() {
    print_id::&lt;Foo&gt;();
    print_id::&lt;Bar&gt;();
}"><pre class="notranslate"><span class="pl-k">trait</span> <span class="pl-smi">HasId</span> <span class="pl-kos">{</span>
    <span class="pl-k">fn</span> <span class="pl-en">id</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-kos">}</span>

<span class="pl-k">trait</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>

<span class="pl-k">impl</span> <span class="pl-smi">HasId</span> <span class="pl-k">for</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
    <span class="pl-k">fn</span> <span class="pl-en">id</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-c1">1</span> <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-k">trait</span> <span class="pl-smi">Bar</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>

<span class="pl-k">impl</span> <span class="pl-smi">HasId</span> <span class="pl-k">for</span> <span class="pl-smi">Bar</span> <span class="pl-kos">{</span>
    <span class="pl-k">fn</span> <span class="pl-en">id</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-c1">2</span> <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-k">fn</span> <span class="pl-en">print_id</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">:</span> <span class="pl-smi">HasId</span> + ?<span class="pl-smi">Sized</span><span class="pl-kos">&gt;</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>, &lt;<span class="pl-v">T</span> <span class="pl-k">as</span> <span class="pl-v">HasId</span>&gt;::id<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">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-en">print_id</span><span class="pl-kos">::</span><span class="pl-kos">&lt;</span><span class="pl-smi">Foo</span><span class="pl-kos">&gt;</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-en">print_id</span><span class="pl-kos">::</span><span class="pl-kos">&lt;</span><span class="pl-smi">Bar</span><span class="pl-kos">&gt;</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">The second piece of code replaces the static methods with an associated constant:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#![feature(associated_consts)]

trait HasId {
    const ID: i32;
}

trait Foo {}

impl HasId for Foo {
    const ID: i32 = 1;
}

trait Bar {}

impl HasId for Bar {
    const ID: i32 = 2;
}

fn print_id&lt;T: HasId + ?Sized&gt;() {
    println!(&quot;{}&quot;, &lt;T as HasId&gt;::ID);
}

fn main() {
    print_id::&lt;Foo&gt;();
    print_id::&lt;Bar&gt;();
}"><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">trait</span> <span class="pl-smi">HasId</span> <span class="pl-kos">{</span>
    <span class="pl-k">const</span> <span class="pl-v">ID</span><span class="pl-kos">:</span> <span class="pl-smi">i32</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">trait</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>

<span class="pl-k">impl</span> <span class="pl-smi">HasId</span> <span class="pl-k">for</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
    <span class="pl-k">const</span> <span class="pl-v">ID</span><span class="pl-kos">:</span> <span class="pl-smi">i32</span> = <span class="pl-c1">1</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">trait</span> <span class="pl-smi">Bar</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>

<span class="pl-k">impl</span> <span class="pl-smi">HasId</span> <span class="pl-k">for</span> <span class="pl-smi">Bar</span> <span class="pl-kos">{</span>
    <span class="pl-k">const</span> <span class="pl-v">ID</span><span class="pl-kos">:</span> <span class="pl-smi">i32</span> = <span class="pl-c1">2</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">fn</span> <span class="pl-en">print_id</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">:</span> <span class="pl-smi">HasId</span> + ?<span class="pl-smi">Sized</span><span class="pl-kos">&gt;</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>, &lt;<span class="pl-v">T</span> <span class="pl-k">as</span> <span class="pl-v">HasId</span>&gt;::<span class="pl-v">ID</span><span class="pl-kos">)</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-en">print_id</span><span class="pl-kos">::</span><span class="pl-kos">&lt;</span><span class="pl-smi">Foo</span><span class="pl-kos">&gt;</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-en">print_id</span><span class="pl-kos">::</span><span class="pl-kos">&lt;</span><span class="pl-smi">Bar</span><span class="pl-kos">&gt;</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">This code fails to compile with the following ICE:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;anon&gt;:4:5: 4:19 error: internal compiler error: Encountered error `Unimplemented` when trying to select an implementation for constant trait item reference.
&lt;anon&gt;:4     const ID: i32;
             ^~~~~~~~~~~~~~
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 'Box&lt;Any&gt;', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libsyntax/diagnostic.rs:170"><pre class="notranslate"><code class="notranslate">&lt;anon&gt;:4:5: 4:19 error: internal compiler error: Encountered error `Unimplemented` when trying to select an implementation for constant trait item reference.
&lt;anon&gt;:4     const ID: i32;
             ^~~~~~~~~~~~~~
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 'Box&lt;Any&gt;', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libsyntax/diagnostic.rs:170
</code></pre></div>
<p dir="auto">What's interesting is that the following code does compile:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#![feature(associated_consts)]

trait HasId {
    const ID: i32;
}

trait Foo {}

impl HasId for Foo {
    const ID: i32 = 1;
}

trait Bar {}

impl HasId for Bar {
    const ID: i32 = 2;
}

fn main() {
    println!(&quot;{}&quot;, &lt;Foo as HasId&gt;::ID);
    println!(&quot;{}&quot;, &lt;Bar as HasId&gt;::ID);
}"><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">trait</span> <span class="pl-smi">HasId</span> <span class="pl-kos">{</span>
    <span class="pl-k">const</span> <span class="pl-v">ID</span><span class="pl-kos">:</span> <span class="pl-smi">i32</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">trait</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>

<span class="pl-k">impl</span> <span class="pl-smi">HasId</span> <span class="pl-k">for</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
    <span class="pl-k">const</span> <span class="pl-v">ID</span><span class="pl-kos">:</span> <span class="pl-smi">i32</span> = <span class="pl-c1">1</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">trait</span> <span class="pl-smi">Bar</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>

<span class="pl-k">impl</span> <span class="pl-smi">HasId</span> <span class="pl-k">for</span> <span class="pl-smi">Bar</span> <span class="pl-kos">{</span>
    <span class="pl-k">const</span> <span class="pl-v">ID</span><span class="pl-kos">:</span> <span class="pl-smi">i32</span> = <span class="pl-c1">2</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-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"{}"</span>, &lt;<span class="pl-v">Foo</span> <span class="pl-k">as</span> <span class="pl-v">HasId</span>&gt;::<span class="pl-v">ID</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>, &lt;<span class="pl-v">Bar</span> <span class="pl-k">as</span> <span class="pl-v">HasId</span>&gt;::<span class="pl-v">ID</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">So it would appear as if this behavior is related to the use of a generic in the UFCS resolution for the associated constant.</p>
<p dir="auto">The compiler fails to compile this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#![feature(associated_consts)]

pub trait Foo {
    const MIN: i32;

    fn get_min() -&gt; i32 {
        Self::MIN
    }
}

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

pub trait Foo {
    const MIN: i32;

    fn get_min() -&gt; i32 {
        Self::MIN
    }
}

fn main() {}
</code></pre></div>
<p dir="auto">The error message:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="main.rs:4:5: 4:20 error: internal compiler error: Encountered error `Unimplemented` when trying to select an implementation for constant trait item reference.
main.rs:4     const MIN: i32;
              ^~~~~~~~~~~~~~~
thread 'rustc' panicked at 'Box&lt;Any&gt;', /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/libsyntax/diagnostic.rs:170"><pre class="notranslate"><code class="notranslate">main.rs:4:5: 4:20 error: internal compiler error: Encountered error `Unimplemented` when trying to select an implementation for constant trait item reference.
main.rs:4     const MIN: i32;
              ^~~~~~~~~~~~~~~
thread 'rustc' panicked at 'Box&lt;Any&gt;', /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/libsyntax/diagnostic.rs:170
</code></pre></div>
<h2 dir="auto">Meta</h2>
<p dir="auto"><code class="notranslate">rustc --version --verbose</code>:<br>
rustc 1.1.0-nightly (<a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/rust-lang/rust/commit/c4b23aec4c5ddf32df1e0ba3cc23212327cd8b1f/hovercard" href="https://github.com/rust-lang/rust/commit/c4b23aec4c5ddf32df1e0ba3cc23212327cd8b1f"><tt>c4b23ae</tt></a> 2015-04-29) (built 2015-04-28)<br>
binary: rustc<br>
commit-hash: <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/rust-lang/rust/commit/c4b23aec4c5ddf32df1e0ba3cc23212327cd8b1f/hovercard" href="https://github.com/rust-lang/rust/commit/c4b23aec4c5ddf32df1e0ba3cc23212327cd8b1f"><tt>c4b23ae</tt></a><br>
commit-date: 2015-04-29<br>
build-date: 2015-04-28<br>
host: x86_64-apple-darwin<br>
release: 1.1.0-nightly</p>
<p dir="auto">Stack backtrace:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   1:        0x10ae5424f - sys::backtrace::write::h0714aaf7fe41e02dzVr
   2:        0x10ae5c8c0 - panicking::on_panic::hb86b9b356f51f92dEVv
   3:        0x10ae18c35 - rt::unwind::begin_unwind_inner::h58f79e41dbedf2efnDv
   4:        0x10a60998e - rt::unwind::begin_unwind::h17476740655312162035
   5:        0x10a60991a - diagnostic::SpanHandler::span_bug::h6ece18e7aebef0b3cFB
   6:        0x108027cfa - middle::const_eval::resolve_trait_associated_const::hfcf715732ac1e584QMi
   7:        0x107fdba61 - middle::const_eval::lookup_const_by_id::hc5a8309a206ad882OOg
   8:        0x107fd58b2 - middle::check_const::check_expr::h4c113c7ea3d8c1ffB2d
   9:        0x107fcd77c - middle::check_const::CheckCrateVisitor&lt;'a, 'tcx&gt;.Visitor&lt;'v&gt;::visit_expr::hdb217d3565a2586cGTd
  10:        0x107fd3e7e - middle::check_const::CheckCrateVisitor&lt;'a, 'tcx&gt;.Visitor&lt;'v&gt;::visit_fn::h37b9b5487c182e36DRd
  11:        0x107fd454e - visit::walk_trait_item::h8343690369834256746
  12:        0x107fd349f - visit::walk_item::h4252660852014709521
  13:        0x107fd2e1c - middle::check_const::CheckCrateVisitor&lt;'a, 'tcx&gt;.Visitor&lt;'v&gt;::visit_item::h3645f3202d46494bKMd
  14:        0x107fdbeea - middle::check_const::check_crate::ha1c34da7b8765db0Hle
  15:        0x107584171 - driver::phase_3_run_analysis_passes::h2554ff95bce00587tGa
  16:        0x10756618c - driver::compile_input::h7c6cf9b085c57594Qba
  17:        0x107625ac3 - run_compiler::h55b523753cbd518765b
  18:        0x10762322a - boxed::F.FnBox&lt;A&gt;::call_box::h11476165885616507686
  19:        0x107622767 - rt::unwind::try::try_fn::h13518150216340287792
  20:        0x10aedec58 - rust_try_inner
  21:        0x10aedec45 - rust_try
  22:        0x107622a4e - boxed::F.FnBox&lt;A&gt;::call_box::h735039165869315632
  23:        0x10ae5b2bd - sys::thread::Thread::new::thread_start::hf4c42a114072ab47mYu
  24:     0x7fff8cfab267 - _pthread_body
  25:     0x7fff8cfab1e4 - _pthread_start"><pre class="notranslate"><code class="notranslate">   1:        0x10ae5424f - sys::backtrace::write::h0714aaf7fe41e02dzVr
   2:        0x10ae5c8c0 - panicking::on_panic::hb86b9b356f51f92dEVv
   3:        0x10ae18c35 - rt::unwind::begin_unwind_inner::h58f79e41dbedf2efnDv
   4:        0x10a60998e - rt::unwind::begin_unwind::h17476740655312162035
   5:        0x10a60991a - diagnostic::SpanHandler::span_bug::h6ece18e7aebef0b3cFB
   6:        0x108027cfa - middle::const_eval::resolve_trait_associated_const::hfcf715732ac1e584QMi
   7:        0x107fdba61 - middle::const_eval::lookup_const_by_id::hc5a8309a206ad882OOg
   8:        0x107fd58b2 - middle::check_const::check_expr::h4c113c7ea3d8c1ffB2d
   9:        0x107fcd77c - middle::check_const::CheckCrateVisitor&lt;'a, 'tcx&gt;.Visitor&lt;'v&gt;::visit_expr::hdb217d3565a2586cGTd
  10:        0x107fd3e7e - middle::check_const::CheckCrateVisitor&lt;'a, 'tcx&gt;.Visitor&lt;'v&gt;::visit_fn::h37b9b5487c182e36DRd
  11:        0x107fd454e - visit::walk_trait_item::h8343690369834256746
  12:        0x107fd349f - visit::walk_item::h4252660852014709521
  13:        0x107fd2e1c - middle::check_const::CheckCrateVisitor&lt;'a, 'tcx&gt;.Visitor&lt;'v&gt;::visit_item::h3645f3202d46494bKMd
  14:        0x107fdbeea - middle::check_const::check_crate::ha1c34da7b8765db0Hle
  15:        0x107584171 - driver::phase_3_run_analysis_passes::h2554ff95bce00587tGa
  16:        0x10756618c - driver::compile_input::h7c6cf9b085c57594Qba
  17:        0x107625ac3 - run_compiler::h55b523753cbd518765b
  18:        0x10762322a - boxed::F.FnBox&lt;A&gt;::call_box::h11476165885616507686
  19:        0x107622767 - rt::unwind::try::try_fn::h13518150216340287792
  20:        0x10aedec58 - rust_try_inner
  21:        0x10aedec45 - rust_try
  22:        0x107622a4e - boxed::F.FnBox&lt;A&gt;::call_box::h735039165869315632
  23:        0x10ae5b2bd - sys::thread::Thread::new::thread_start::hf4c42a114072ab47mYu
  24:     0x7fff8cfab267 - _pthread_body
  25:     0x7fff8cfab1e4 - _pthread_start
</code></pre></div>