title: Trait specialization
body: <p>I want to define a trait <code>A</code>. I can fulfill <code>A</code> on anything which is a <code>std::default::Default</code> but I want a special implementation for <code>u64</code>. The specialization feature is designed to do this, and the following code compiles fine:</p>
  
  <pre><code>#![feature(specialization)]
  
  trait A {}
  impl&lt;T: std::default::Default&gt; A for T {}
  impl A for u64 {}
  
  fn main() {}
  </code></pre>
  
  <p>Now I want to use a trait from another crate (<code>protobuf::Message</code>) instead of <code>std::default::Default</code>. The following code doesn't work:</p>
  
  <pre><code>#![feature(specialization)]
  extern crate protobuf;
  
  trait A {}
  impl&lt;T: protobuf::Message&gt; A for T {}
  impl A for u64 {}
  
  fn main() {}
  </code></pre>
  
  <p>The compiler complains of conflicting implementations:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0119]: conflicting implementations of trait `A` for type `u64`:
   --&gt; src/main.rs:6:1
    |
  5 | impl&lt;T: protobuf::Message&gt; A for T {}
    | ------------------------------------- first implementation here
  6 | impl A for u64 {}
    | ^^^^^^^^^^^^^^^^^ conflicting implementation for `u64`
  </code></pre>
  
  <p><code>protobuf::Message</code> is not implemented for <code>u64</code>, so there's no conflict, but that doesn't really seem relevant, because <code>std::default::Default</code> <em>is</em> defined for <code>u64</code>, and the specialization works fine for that case. </p>
  
  <p>Since I specified the implementation for a concrete type, I would expect that to override implementations via traits.</p>
  
  <p><strong>Follow-up</strong>: I believe this is not a duplicate of <a href="https://stackoverflow.com/questions/45873736">Why do I get a conflicting implementations error when specializing a trait?</a>, because this code works for traits defined in the standard library and fails for traits defined in external crates. In the other question, the mistake was in insufficiently strict trait bound specification. Here, the specializing trait is a primitive type, so that solution cannot apply.</p>