<p dir="auto">This code snippet causes a link failure. I am guessing it is because the return type of foo is not publicly exported from the crate it is causing a link failure in the test.</p>
<p dir="auto">I tried this (reduced) code:</p>
<p dir="auto">lib.rs</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="mod helper {
    pub struct Foo;
    impl Foo {
        pub fn baz(&amp;self) { }
    }

    pub fn foo() -&gt; Foo {
        return Foo;
    }
}

pub use helper::foo;"><pre class="notranslate"><span class="pl-k">mod</span> helper <span class="pl-kos">{</span>
    <span class="pl-k">pub</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">Foo</span> <span class="pl-kos">{</span>
        <span class="pl-k">pub</span> <span class="pl-k">fn</span> <span class="pl-en">baz</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">pub</span> <span class="pl-k">fn</span> <span class="pl-en">foo</span><span class="pl-kos">(</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
        <span class="pl-k">return</span> <span class="pl-v">Foo</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-k">pub</span> <span class="pl-k">use</span> helper<span class="pl-kos">::</span>foo<span class="pl-kos">;</span></pre></div>
<p dir="auto">test.rs</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="extern crate lib;

#[test]
fn test() {
    lib::foo().baz();
}"><pre class="notranslate"><span class="pl-k">extern</span> <span class="pl-k">crate</span> lib<span class="pl-kos">;</span>

