Skip to content

Commit bdffb97

Browse files
committed
Move public reexports of private extern crates into a separate lint
This is going to be a hard error while all private-in-public errors from rustc_privacy will be reclassified into lints.
1 parent 96bcdac commit bdffb97

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

src/librustc/lint/builtin.rs

+7
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ declare_lint! {
130130
"detect private items in public interfaces not caught by the old implementation"
131131
}
132132

133+
declare_lint! {
134+
pub PUB_USE_OF_PRIVATE_EXTERN_CRATE,
135+
Deny,
136+
"detect public reexports of private extern crates"
137+
}
138+
133139
declare_lint! {
134140
pub INVALID_TYPE_PARAM_DEFAULT,
135141
Deny,
@@ -230,6 +236,7 @@ impl LintPass for HardwiredLints {
230236
TRIVIAL_CASTS,
231237
TRIVIAL_NUMERIC_CASTS,
232238
PRIVATE_IN_PUBLIC,
239+
PUB_USE_OF_PRIVATE_EXTERN_CRATE,
233240
INVALID_TYPE_PARAM_DEFAULT,
234241
CONST_ERR,
235242
RENAMED_AND_REMOVED_LINTS,

src/librustc_lint/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
184184
id: LintId::of(PRIVATE_IN_PUBLIC),
185185
reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",
186186
},
187+
FutureIncompatibleInfo {
188+
id: LintId::of(PUB_USE_OF_PRIVATE_EXTERN_CRATE),
189+
reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",
190+
},
187191
FutureIncompatibleInfo {
188192
id: LintId::of(PATTERNS_IN_FNS_WITHOUT_BODY),
189193
reference: "issue #35203 <https://github.com/rust-lang/rust/issues/35203>",

src/librustc_resolve/resolve_imports.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +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;
21+
use rustc::lint::builtin::PUB_USE_OF_PRIVATE_EXTERN_CRATE;
2222
use rustc::hir::def_id::DefId;
2323
use rustc::hir::def::*;
2424
use rustc::util::nodemap::FxHashMap;
@@ -296,7 +296,8 @@ impl<'a> Resolver<'a> {
296296
pub fn import(&self, binding: &'a NameBinding<'a>, directive: &'a ImportDirective<'a>)
297297
-> &'a NameBinding<'a> {
298298
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`
299+
// c.f. `PUB_USE_OF_PRIVATE_EXTERN_CRATE`
300+
!directive.is_glob() && binding.is_extern_crate() {
300301
directive.vis.get()
301302
} else {
302303
binding.pseudo_vis()
@@ -735,7 +736,8 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
735736
let msg = format!("extern crate `{}` is private, and cannot be reexported \
736737
(error E0365), consider declaring with `pub`",
737738
ident);
738-
self.session.add_lint(PRIVATE_IN_PUBLIC, directive.id, directive.span, msg);
739+
self.session.add_lint(PUB_USE_OF_PRIVATE_EXTERN_CRATE,
740+
directive.id, directive.span, msg);
739741
} else if ns == TypeNS {
740742
struct_span_err!(self.session, directive.span, E0365,
741743
"`{}` is private, and cannot be reexported", ident)

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

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
#![allow(unused)]
12-
#![deny(private_in_public)]
1312

1413
extern crate core;
1514
pub use core as reexported_core; //~ ERROR `core` is private, and cannot be reexported

0 commit comments

Comments
 (0)