<p dir="auto">When compiling the following code:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="use std::cell::{RefCell, RefMut};

trait FooTrait {
    fn footrait(&amp;mut self);
}

struct Foo;
impl FooTrait for Foo {
    fn footrait(&amp;mut self) { () }
}

impl&lt;'a&gt; FooTrait for RefMut&lt;'a, Foo&gt; {
    fn footrait(&amp;mut self) { () }
}

struct Bar {
    bar: RefCell&lt;Foo&gt;,
}
impl Bar {
    fn foobox(&amp;self) -&gt; Box&lt;FooTrait&gt; {
        let inner = self.bar.borrow_mut();
        Box::new(inner)
    }
}"><pre class="notranslate"><span class="pl-k">use</span> std<span class="pl-kos">::</span>cell<span class="pl-kos">::</span><span class="pl-kos">{</span><span class="pl-v">RefCell</span><span class="pl-kos">,</span> <span class="pl-v">RefMut</span><span class="pl-kos">}</span><span class="pl-kos">;</span>

<span class="pl-k">trait</span> <span class="pl-smi">FooTrait</span> <span class="pl-kos">{</span>
    <span class="pl-k">fn</span> <span class="pl-en">footrait</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-k">mut</span> <span class="pl-smi">self</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">struct</span> <span class="pl-smi">Foo</span><span class="pl-kos">;</span>
<span class="pl-k">impl</span> <span class="pl-smi">FooTrait</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">footrait</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-k">mut</span> <span class="pl-smi">self</span><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-kos">}</span>

<span class="pl-k">impl</span><span class="pl-kos">&lt;</span><span class="pl-c1">'</span><span class="pl-ent">a</span><span class="pl-kos">&gt;</span> <span class="pl-smi">FooTrait</span> <span class="pl-k">for</span> <span class="pl-smi">RefMut</span><span class="pl-kos">&lt;</span><span class="pl-c1">'</span><span class="pl-ent">a</span><span class="pl-kos">,</span> <span class="pl-smi">Foo</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">fn</span> <span class="pl-en">footrait</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-k">mut</span> <span class="pl-smi">self</span><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-kos">}</span>

<span class="pl-k">struct</span> <span class="pl-smi">Bar</span> <span class="pl-kos">{</span>
    <span class="pl-c1">bar</span><span class="pl-kos">:</span> <span class="pl-smi">RefCell</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-k">impl</span> <span class="pl-smi">Bar</span> <span class="pl-kos">{</span>
    <span class="pl-k">fn</span> <span class="pl-en">foobox</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-smi">self</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">Box</span><span class="pl-kos">&lt;</span><span class="pl-smi">FooTrait</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
        <span class="pl-k">let</span> inner = <span class="pl-smi">self</span><span class="pl-kos">.</span><span class="pl-c1">bar</span><span class="pl-kos">.</span><span class="pl-en">borrow_mut</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-smi">Box</span><span class="pl-kos">::</span><span class="pl-en">new</span><span class="pl-kos">(</span>inner<span class="pl-kos">)</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">I get the following (confusing) error message:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;anon&gt;:21:30: 21:42 error: cannot infer an appropriate lifetime for autoref due to conflicting requirements
&lt;anon&gt;:21         let inner = self.bar.borrow_mut();
                                       ^~~~~~~~~~~~
&lt;anon&gt;:21:21: 21:29 note: first, the lifetime cannot outlive the expression at 21:20...
&lt;anon&gt;:21         let inner = self.bar.borrow_mut();
                              ^~~~~~~~
&lt;anon&gt;:21:21: 21:29 note: ...so that auto-reference is valid at the time of borrow
&lt;anon&gt;:21         let inner = self.bar.borrow_mut();
                              ^~~~~~~~
&lt;anon&gt;:21:21: 21:42 note: but, the lifetime must be valid for the method call at 21:20...
&lt;anon&gt;:21         let inner = self.bar.borrow_mut();
                              ^~~~~~~~~~~~~~~~~~~~~
&lt;anon&gt;:21:21: 21:29 note: ...so that method receiver is valid for the method call
&lt;anon&gt;:21         let inner = self.bar.borrow_mut();
                              ^~~~~~~~"><pre class="notranslate"><code class="notranslate">&lt;anon&gt;:21:30: 21:42 error: cannot infer an appropriate lifetime for autoref due to conflicting requirements
&lt;anon&gt;:21         let inner = self.bar.borrow_mut();
                                       ^~~~~~~~~~~~
&lt;anon&gt;:21:21: 21:29 note: first, the lifetime cannot outlive the expression at 21:20...
&lt;anon&gt;:21         let inner = self.bar.borrow_mut();
                              ^~~~~~~~
&lt;anon&gt;:21:21: 21:29 note: ...so that auto-reference is valid at the time of borrow
&lt;anon&gt;:21         let inner = self.bar.borrow_mut();
                              ^~~~~~~~
&lt;anon&gt;:21:21: 21:42 note: but, the lifetime must be valid for the method call at 21:20...
&lt;anon&gt;:21         let inner = self.bar.borrow_mut();
                              ^~~~~~~~~~~~~~~~~~~~~
&lt;anon&gt;:21:21: 21:29 note: ...so that method receiver is valid for the method call
&lt;anon&gt;:21         let inner = self.bar.borrow_mut();
                              ^~~~~~~~
</code></pre></div>
<p dir="auto">After a lot of trial-and-error I noticed I had to do the following change:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// old:
     fn foobox(&amp;self) -&gt; Box&lt;FooTrait&gt; {
// new:
     fn foobox&lt;'a&gt;(&amp;'a self) -&gt; Box&lt;FooTrait + 'a&gt; {"><pre class="notranslate"><span class="pl-c">// old:</span>
     <span class="pl-k">fn</span> foobox<span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-smi">self</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">Box</span><span class="pl-kos">&lt;</span><span class="pl-smi">FooTrait</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
<span class="pl-c">// new:</span>
     <span class="pl-k">fn</span> foobox<span class="pl-kos">&lt;</span><span class="pl-c1">'</span><span class="pl-ent">a</span><span class="pl-kos">&gt;</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-c1">'</span><span class="pl-ent">a</span> <span class="pl-smi">self</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">Box</span><span class="pl-kos">&lt;</span><span class="pl-smi">FooTrait</span> + <span class="pl-c1">'</span><span class="pl-ent">a</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span></pre></div>
<p dir="auto">Compiler panics when compiling code that implements a trait for a generic type and a generic type in a vector.</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="trait MyTrait {
    fn foo(&amp;self){}
}
trait OtherTrait {
    fn bar(&amp;self){}
}

impl OtherTrait for String {}
impl OtherTrait for Vec&lt;String&gt; {}

impl&lt;T: OtherTrait&gt; MyTrait for T {}
impl&lt;T: OtherTrait&gt; MyTrait for Vec&lt;T&gt; {}

fn main() {
    let test_var: Vec&lt;String&gt; = Vec::&lt;String&gt;::new();
    test_var.foo();
}"><pre class="notranslate"><span class="pl-k">trait</span> <span class="pl-smi">MyTrait</span> <span class="pl-kos">{</span>
    <span class="pl-k">fn</span> <span class="pl-en">foo</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-smi">self</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">trait</span> <span class="pl-smi">OtherTrait</span> <span class="pl-kos">{</span>
    <span class="pl-k">fn</span> <span class="pl-en">bar</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-smi">self</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">impl</span> <span class="pl-smi">OtherTrait</span> <span class="pl-k">for</span> <span class="pl-smi">String</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>
<span class="pl-k">impl</span> <span class="pl-smi">OtherTrait</span> <span class="pl-k">for</span> <span class="pl-smi">Vec</span><span class="pl-kos">&lt;</span><span class="pl-smi">String</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>

<span class="pl-k">impl</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">:</span> <span class="pl-smi">OtherTrait</span><span class="pl-kos">&gt;</span> <span class="pl-smi">MyTrait</span> <span class="pl-k">for</span> <span class="pl-smi">T</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>
<span class="pl-k">impl</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">:</span> <span class="pl-smi">OtherTrait</span><span class="pl-kos">&gt;</span> <span class="pl-smi">MyTrait</span> <span class="pl-k">for</span> <span class="pl-smi">Vec</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</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-k">let</span> test_var<span class="pl-kos">:</span> <span class="pl-smi">Vec</span><span class="pl-kos">&lt;</span><span class="pl-smi">String</span><span class="pl-kos">&gt;</span> = <span class="pl-smi">Vec</span><span class="pl-kos">::</span><span class="pl-kos">&lt;</span><span class="pl-smi">String</span><span class="pl-kos">&gt;</span><span class="pl-kos">::</span><span class="pl-en">new</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    test_var<span class="pl-kos">.</span><span class="pl-en">foo</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">I expected to see this happen: As in 1.0.0-nightly (<a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/rust-lang/rust/commit/3e4be02b80a3dd27bce20870958fe0aef7e7336d/hovercard" href="https://github.com/rust-lang/rust/commit/3e4be02b80a3dd27bce20870958fe0aef7e7336d"><tt>3e4be02</tt></a> 2015-03-13) (built 2015-03-14), the compiler should catch the conflicting implementations.</p>
<p dir="auto">Instead, this happened: Compiler panics</p>
<h2 dir="auto">Meta</h2>
<p dir="auto"><code class="notranslate">rustc --version --verbose</code>:<br>
rustc 1.0.0-beta (<a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/rust-lang/rust/commit/9854143cba679834bc4ef932858cd5303f015a0e/hovercard" href="https://github.com/rust-lang/rust/commit/9854143cba679834bc4ef932858cd5303f015a0e"><tt>9854143</tt></a> 2015-04-02) (built 2015-04-02)<br>
binary: rustc<br>
commit-hash: <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/rust-lang/rust/commit/9854143cba679834bc4ef932858cd5303f015a0e/hovercard" href="https://github.com/rust-lang/rust/commit/9854143cba679834bc4ef932858cd5303f015a0e"><tt>9854143</tt></a><br>
commit-date: 2015-04-02<br>
build-date: 2015-04-02<br>
host: x86_64-pc-windows-gnu<br>
release: 1.0.0-beta</p>
<p dir="auto">Error: internal compiler error: coherence failed to report ambiguity: cannot locate the impl of the trait <code class="notranslate">MyTrait</code> for the type <code class="notranslate">collections::vec::Vec&lt;collections::string::String&gt;</code></p>