<span class="pl-c1">#<span class="pl-kos">[</span>test<span class="pl-kos">]</span></span>
<span class="pl-k">fn</span> <span class="pl-en">test</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    lib<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-en">baz</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: Definitely a clear error as opposed to a link failure. Probably an error stating that the return type of <code class="notranslate">foo()</code> is not visible outside the crate.</p>
<p dir="auto">Instead, this happened: Linker error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="── env RUST_BACKTRACE=1 cargo test
   Compiling lib v0.1.0 (file:///Users/nwr/tmp/cargo-test/lib)
error: linking with `cc` failed: exit code: 1
note: &quot;cc&quot; &quot;-m64&quot; &quot;-L&quot; &quot;/usr/local/lib/rustlib/x86_64-apple-darwin/lib&quot; &quot;/Users/nwr/tmp/cargo-test/lib/target/debug/foo-5f1f39478ede92a5.0.o&quot; &quot;-o&quot; &quot;/Users/nwr/tmp/cargo-test/lib/target/debug/foo-5f1f39478ede92a5&quot; &quot;-Wl,-force_load,/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libmorestack.a&quot; &quot;-Wl,-dead_strip&quot; &quot;-nodefaultlibs&quot; &quot;/Users/nwr/tmp/cargo-test/lib/target/debug/liblib.rlib&quot; &quot;/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libtest-74fa456f.rlib&quot; &quot;/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libgetopts-74fa456f.rlib&quot; &quot;/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libserialize-74fa456f.rlib&quot; &quot;/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libterm-74fa456f.rlib&quot; &quot;/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liblog-74fa456f.rlib&quot; &quot;/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libstd-74fa456f.rlib&quot; &quot;/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcollections-74fa456f.rlib&quot; &quot;/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librustc_unicode-74fa456f.rlib&quot; &quot;/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librand-74fa456f.rlib&quot; &quot;/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liballoc-74fa456f.rlib&quot; &quot;/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liblibc-74fa456f.rlib&quot; &quot;/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcore-74fa456f.rlib&quot; &quot;-L&quot; &quot;/Users/nwr/tmp/cargo-test/lib/target/debug&quot; &quot;-L&quot; &quot;/Users/nwr/tmp/cargo-test/lib/target/debug/deps&quot; &quot;-L&quot; &quot;/usr/local/lib/rustlib/x86_64-apple-darwin/lib&quot; &quot;-L&quot; &quot;/Users/nwr/tmp/cargo-test/lib/.rust/lib/x86_64-apple-darwin&quot; &quot;-L&quot; &quot;/Users/nwr/tmp/cargo-test/lib/lib/x86_64-apple-darwin&quot; &quot;-l&quot; &quot;System&quot; &quot;-l&quot; &quot;pthread&quot; &quot;-l&quot; &quot;c&quot; &quot;-l&quot; &quot;m&quot; &quot;-l&quot; &quot;compiler-rt&quot;
note: ld: warning: directory not found for option '-L/Users/nwr/tmp/cargo-test/lib/.rust/lib/x86_64-apple-darwin'
ld: warning: directory not found for option '-L/Users/nwr/tmp/cargo-test/lib/lib/x86_64-apple-darwin'
Undefined symbols for architecture x86_64:
  &quot;helper::Foo::baz::heb3ebf21697cffffkaa&quot;, referenced from:
      test::h63ea6d9d3e0d725cfaa in foo-5f1f39478ede92a5.0.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: aborting due to previous error
Could not compile `lib`.

To learn more, run the command again with --verbose."><pre class="notranslate"><code class="notranslate">── env RUST_BACKTRACE=1 cargo test
   Compiling lib v0.1.0 (file:///Users/nwr/tmp/cargo-test/lib)
error: linking with `cc` failed: exit code: 1
note: "cc" "-m64" "-L" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib" "/Users/nwr/tmp/cargo-test/lib/target/debug/foo-5f1f39478ede92a5.0.o" "-o" "/Users/nwr/tmp/cargo-test/lib/target/debug/foo-5f1f39478ede92a5" "-Wl,-force_load,/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libmorestack.a" "-Wl,-dead_strip" "-nodefaultlibs" "/Users/nwr/tmp/cargo-test/lib/target/debug/liblib.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libtest-74fa456f.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libgetopts-74fa456f.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libserialize-74fa456f.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libterm-74fa456f.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liblog-74fa456f.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libstd-74fa456f.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcollections-74fa456f.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librustc_unicode-74fa456f.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/librand-74fa456f.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liballoc-74fa456f.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/liblibc-74fa456f.rlib" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libcore-74fa456f.rlib" "-L" "/Users/nwr/tmp/cargo-test/lib/target/debug" "-L" "/Users/nwr/tmp/cargo-test/lib/target/debug/deps" "-L" "/usr/local/lib/rustlib/x86_64-apple-darwin/lib" "-L" "/Users/nwr/tmp/cargo-test/lib/.rust/lib/x86_64-apple-darwin" "-L" "/Users/nwr/tmp/cargo-test/lib/lib/x86_64-apple-darwin" "-l" "System" "-l" "pthread" "-l" "c" "-l" "m" "-l" "compiler-rt"
note: ld: warning: directory not found for option '-L/Users/nwr/tmp/cargo-test/lib/.rust/lib/x86_64-apple-darwin'
ld: warning: directory not found for option '-L/Users/nwr/tmp/cargo-test/lib/lib/x86_64-apple-darwin'
Undefined symbols for architecture x86_64:
  "helper::Foo::baz::heb3ebf21697cffffkaa", referenced from:
      test::h63ea6d9d3e0d725cfaa in foo-5f1f39478ede92a5.0.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: aborting due to previous error
Could not compile `lib`.

To learn more, run the command again with --verbose.
</code></pre></div>
<h2 dir="auto">Meta</h2>
<p dir="auto"><code class="notranslate">rustc --version --verbose</code> (repos on 1.1.0 stable as well):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="rustc 1.3.0-nightly (8ce69e856 2015-07-31)
binary: rustc
commit-hash: 8ce69e856a4def6ef39581823520c68944bd1c8e
commit-date: 2015-07-31
host: x86_64-apple-darwin
release: 1.3.0-nightly"><pre class="notranslate"><code class="notranslate">rustc 1.3.0-nightly (8ce69e856 2015-07-31)
binary: rustc
commit-hash: 8ce69e856a4def6ef39581823520c68944bd1c8e
commit-date: 2015-07-31
host: x86_64-apple-darwin
release: 1.3.0-nightly
</code></pre></div>
<p dir="auto">Backtrace: None</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>