Turn public reexporting of private extern crates into a lint again

This commit is contained in:
Vadim Petrochenkov 2017-05-21 15:50:38 +03:00
parent caecb76f08
commit d73a0fef38
2 changed files with 14 additions and 2 deletions

View File

@ -18,6 +18,7 @@ use {names_to_string, module_to_string};
use {resolve_error, ResolutionError}; use {resolve_error, ResolutionError};
use rustc::ty; use rustc::ty;
use rustc::lint::builtin::PRIVATE_IN_PUBLIC;
use rustc::hir::def_id::DefId; use rustc::hir::def_id::DefId;
use rustc::hir::def::*; use rustc::hir::def::*;
use rustc::util::nodemap::FxHashMap; use rustc::util::nodemap::FxHashMap;
@ -294,7 +295,8 @@ impl<'a> Resolver<'a> {
// return the corresponding binding defined by the import directive. // return the corresponding binding defined by the import directive.
pub fn import(&self, binding: &'a NameBinding<'a>, directive: &'a ImportDirective<'a>) pub fn import(&self, binding: &'a NameBinding<'a>, directive: &'a ImportDirective<'a>)
-> &'a NameBinding<'a> { -> &'a NameBinding<'a> {
let vis = if binding.pseudo_vis().is_at_least(directive.vis.get(), self) { let vis = if binding.pseudo_vis().is_at_least(directive.vis.get(), self) ||
!directive.is_glob() && binding.is_extern_crate() { // c.f. `PRIVATE_IN_PUBLIC`
directive.vis.get() directive.vis.get()
} else { } else {
binding.pseudo_vis() binding.pseudo_vis()
@ -718,7 +720,13 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
// All namespaces must be re-exported with extra visibility for an error to occur. // All namespaces must be re-exported with extra visibility for an error to occur.
if !any_successful_reexport { if !any_successful_reexport {
if reexport_error.unwrap().0 == TypeNS { let (ns, binding) = reexport_error.unwrap();
if ns == TypeNS && binding.is_extern_crate() {
let msg = format!("extern crate `{}` is private, and cannot be reexported \
(error E0365), consider declaring with `pub`",
ident);
self.session.add_lint(PRIVATE_IN_PUBLIC, directive.id, directive.span, msg);
} else if ns == TypeNS {
struct_span_err!(self.session, directive.span, E0365, struct_span_err!(self.session, directive.span, E0365,
"`{}` is private, and cannot be reexported", ident) "`{}` is private, and cannot be reexported", ident)
.span_label(directive.span, format!("reexport of private `{}`", ident)) .span_label(directive.span, format!("reexport of private `{}`", ident))

View File

@ -9,9 +9,11 @@
// except according to those terms. // except according to those terms.
#![allow(unused)] #![allow(unused)]
#![deny(private_in_public)]
extern crate core; extern crate core;
pub use core as reexported_core; //~ ERROR `core` is private, and cannot be reexported pub use core as reexported_core; //~ ERROR `core` is private, and cannot be reexported
//~^ WARN this was previously accepted
mod foo1 { mod foo1 {
extern crate core; extern crate core;
@ -19,6 +21,7 @@ mod foo1 {
mod foo2 { mod foo2 {
use foo1::core; //~ ERROR `core` is private, and cannot be reexported use foo1::core; //~ ERROR `core` is private, and cannot be reexported
//~^ WARN this was previously accepted
pub mod bar { pub mod bar {
extern crate core; extern crate core;
} }
@ -26,6 +29,7 @@ mod foo2 {
mod baz { mod baz {
pub use foo2::bar::core; //~ ERROR `core` is private, and cannot be reexported pub use foo2::bar::core; //~ ERROR `core` is private, and cannot be reexported
//~^ WARN this was previously accepted
} }
fn main() {} fn main() {}