Issue 1:
Compilation of:

mod privmod {
pub struct HiddenType;

impl HiddenType {
pub fn hidden_method(&self) {

}
}
}

pub mod pubmod {
use privmod;

pub fn expose() -> privmod::HiddenType {
privmod::HiddenType
}
}

pub use pubmod::expose;

produces the warning:

warning: method is never used: hidden_method, #[warn(dead_code)] on by default

I think it's not correct, because hidden_method can be called from outside the crate by getting an instance of the type via pubmod::expose.

I'd expect Rust to either stop with an error that a private type (private due to being in a private module) is exposed, or figure out that the method is exposed indirectly and assume it's used.

This problem creates another when linking across crates. To reproduce the problem: take the example code above and put it in src/lib.rs of a crate called "library", and then create a crate "tool" with it as a dependency:

tool/Cargo.toml +=

[dependencies.library]
path = "../library"

and src/bin/tool.rs as follows:

extern crate library;

fn main() {
library::expose().hidden_method();
}

cargo run --bin tool will compile, but won't link:

Undefined symbols for architecture x86_64:
"privmod::HiddenType::hidden_method::h4e1e7549e65f404ckaa", referenced from:
main::hb631601ec0f76d56faa in tool.0.o

I'd prefer this to either work, or fail at compilation stage, because linker errors are scary.

rustc 1.4.0-nightly (8f1b0aa 2015-08-21); OS X 11.11

Issue 2:
// foo.rs
pub use foo::Bar;

pub fn test() -> Bar<i32> {
loop {}
}

mod foo {
pub type Bar<T> = Result<T, Baz>;

pub struct Baz;

impl Baz {
pub fn foo(&self) {}
}
}

// bar.rs
extern crate foo;

fn main() {
match foo::test() {
Ok(..) => {}
Err(e) => e.foo()
}
}

$ 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(&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

There are a number of problems with this, and they may likely all be inter-related.

linker error

dead code which is not actually dead code

it should be an error that Baz is a publicly visible private type.

Nominating due to the publicly visible private type not generating an error.