1
Fork 0

Warn when reexporting a private extern crate

This commit is contained in:
Jeffrey Seyfried 2016-02-02 09:39:59 +00:00
parent 3358fb11da
commit f8d6dcf46e
5 changed files with 24 additions and 13 deletions

View file

@ -51,7 +51,7 @@ extern crate getopts;
extern crate graphviz; extern crate graphviz;
extern crate libc; extern crate libc;
extern crate rbml; extern crate rbml;
extern crate rustc_llvm; pub extern crate rustc_llvm as llvm;
extern crate rustc_back; extern crate rustc_back;
extern crate rustc_front; extern crate rustc_front;
extern crate rustc_data_structures; extern crate rustc_data_structures;
@ -66,8 +66,6 @@ extern crate serialize as rustc_serialize; // used by deriving
#[cfg(test)] #[cfg(test)]
extern crate test; extern crate test;
pub use rustc_llvm as llvm;
#[macro_use] #[macro_use]
mod macros; mod macros;

View file

@ -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 => { (_, &Success(name_binding)) if !name_binding.is_import() && directive.is_public => {
// Disallow reexporting private items, excepting extern crates. if !name_binding.is_public() {
if !name_binding.is_public() && !name_binding.is_extern_crate() { 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 msg = format!("`{}` is private, and cannot be reexported", source);
let note_msg = let note_msg =
format!("Consider declaring type or module `{}` with `pub`", source); format!("Consider declaring type or module `{}` with `pub`", source);
struct_span_err!(self.resolver.session, directive.span, E0365, "{}", &msg) struct_span_err!(self.resolver.session, directive.span, E0365, "{}", &msg)
.span_note(directive.span, &note_msg) .span_note(directive.span, &note_msg)
.emit(); .emit();
}
} else if name_binding.defined_with(DefModifiers::PRIVATE_VARIANT) { } else if name_binding.defined_with(DefModifiers::PRIVATE_VARIANT) {
let msg = format!("variant `{}` is private, and cannot be reexported \ let msg = format!("variant `{}` is private, and cannot be reexported \
(error E0364), consider declaring its enum as `pub`", (error E0364), consider declaring its enum as `pub`",

View file

@ -46,7 +46,7 @@ extern crate rustc;
extern crate rustc_back; extern crate rustc_back;
extern crate rustc_data_structures; extern crate rustc_data_structures;
extern crate rustc_front; extern crate rustc_front;
extern crate rustc_llvm as llvm; pub extern crate rustc_llvm as llvm;
extern crate rustc_mir; extern crate rustc_mir;
extern crate rustc_platform_intrinsics as intrinsics; extern crate rustc_platform_intrinsics as intrinsics;
extern crate serialize; extern crate serialize;

View file

@ -21,7 +21,7 @@ use sys_common::net::{getsockopt, setsockopt};
use time::Duration; use time::Duration;
pub use sys::{cvt, cvt_r}; pub use sys::{cvt, cvt_r};
pub use libc as netc; pub extern crate libc as netc;
pub type wrlen_t = size_t; pub type wrlen_t = size_t;

View file

@ -11,6 +11,10 @@
#![feature(rustc_attrs)] #![feature(rustc_attrs)]
#![allow(dead_code)] #![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 { mod m1 {
pub use ::E::V; //~ WARN variant `V` is private, and cannot be reexported pub use ::E::V; //~ WARN variant `V` is private, and cannot be reexported
//~^ WARNING hard error //~^ WARNING hard error