<p dir="auto">Running tests requires linking to <code class="notranslate">std</code>, where the test runner lives. core has a huge hack in it to allow it to link to std when building with <code class="notranslate">--test</code>.</p>
<p dir="auto">When building core tests (an executable), core links to std, which then links to <em>the actual core shared library</em>. As a result coretest actually includes two entire copies of core at runtime. The tests are exercising the core code compiled into the executable, and std is exercising the core library.</p>
<p dir="auto">This caused a confusing problem with the TLS tests which use function addresses as keys, because std and coretest were using two different functions.</p>
<p dir="auto">Two solutions</p>
<ul dir="auto">
<li>move std::test to core</li>
<li>move core tests to their own crate</li>
</ul>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="struct Foo;

trait Bar {
    fn bar(&amp;self) -&gt; int;
}
impl Bar for Foo {
    fn bar(&amp;self) -&gt; int {1}
    fn bar(&amp;self) -&gt; int {2}
}

fn main() {
    printfln!(Foo.bar())
}"><pre class="notranslate"><span class="pl-k">struct</span> <span class="pl-smi">Foo</span><span class="pl-kos">;</span>

<span class="pl-k">trait</span> <span class="pl-smi">Bar</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">int</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-k">for</span> <span class="pl-smi">Foo</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">int</span> <span class="pl-kos">{</span><span class="pl-c1">1</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">int</span> <span class="pl-kos">{</span><span class="pl-c1">2</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-en">printfln</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-v">Foo</span>.bar<span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ rustc double-def.rs
$ ./double-def
1"><pre class="notranslate"><code class="notranslate">$ rustc double-def.rs
$ ./double-def
1
</code></pre></div>