Skip to content

Commit d73a0fe

Browse files
committed
Turn public reexporting of private extern crates into a lint again
1 parent caecb76 commit d73a0fe

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/librustc_resolve/resolve_imports.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use {names_to_string, module_to_string};
1818
use {resolve_error, ResolutionError};
1919

2020
use rustc::ty;
21+
use rustc::lint::builtin::PRIVATE_IN_PUBLIC;
2122
use rustc::hir::def_id::DefId;
2223
use rustc::hir::def::*;
2324
use rustc::util::nodemap::FxHashMap;
@@ -294,7 +295,8 @@ impl<'a> Resolver<'a> {
294295
// return the corresponding binding defined by the import directive.
295296
pub fn import(&self, binding: &'a NameBinding<'a>, directive: &'a ImportDirective<'a>)
296297
-> &'a NameBinding<'a> {
297-
let vis = if binding.pseudo_vis().is_at_least(directive.vis.get(), self) {
298+
let vis = if binding.pseudo_vis().is_at_least(directive.vis.get(), self) ||
299+
!directive.is_glob() && binding.is_extern_crate() { // c.f. `PRIVATE_IN_PUBLIC`
298300
directive.vis.get()
299301
} else {
300302
binding.pseudo_vis()
@@ -718,7 +720,13 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
718720

719721
// All namespaces must be re-exported with extra visibility for an error to occur.
720722
if !any_successful_reexport {
721-
if reexport_error.unwrap().0 == TypeNS {
723+
let (ns, binding) = reexport_error.unwrap();
724+
if ns == TypeNS && binding.is_extern_crate() {
725+
let msg = format!("extern crate `{}` is private, and cannot be reexported \
726+
(error E0365), consider declaring with `pub`",
727+
ident);
728+
self.session.add_lint(PRIVATE_IN_PUBLIC, directive.id, directive.span, msg);
729+
} else if ns == TypeNS {
722730
struct_span_err!(self.session, directive.span, E0365,
723731
"`{}` is private, and cannot be reexported", ident)
724732
.span_label(directive.span, format!("reexport of private `{}`", ident))

src/test/compile-fail/pub-reexport-priv-extern-crate.rs

+4
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,27 @@
99
// except according to those terms.
1010

1111
#![allow(unused)]
12+
#![deny(private_in_public)]
1213

1314
extern crate core;
1415
pub use core as reexported_core; //~ ERROR `core` is private, and cannot be reexported
16+
//~^ WARN this was previously accepted
1517

1618
mod foo1 {
1719
extern crate core;
1820
}
1921

2022
mod foo2 {
2123
use foo1::core; //~ ERROR `core` is private, and cannot be reexported
24+
//~^ WARN this was previously accepted
2225
pub mod bar {
2326
extern crate core;
2427
}
2528
}
2629

2730
mod baz {
2831
pub use foo2::bar::core; //~ ERROR `core` is private, and cannot be reexported
32+
//~^ WARN this was previously accepted
2933
}
3034

3135
fn main() {}

0 commit comments

Comments
 (0)