<p dir="auto">The following program fails to compile:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="trait Foo { fn foo(&amp;self, x: &amp;Self); }
trait Bar&lt;A: Foo&gt; { fn bar(&amp;self) -&gt; A; }

struct Wrap&lt;T&gt;(T);

impl&lt;A, B: Bar&lt;A&gt;&gt; Wrap&lt;B&gt; {
    fn test(&amp;self, x: &amp;A) {
        (*self).bar().foo(x);
    }
}

fn main() {}"><pre class="notranslate"><span class="pl-k">trait</span> <span class="pl-smi">Foo</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-s1">x</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-k">trait</span> <span class="pl-smi">Bar</span><span class="pl-kos">&lt;</span><span class="pl-smi">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">bar</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">A</span><span class="pl-kos">;</span> <span class="pl-kos">}</span>

<span class="pl-k">struct</span> <span class="pl-smi">Wrap</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-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">A</span><span class="pl-kos">,</span> <span class="pl-smi">B</span><span class="pl-kos">:</span> <span class="pl-smi">Bar</span><span class="pl-kos">&lt;</span><span class="pl-smi">A</span><span class="pl-kos">&gt;</span><span class="pl-kos">&gt;</span> <span class="pl-smi">Wrap</span><span class="pl-kos">&lt;</span><span class="pl-smi">B</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">fn</span> <span class="pl-en">test</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-s1">x</span><span class="pl-kos">:</span> <span class="pl-c1">&amp;</span><span class="pl-smi">A</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-kos">(</span><span class="pl-c1">*</span><span class="pl-smi">self</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">bar</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">foo</span><span class="pl-kos">(</span>x<span class="pl-kos">)</span><span class="pl-kos">;</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-kos">}</span></pre></div>
<p dir="auto">With the following error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="implsearch.rs:8:8: 8:22 error: failed to find an implementation of trait Foo for A
implsearch.rs:8         (*self).bar().foo(x);
                        ^~~~~~~~~~~~~~"><pre class="notranslate"><code class="notranslate">implsearch.rs:8:8: 8:22 error: failed to find an implementation of trait Foo for A
implsearch.rs:8         (*self).bar().foo(x);
                        ^~~~~~~~~~~~~~
</code></pre></div>
<p dir="auto">Given that <code class="notranslate">B: Bar&lt;A&gt;</code>, we know <code class="notranslate">A: Foo</code> because of the definition of the trait Bar. This can be seen as a generalized case of trait inheritance (trait B inheriting from A lets us know that if <code class="notranslate">X:B</code>, then <code class="notranslate">X:A</code>, because <code class="notranslate">X:B</code> requires <code class="notranslate">X:A</code>; similarly, <code class="notranslate">B:Bar&lt;A&gt;</code> requires <code class="notranslate">A:Foo</code>, so we know <code class="notranslate">A:Foo</code>). Indeed, in Haskell there is no distinction between the two forms of inheritance:</p>
<div class="highlight highlight-source-haskell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{-# LANGUAGE MultiParamTypeClasses #-}
class Foo b where foo :: b -&gt; b -&gt; ()
class Foo b =&gt; Bar a b where bar :: a -&gt; b

test :: Bar a b =&gt; a -&gt; b -&gt; ()
test x y = foo (bar x) y"><pre class="notranslate">{-# <span class="pl-k">LANGUAGE</span> MultiParamTypeClasses #-}
<span class="pl-k">class</span> <span class="pl-en">Foo</span> <span class="pl-smi">b</span> <span class="pl-k">where</span> foo <span class="pl-k">::</span> <span class="pl-smi">b</span> <span class="pl-k">-&gt;</span> <span class="pl-smi">b</span> <span class="pl-k">-&gt;</span> <span class="pl-c1">()</span>
<span class="pl-k">class</span> <span class="pl-en">Foo</span> <span class="pl-smi">b</span> <span class="pl-k">=&gt;</span> <span class="pl-en">Bar</span> <span class="pl-smi">a</span> <span class="pl-smi">b</span> <span class="pl-k">where</span> bar <span class="pl-k">::</span> <span class="pl-smi">a</span> <span class="pl-k">-&gt;</span> <span class="pl-smi">b</span>

<span class="pl-en">test</span> <span class="pl-k">::</span> <span class="pl-en">Bar</span> <span class="pl-smi">a</span> <span class="pl-smi">b</span> <span class="pl-k">=&gt;</span> <span class="pl-smi">a</span> <span class="pl-k">-&gt;</span> <span class="pl-smi">b</span> <span class="pl-k">-&gt;</span> <span class="pl-c1">()</span>
test x y <span class="pl-k">=</span> foo (bar x) y</pre></div>
<p dir="auto">The order of arguments to Bar could be switched and the program above would still be valid.</p>
<p dir="auto">The following example:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="trait Foo&lt;T&gt; {
   fn foo(&amp;self) -&gt; &amp;T;
}

