title: Why does rust say "unconstrained type parameter" whereas it seems to be constrained?
body: <p>There are two existing structs <code>S1</code> and <code>S2&lt;T&gt;</code> and two traits <code>T1</code> and <code>T2&lt;T&gt;</code>. I want to implement <code>T2&lt;T&gt;</code> for <code>S1</code>, for all <code>T</code> that are <code>AsRef&lt;S2&lt;T1&gt;&gt;</code>.</p>
  
  <p>I thought I could write : </p>
  
  <pre class="lang-rust prettyprint-override"><code>struct S1;
  struct S2&lt;T&gt;{t:T}
  
  trait T1 {}
  trait T2&lt;T&gt; {}
  
  impl &lt;T: AsRef&lt;S2&lt;T1&gt;&gt;&gt; T2&lt;T&gt; for S1 {}
  </code></pre>
  
  <p>but I get the following error (<a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=a9547fa583278c161daaef8978e5da39" rel="nofollow noreferrer">playground</a>):</p>
  
  <blockquote>
    <p>error[E0277]: the size for values of type <code>(dyn T1 + 'static)</code> cannot be known at compilation time</p>
  </blockquote>
  
  <p>Of course the size of the type is not known at this point ! I want to create a generic implementation for all types that implement T1. So I tried the following :</p>
  
  <pre class="lang-rust prettyprint-override"><code>struct S1;
  struct S2&lt;T&gt;{t:T}
  
  trait T1 {}
  trait T2&lt;T&gt; {}
  
  impl &lt;T,U&gt; T2&lt;T&gt; for S1 
      where T: AsRef&lt;S2&lt;U&gt;&gt;,
            U: T1
  {}
  </code></pre>
  
  <p>But this does not compile either, with the following error:</p>
  
  <blockquote>
    <p>error[E0207]: the type parameter <code>U</code> is not constrained by the impl trait, self type, or predicates</p>
  </blockquote>
  
  <p>What is the problem with the code above, and how can it be fixed ?</p>