]> git.lizzy.rs Git - rust.git/commitdiff
Warn when reexporting a private extern crate
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Tue, 2 Feb 2016 09:39:59 +0000 (09:39 +0000)
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Wed, 24 Feb 2016 01:34:20 +0000 (01:34 +0000)
src/librustc/lib.rs
src/librustc_resolve/resolve_imports.rs
src/librustc_trans/lib.rs
src/libstd/sys/unix/net.rs
src/test/compile-fail/private-variant-and-crate-reexport.rs [new file with mode: 0644]
src/test/compile-fail/private-variant-reexport.rs [deleted file]

index 53fd867e7fd487158d6a3002a5b2ea9dab468655..bd256d19b6725653a302f979089fbc389c62d620 100644 (file)
@@ -51,7 +51,7 @@
 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 @@
 #[cfg(test)]
 extern crate test;
 
-pub use rustc_llvm as llvm;
-
 #[macro_use]
 mod macros;
 
index 4cefffce777f7c460e2fa6daf0af8e8d7c424aba..4776c83b94cf110dcb5e389f4e244710fa34ef37 100644 (file)
@@ -402,14 +402,23 @@ fn resolve_single_import(&mut self,
             }
 
             (_, &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`",
index 27d6dbae28a67e55be0234e7b8e84ae26043258c..6f596b15b9214fd29b4832f76314021760aa6b54 100644 (file)
@@ -46,7 +46,7 @@
 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;
index 507cc0f4ea46191e930fc0ced1ba266dc7843910..16c369674f0a2e2bf90f8f80952135480fff1328 100644 (file)
@@ -21,7 +21,7 @@
 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-and-crate-reexport.rs b/src/test/compile-fail/private-variant-and-crate-reexport.rs
new file mode 100644 (file)
index 0000000..5811d82
--- /dev/null
@@ -0,0 +1,41 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![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
+}
+
+mod m2 {
+    pub use ::E::{V}; //~ WARN variant `V` is private, and cannot be reexported
+    //~^ WARNING hard error
+}
+
+mod m3 {
+    pub use ::E::V::{self}; //~ WARN variant `V` is private, and cannot be reexported
+    //~^ WARNING hard error
+}
+
+mod m4 {
+    pub use ::E::*; //~ WARN variant `V` is private, and cannot be reexported
+    //~^ WARNING hard error
+}
+
+enum E { V }
+
+#[rustc_error]
+fn main() {} //~ ERROR compilation successful
diff --git a/src/test/compile-fail/private-variant-reexport.rs b/src/test/compile-fail/private-variant-reexport.rs
deleted file mode 100644 (file)
index 06f08dc..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![feature(rustc_attrs)]
-#![allow(dead_code)]
-
-mod m1 {
-    pub use ::E::V; //~ WARN variant `V` is private, and cannot be reexported
-    //~^ WARNING hard error
-}
-
-mod m2 {
-    pub use ::E::{V}; //~ WARN variant `V` is private, and cannot be reexported
-    //~^ WARNING hard error
-}
-
-mod m3 {
-    pub use ::E::V::{self}; //~ WARN variant `V` is private, and cannot be reexported
-    //~^ WARNING hard error
-}
-
-mod m4 {
-    pub use ::E::*; //~ WARN variant `V` is private, and cannot be reexported
-    //~^ WARNING hard error
-}
-
-enum E { V }
-
-#[rustc_error]
-fn main() {} //~ ERROR compilation successful