about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-02-02 09:39:59 +0000
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-02-24 01:34:20 +0000
commitf8d6dcf46ec646a41d0dc222764cc0ed026ceb03 (patch)
treed1c7431e35806d24051742d9325c1f11ed326ba8 /src
parent3358fb11da258007d26cc27364455c610088d630 (diff)
downloadrust-f8d6dcf46ec646a41d0dc222764cc0ed026ceb03.tar.gz
rust-f8d6dcf46ec646a41d0dc222764cc0ed026ceb03.zip
Warn when reexporting a private extern crate
Diffstat (limited to 'src')
-rw-r--r--src/librustc/lib.rs4
-rw-r--r--src/librustc_resolve/resolve_imports.rs25
-rw-r--r--src/librustc_trans/lib.rs2
-rw-r--r--src/libstd/sys/unix/net.rs2
-rw-r--r--src/test/compile-fail/private-variant-and-crate-reexport.rs (renamed from src/test/compile-fail/private-variant-reexport.rs)4
5 files changed, 24 insertions, 13 deletions
diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs
index 53fd867e7fd..bd256d19b67 100644
--- a/src/librustc/lib.rs
+++ b/src/librustc/lib.rs
@@ -51,7 +51,7 @@ extern crate getopts;
 extern crate graphviz;
 extern crate libc;
 extern crate rbml;
-extern crate rustc_llvm;
+pub extern crate rustc_llvm as llvm;
 extern crate rustc_back;
 extern crate rustc_front;
 extern crate rustc_data_structures;
@@ -66,8 +66,6 @@ extern crate serialize as rustc_serialize; // used by deriving
 #[cfg(test)]
 extern crate test;
 
-pub use rustc_llvm as llvm;
-
 #[macro_use]
 mod macros;
 
diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs
index 4cefffce777..4776c83b94c 100644
--- a/src/librustc_resolve/resolve_imports.rs
+++ b/src/librustc_resolve/resolve_imports.rs
@@ -402,14 +402,23 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
             }
 
             (_, &Success(name_binding)) if !name_binding.is_import() && directive.is_public => {
-                // Disallow reexporting private items, excepting extern crates.
-                if !name_binding.is_public() && !name_binding.is_extern_crate() {
-                    let msg = format!("`{}` is private, and cannot be reexported", source);
-                    let note_msg =
-                        format!("Consider declaring type or module `{}` with `pub`", source);
-                    struct_span_err!(self.resolver.session, directive.span, E0365, "{}", &msg)
-                        .span_note(directive.span, &note_msg)
-                        .emit();
+                if !name_binding.is_public() {
+                    if name_binding.is_extern_crate() {
+                        let msg = format!("extern crate `{}` is private, and cannot be reexported \
+                                           (error E0364), consider declaring with `pub`",
+                                           source);
+                        self.resolver.session.add_lint(lint::builtin::PRIVATE_IN_PUBLIC,
+                                                       directive.id,
+                                                       directive.span,
+                                                       msg);
+                    } else {
+                        let msg = format!("`{}` is private, and cannot be reexported", source);
+                        let note_msg =
+                            format!("Consider declaring type or module `{}` with `pub`", source);
+                        struct_span_err!(self.resolver.session, directive.span, E0365, "{}", &msg)
+                            .span_note(directive.span, &note_msg)
+                            .emit();
+                    }
                 } else if name_binding.defined_with(DefModifiers::PRIVATE_VARIANT) {
                     let msg = format!("variant `{}` is private, and cannot be reexported \
                                        (error E0364), consider declaring its enum as `pub`",
diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs
index 27d6dbae28a..6f596b15b92 100644
--- a/src/librustc_trans/lib.rs
+++ b/src/librustc_trans/lib.rs
@@ -46,7 +46,7 @@ extern crate rustc;
 extern crate rustc_back;
 extern crate rustc_data_structures;
 extern crate rustc_front;
-extern crate rustc_llvm as llvm;
+pub extern crate rustc_llvm as llvm;
 extern crate rustc_mir;
 extern crate rustc_platform_intrinsics as intrinsics;
 extern crate serialize;
diff --git a/src/libstd/sys/unix/net.rs b/src/libstd/sys/unix/net.rs
index 507cc0f4ea4..16c369674f0 100644
--- a/src/libstd/sys/unix/net.rs
+++ b/src/libstd/sys/unix/net.rs
@@ -21,7 +21,7 @@ use sys_common::net::{getsockopt, setsockopt};
 use time::Duration;
 
 pub use sys::{cvt, cvt_r};
-pub use libc as netc;
+pub extern crate libc as netc;
 
 pub type wrlen_t = size_t;
 
diff --git a/src/test/compile-fail/private-variant-reexport.rs b/src/test/compile-fail/private-variant-and-crate-reexport.rs
index 06f08dc13c6..5811d82681e 100644
--- a/src/test/compile-fail/private-variant-reexport.rs
+++ b/src/test/compile-fail/private-variant-and-crate-reexport.rs
@@ -11,6 +11,10 @@
 #![feature(rustc_attrs)]
 #![allow(dead_code)]
 
+extern crate core;
+pub use core as reexported_core; //~ WARN extern crate `core` is private, and cannot be reexported
+//~^ WARNING hard error
+
 mod m1 {
     pub use ::E::V; //~ WARN variant `V` is private, and cannot be reexported
     //~^ WARNING hard error