Error: unable to infer enough type information about `_`; type annotations or generic parameter binding required
<p>Apologies for the generic title.</p>

<p>Here is some example code:</p>

<pre><code>use std::marker::PhantomData;

pub trait Foo {
    fn foo(&amp;self);
}

pub trait Bar&lt;A: Foo&gt; {
    fn bar(&amp;self, a: A);
}

pub struct Test&lt;A, B&gt;
    where A: Foo,
          B: Bar&lt;A&gt;
{
    _phantom_r: PhantomData&lt;A&gt;,
    bars: Vec&lt;B&gt;,
}

impl&lt;A, B&gt; Test&lt;A, B&gt;
    where A: Foo,
          B: Bar&lt;A&gt;
{
    pub fn new() -&gt; Test&lt;A, B&gt; {
        Test {
            _phantom_r: PhantomData,
            bars: Vec::new(),
        }
    }

    pub fn add_bar(&amp;mut self, b: B) {
        self.bars.push(b);
    }
}

fn main() {
    let t = Test::new();
}
</code></pre>

<p>(<a href="https://play.rust-lang.org/?gist=989824eb1e4d1a594eebab1b421dc987&amp;version=stable&amp;backtrace=0" rel="nofollow">Playground</a>)</p>

<p>The error is:</p>

<pre><code>&lt;anon&gt;:32:13: 36:22 error: unable to infer enough type information about `_`; type annotations or generic parameter binding required [E0282]
&lt;anon&gt;:32     let t = Test::new();
</code></pre>

<p>I'm quite confused on what Rust is having trouble inferring the trait types, and how I can specify what it wants. That is, I'm not sure if this is right, because then I run into <code>Sized</code> issues:</p>

<pre><code>let t = Test::new() as Test&lt;Foo,Bar&lt;Foo&gt;&gt;;
</code></pre>

<p>error:</p>

<pre><code>&lt;anon&gt;:36:28: 36:46 error: the trait `core::marker::Sized` is not implemented for the type `Foo` [E0277]
&lt;anon&gt;:36     let t = Test::new() as Test&lt;Foo,Bar&lt;Foo&gt;&gt;;
</code></pre>

<p>I have two main questions:</p>

<ol>
<li>Why is Rust unable to infer the trait types of <code>Test&lt;A,B&lt;A&gt;&gt;</code>?</li>
<li>What is the solution to make this code work?</li>
</ol>