diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2017-06-25 05:50:51 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2017-07-08 01:56:27 +0300 |
| commit | bdffb9722d9330d3815be356a5ccedae07555328 (patch) | |
| tree | d64f9a32d8bb0f9f3d1ddc6673625d75baa8b035 | |
| parent | 96bcdac9e483e0e7d8a02f82c0ab961a536cafc4 (diff) | |
| download | rust-bdffb9722d9330d3815be356a5ccedae07555328.tar.gz rust-bdffb9722d9330d3815be356a5ccedae07555328.zip | |
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.
| -rw-r--r-- | src/librustc/lint/builtin.rs | 7 | ||||
| -rw-r--r-- | src/librustc_lint/lib.rs | 4 | ||||
| -rw-r--r-- | src/librustc_resolve/resolve_imports.rs | 8 | ||||
| -rw-r--r-- | src/test/compile-fail/pub-reexport-priv-extern-crate.rs | 1 |
4 files changed, 16 insertions, 4 deletions
diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index dd6e78b87af..ce120a32d90 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -131,6 +131,12 @@ declare_lint! { } declare_lint! { + pub PUB_USE_OF_PRIVATE_EXTERN_CRATE, + Deny, + "detect public reexports of private extern crates" +} + +declare_lint! { pub INVALID_TYPE_PARAM_DEFAULT, Deny, "type parameter default erroneously allowed in invalid location" @@ -230,6 +236,7 @@ impl LintPass for HardwiredLints { TRIVIAL_CASTS, TRIVIAL_NUMERIC_CASTS, PRIVATE_IN_PUBLIC, + PUB_USE_OF_PRIVATE_EXTERN_CRATE, INVALID_TYPE_PARAM_DEFAULT, CONST_ERR, RENAMED_AND_REMOVED_LINTS, diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index f5c43c7b57d..a03f12c3dfb 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -185,6 +185,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>", }, FutureIncompatibleInfo { + id: LintId::of(PUB_USE_OF_PRIVATE_EXTERN_CRATE), + reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>", + }, + FutureIncompatibleInfo { id: LintId::of(PATTERNS_IN_FNS_WITHOUT_BODY), reference: "issue #35203 <https://github.com/rust-lang/rust/issues/35203>", }, diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 405b2ed6ba9..4bff5da3d6b 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -18,7 +18,7 @@ use {names_to_string, module_to_string}; use {resolve_error, ResolutionError}; use rustc::ty; -use rustc::lint::builtin::PRIVATE_IN_PUBLIC; +use rustc::lint::builtin::PUB_USE_OF_PRIVATE_EXTERN_CRATE; use rustc::hir::def_id::DefId; use rustc::hir::def::*; use rustc::util::nodemap::FxHashMap; @@ -296,7 +296,8 @@ impl<'a> Resolver<'a> { pub fn import(&self, binding: &'a NameBinding<'a>, directive: &'a ImportDirective<'a>) -> &'a NameBinding<'a> { 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` + // c.f. `PUB_USE_OF_PRIVATE_EXTERN_CRATE` + !directive.is_glob() && binding.is_extern_crate() { directive.vis.get() } else { binding.pseudo_vis() @@ -735,7 +736,8 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { 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); + self.session.add_lint(PUB_USE_OF_PRIVATE_EXTERN_CRATE, + directive.id, directive.span, msg); } else if ns == TypeNS { struct_span_err!(self.session, directive.span, E0365, "`{}` is private, and cannot be reexported", ident) diff --git a/src/test/compile-fail/pub-reexport-priv-extern-crate.rs b/src/test/compile-fail/pub-reexport-priv-extern-crate.rs index 185da379694..5479be54533 100644 --- a/src/test/compile-fail/pub-reexport-priv-extern-crate.rs +++ b/src/test/compile-fail/pub-reexport-priv-extern-crate.rs @@ -9,7 +9,6 @@ // except according to those terms. #![allow(unused)] -#![deny(private_in_public)] extern crate core; pub use core as reexported_core; //~ ERROR `core` is private, and cannot be reexported |
