title: Is there a way to get the type name of a trait?
body: <p>I'm trying to use <code>std::intrinsics::type_name</code> to get the type name of a trait but can't compile it:</p>
  
  <pre><code>#![feature(core_intrinsics)]
  
  use std::intrinsics::type_name;
  
  trait TestTrait: Sized {
      fn test(&amp;self);
  }
  
  struct MyStruct {}
  
  struct GetType {}
  
  impl GetType {
      fn test_type&lt;T: ?Sized&gt;() {
          let test = unsafe { type_name::&lt;T&gt;() };
          println!("{:?}", test);
      }
  }
  
  fn main() {
      GetType::test_type::&lt;i32&gt;();
      GetType::test_type::&lt;MyStruct&gt;();
      GetType::test_type::&lt;TestTrait&gt;();
  }
  </code></pre>
  
  <p>Here is the error I get from the compiler</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0038]: the trait `TestTrait` cannot be made into an object
    --&gt; src/main.rs:23:30
     |
  23 |         GetType::test_type::&lt;TestTrait&gt;();
     |                              ^^^^^^^^^ the trait `TestTrait` cannot be made into an object
     |
     = note: the trait cannot require that `Self : Sized`
  </code></pre>
  
  <p>Here is the output of that test when I comment the line <code>GetType::test_type::&lt;TestTrait&gt;();</code></p>
  
  <pre class="lang-none prettyprint-override"><code>"i32"
  "MyStruct"
  </code></pre>
  
  <p>Is there a way to solve this or to get the type name of a trait?</p>
  
  <hr>
  
  <p>Working solution thanks to @evotopid</p>
  
  <pre><code>#![feature(core_intrinsics)]
  
  use std::intrinsics::type_name;
  
  trait TestTrait { // &lt;--- remove `: Sized` constraint from here 
      fn test(&amp;self);
  }
  
  struct MyStruct {}
  
  struct GetType {}
  
  impl GetType {
      fn test_type&lt;T: ?Sized&gt;() { // &lt;--- trick is in that bound
          let test = unsafe { type_name::&lt;T&gt;() };
          println!("{:?}", test);
      }
  }
  
  fn main() {
      GetType::test_type::&lt;i32&gt;();
      GetType::test_type::&lt;MyStruct&gt;();
      GetType::test_type::&lt;TestTrait&gt;();
  }
  </code></pre>
  
  <p>Leading to the following output</p>
  
  <pre class="lang-none prettyprint-override"><code>"i32"
  "MyStruct"
  "TestTrait"
  </code></pre>