trait Bar&lt;A&gt; where A: Foo&lt;Self&gt; {}

fn foobar&lt;A, B: Bar&lt;A&gt;&gt;(a: &amp;A) -&gt; &amp;B {
   a.foo()
}"><pre class="notranslate"><span class="pl-k">trait</span> <span class="pl-smi">Foo</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-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> -&gt; <span class="pl-c1">&amp;</span><span class="pl-smi">T</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">trait</span> <span class="pl-smi">Bar</span><span class="pl-kos">&lt;</span><span class="pl-smi">A</span><span class="pl-kos">&gt;</span> <span class="pl-k">where</span> <span class="pl-smi">A</span><span class="pl-kos">:</span> <span class="pl-smi">Foo</span><span class="pl-kos">&lt;</span><span class="pl-smi">Self</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">foobar</span><span class="pl-kos">&lt;</span><span class="pl-smi">A</span><span class="pl-kos">,</span> <span class="pl-smi">B</span><span class="pl-kos">:</span> <span class="pl-smi">Bar</span><span class="pl-kos">&lt;</span><span class="pl-smi">A</span><span class="pl-kos">&gt;</span><span class="pl-kos">&gt;</span><span class="pl-kos">(</span><span class="pl-s1">a</span><span class="pl-kos">:</span> <span class="pl-c1">&amp;</span><span class="pl-smi">A</span><span class="pl-kos">)</span> -&gt; <span class="pl-c1">&amp;</span><span class="pl-smi">B</span> <span class="pl-kos">{</span>
   a<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></pre></div>
<p dir="auto">fails with "error: type <code class="notranslate">&amp;A</code> does not implement any method in scope named <code class="notranslate">foo</code>".</p>
<p dir="auto">This UFCS variant</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="trait Foo&lt;T&gt; {
    fn foo(&amp;self) -&gt; &amp;T;
}

trait Bar&lt;A&gt; where A: Foo&lt;Self&gt; {}

fn foobar&lt;A, B: Bar&lt;A&gt;&gt;(a: &amp;A) -&gt; &amp;B {
    Foo::foo(a)
}"><pre class="notranslate"><span class="pl-k">trait</span> <span class="pl-smi">Foo</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-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> -&gt; <span class="pl-c1">&amp;</span><span class="pl-smi">T</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">trait</span> <span class="pl-smi">Bar</span><span class="pl-kos">&lt;</span><span class="pl-smi">A</span><span class="pl-kos">&gt;</span> <span class="pl-k">where</span> <span class="pl-smi">A</span><span class="pl-kos">:</span> <span class="pl-smi">Foo</span><span class="pl-kos">&lt;</span><span class="pl-smi">Self</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">foobar</span><span class="pl-kos">&lt;</span><span class="pl-smi">A</span><span class="pl-kos">,</span> <span class="pl-smi">B</span><span class="pl-kos">:</span> <span class="pl-smi">Bar</span><span class="pl-kos">&lt;</span><span class="pl-smi">A</span><span class="pl-kos">&gt;</span><span class="pl-kos">&gt;</span><span class="pl-kos">(</span><span class="pl-s1">a</span><span class="pl-kos">:</span> <span class="pl-c1">&amp;</span><span class="pl-smi">A</span><span class="pl-kos">)</span> -&gt; <span class="pl-c1">&amp;</span><span class="pl-smi">B</span> <span class="pl-kos">{</span>
    <span class="pl-smi">Foo</span><span class="pl-kos">::</span><span class="pl-en">foo</span><span class="pl-kos">(</span>a<span class="pl-kos">)</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">fails with "error: the trait <code class="notranslate">Foo&lt;_&gt;</code> is not implemented for the type <code class="notranslate">A</code>".</p>