<p dir="auto">This error can be shown with two rust files compiled directly via <code class="notranslate">rustc</code> (or cargo, but just using rustc is simpler for showing the error).</p>
<p dir="auto"><code class="notranslate">cratea.rs</code>:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#![crate_name = &quot;cratea&quot;]
#![crate_type = &quot;lib&quot;]

pub mod pub_dispatch {
    use dispatch;

    pub fn create_dispatch() -&gt; dispatch::Dispatch {
        return dispatch::Dispatch;
    }
}

mod dispatch {
    pub struct Dispatch;

    impl Dispatch {
        pub fn dispatch(self) {
        }
    }
}"><pre class="notranslate"><span class="pl-c1">#!<span class="pl-kos">[</span>crate_name = <span class="pl-s">"cratea"</span><span class="pl-kos">]</span></span>
<span class="pl-c1">#!<span class="pl-kos">[</span>crate_type = <span class="pl-s">"lib"</span><span class="pl-kos">]</span></span>

<span class="pl-k">pub</span> <span class="pl-k">mod</span> pub_dispatch <span class="pl-kos">{</span>
    <span class="pl-k">use</span> dispatch<span class="pl-kos">;</span>

    <span class="pl-k">pub</span> <span class="pl-k">fn</span> <span class="pl-en">create_dispatch</span><span class="pl-kos">(</span><span class="pl-kos">)</span> -&gt; dispatch<span class="pl-kos">::</span><span class="pl-smi">Dispatch</span> <span class="pl-kos">{</span>
        <span class="pl-k">return</span> dispatch<span class="pl-kos">::</span><span class="pl-v">Dispatch</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-k">mod</span> dispatch <span class="pl-kos">{</span>
    <span class="pl-k">pub</span> <span class="pl-k">struct</span> <span class="pl-smi">Dispatch</span><span class="pl-kos">;</span>

    <span class="pl-k">impl</span> <span class="pl-smi">Dispatch</span> <span class="pl-kos">{</span>
        <span class="pl-k">pub</span> <span class="pl-k">fn</span> <span class="pl-en">dispatch</span><span class="pl-kos">(</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></pre></div>
<p dir="auto"><code class="notranslate">crateb.rs</code>:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#![crate_name = &quot;crateb&quot;]
extern crate cratea;

fn main() {
    let dispatch = cratea::pub_dispatch::create_dispatch();

    dispatch.dispatch();
}"><pre class="notranslate"><span class="pl-c1">#!<span class="pl-kos">[</span>crate_name = <span class="pl-s">"crateb"</span><span class="pl-kos">]</span></span>
<span class="pl-k">extern</span> <span class="pl-k">crate</span> cratea<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> dispatch = cratea<span class="pl-kos">::</span>pub_dispatch<span class="pl-kos">::</span><span class="pl-en">create_dispatch</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    dispatch<span class="pl-kos">.</span><span class="pl-en">dispatch</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">Output from compiling:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ rustc cratea.rs
cratea.rs:16:9: 17:10 warning: method is never used: `dispatch`, #[warn(dead_code)] on by default
cratea.rs:16         pub fn dispatch(self) {
cratea.rs:17         }
$ rustc -L crate=./ crateb.rs
error: linking with `cc` failed: exit code: 1
note: &quot;cc&quot; &quot;-Wl,--as-needed&quot; &quot;-m64&quot; &quot;-L&quot; &quot;/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib&quot; &quot;-o&quot; &quot;crateb&quot; &quot;crateb.o&quot; &quot;-Wl,--whole-archive&quot; &quot;-lmorestack&quot; &quot;-Wl,--no-whole-archive&quot; &quot;-Wl,--gc-sections&quot; &quot;-pie&quot; &quot;-nodefaultlibs&quot; &quot;/tmp/tmp.8n2IVQ5qlk/libcratea.rlib&quot; &quot;/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-4e7c5e5c.rlib&quot; &quot;/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-4e7c5e5c.rlib&quot; &quot;/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunicode-4e7c5e5c.rlib&quot; &quot;/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-4e7c5e5c.rlib&quot; &quot;/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-4e7c5e5c.rlib&quot; &quot;/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-4e7c5e5c.rlib&quot; &quot;/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-4e7c5e5c.rlib&quot; &quot;-L&quot; &quot;./&quot; &quot;-L&quot; &quot;/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib&quot; &quot;-L&quot; &quot;/tmp/tmp.8n2IVQ5qlk/.rust/lib/x86_64-unknown-linux-gnu&quot; &quot;-L&quot; &quot;/tmp/tmp.8n2IVQ5qlk/lib/x86_64-unknown-linux-gnu&quot; &quot;-Wl,--whole-archive&quot; &quot;-Wl,-Bstatic&quot; &quot;-Wl,--no-whole-archive&quot; &quot;-Wl,-Bdynamic&quot; &quot;-ldl&quot; &quot;-lpthread&quot; &quot;-lrt&quot; &quot;-lgcc_s&quot; &quot;-lpthread&quot; &quot;-lc&quot; &quot;-lm&quot; &quot;-lcompiler-rt&quot;
note: crateb.o: In function `main::h69a169139aab5413faa':
crateb.0.rs:(.text._ZN4main20h69a169139aab5413faaE+0x2c): undefined reference to `dispatch::Dispatch::dispatch::ha28d1bdf4c2d8d39uaa'
collect2: error: ld returned 1 exit status

error: aborting due to previous error"><pre lang="text" class="notranslate"><code class="notranslate">$ rustc cratea.rs
cratea.rs:16:9: 17:10 warning: method is never used: `dispatch`, #[warn(dead_code)] on by default
cratea.rs:16         pub fn dispatch(self) {
cratea.rs:17         }
$ rustc -L crate=./ crateb.rs
error: linking with `cc` failed: exit code: 1
note: "cc" "-Wl,--as-needed" "-m64" "-L" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "crateb" "crateb.o" "-Wl,--whole-archive" "-lmorestack" "-Wl,--no-whole-archive" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "/tmp/tmp.8n2IVQ5qlk/libcratea.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunicode-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-4e7c5e5c.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-4e7c5e5c.rlib" "-L" "./" "-L" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-L" "/tmp/tmp.8n2IVQ5qlk/.rust/lib/x86_64-unknown-linux-gnu" "-L" "/tmp/tmp.8n2IVQ5qlk/lib/x86_64-unknown-linux-gnu" "-Wl,--whole-archive" "-Wl,-Bstatic" "-Wl,--no-whole-archive" "-Wl,-Bdynamic" "-ldl" "-lpthread" "-lrt" "-lgcc_s" "-lpthread" "-lc" "-lm" "-lcompiler-rt"
note: crateb.o: In function `main::h69a169139aab5413faa':
crateb.0.rs:(.text._ZN4main20h69a169139aab5413faaE+0x2c): undefined reference to `dispatch::Dispatch::dispatch::ha28d1bdf4c2d8d39uaa'
collect2: error: ld returned 1 exit status

error: aborting due to previous error
</code></pre></div>
<p dir="auto">Happens in <code class="notranslate">rustc 1.0.0-beta (9854143cb 2015-04-02) (built 2015-04-02)</code> and <code class="notranslate">rustc 1.0.0-nightly (083b8a404 2015-04-05) (built 2015-04-05)</code>.</p>
<p dir="auto">I would expect this to fail when compiling <code class="notranslate">cratea</code>, but instead <code class="notranslate">cratea</code> compiles fine, but then any crate using it will fail compiling.</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// foo.rs
pub use foo::Bar;

pub fn test() -&gt; Bar&lt;i32&gt; {
    loop {}
}

mod foo {
    pub type Bar&lt;T&gt; = Result&lt;T, Baz&gt;;

    pub struct Baz;

    impl Baz {
        pub fn foo(&amp;self) {}
    }
}"><pre class="notranslate"><span class="pl-c">// foo.rs</span>
<span class="pl-k">pub</span> <span class="pl-k">use</span> foo<span class="pl-kos">::</span><span class="pl-v">Bar</span><span class="pl-kos">;</span>

<span class="pl-k">pub</span> <span class="pl-k">fn</span> <span class="pl-en">test</span><span class="pl-kos">(</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">Bar</span><span class="pl-kos">&lt;</span><span class="pl-smi">i32</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">loop</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-k">mod</span> foo <span class="pl-kos">{</span>
    <span class="pl-k">pub</span> <span class="pl-k">type</span> <span class="pl-smi">Bar</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span> = <span class="pl-smi">Result</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">,</span> <span class="pl-smi">Baz</span><span class="pl-kos">&gt;</span><span class="pl-kos">;</span>

    <span class="pl-k">pub</span> <span class="pl-k">struct</span> <span class="pl-smi">Baz</span><span class="pl-kos">;</span>

    <span class="pl-k">impl</span> <span class="pl-smi">Baz</span> <span class="pl-kos">{</span>
        <span class="pl-k">pub</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-kos">}</span></pre></div>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// bar.rs
extern crate foo;

fn main() {
    match foo::test() {
        Ok(..) =&gt; {}
        Err(e) =&gt; e.foo()
    }
}"><pre class="notranslate"><span class="pl-c">// bar.rs</span>
<span class="pl-k">extern</span> <span class="pl-k">crate</span> foo<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">match</span> foo<span class="pl-kos">::</span><span class="pl-en">test</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-v">Ok</span><span class="pl-kos">(</span>..<span class="pl-kos">)</span> =&gt; <span class="pl-kos">{</span><span class="pl-kos">}</span>
        <span class="pl-v">Err</span><span class="pl-kos">(</span>e<span class="pl-kos">)</span> =&gt; e<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>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ rustc --crate-type lib foo.rs      
foo.rs:13:9: 13:29 warning: code is never used: `foo`, #[warn(dead_code)] on by default
foo.rs:13         pub fn foo(&amp;self) {}
                  ^~~~~~~~~~~~~~~~~~~~
$ rustc bar.rs -L.    
error: linking with `cc` failed: exit code: 1
note: cc '-m64' '-L' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-o' 'bar' 'bar.o' '-Wl,--whole-archive' '-lmorestack' '-Wl,--no-whole-archive' '-nodefaultlibs' '-Wl,--gc-sections' '-pie' '-Wl,--as-needed' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libnative-4e7c5e5c.rlib' '/home/alex/libfoo.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libsync-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustrt-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunicode-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-4e7c5e5c.rlib' '-L' '.' '-L' '/home/alex/.rust' '-L' '/home/alex' '-Wl,--whole-archive' '-Wl,-Bstatic' '-Wl,--no-whole-archive' '-Wl,-Bdynamic' '-ldl' '-lpthread' '-lgcc_s' '-lpthread' '-lc' '-lm' '-lcompiler-rt'
note: bar.o: In function `main::hbeb79415393a4115faa':
bar.rs:(.text._ZN4main20hbeb79415393a4115faaE+0x45): undefined reference to `foo::Baz::foo::h3d69757c908833a5Yaa'
collect2: error: ld returned 1 exit status

error: aborting due to previous error
"><pre class="notranslate"><code class="notranslate">$ rustc --crate-type lib foo.rs      
foo.rs:13:9: 13:29 warning: code is never used: `foo`, #[warn(dead_code)] on by default
foo.rs:13         pub fn foo(&amp;self) {}
                  ^~~~~~~~~~~~~~~~~~~~
$ rustc bar.rs -L.    
error: linking with `cc` failed: exit code: 1
note: cc '-m64' '-L' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-o' 'bar' 'bar.o' '-Wl,--whole-archive' '-lmorestack' '-Wl,--no-whole-archive' '-nodefaultlibs' '-Wl,--gc-sections' '-pie' '-Wl,--as-needed' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libnative-4e7c5e5c.rlib' '/home/alex/libfoo.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libsync-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustrt-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunicode-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-4e7c5e5c.rlib' '-L' '.' '-L' '/home/alex/.rust' '-L' '/home/alex' '-Wl,--whole-archive' '-Wl,-Bstatic' '-Wl,--no-whole-archive' '-Wl,-Bdynamic' '-ldl' '-lpthread' '-lgcc_s' '-lpthread' '-lc' '-lm' '-lcompiler-rt'
note: bar.o: In function `main::hbeb79415393a4115faa':
bar.rs:(.text._ZN4main20hbeb79415393a4115faaE+0x45): undefined reference to `foo::Baz::foo::h3d69757c908833a5Yaa'
collect2: error: ld returned 1 exit status

error: aborting due to previous error

</code></pre></div>
<p dir="auto">There are a number of problems with this, and they may likely all be inter-related.</p>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> linker error</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> dead code which is not actually dead code</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> it should be an error that <code class="notranslate">Baz</code> is a publicly visible private type.</li>
</ul>
<p dir="auto">Nominating due to the publicly visible private type not generating an error.</p>