"detect private items in public interfaces not caught by the old implementation"
}
+declare_lint! {
+ pub INACCESSIBLE_EXTERN_CRATE,
+ Warn,
+ "use of inaccessible extern crate erroneously allowed"
+}
+
declare_lint! {
pub INVALID_TYPE_PARAM_DEFAULT,
Warn,
TRIVIAL_CASTS,
TRIVIAL_NUMERIC_CASTS,
PRIVATE_IN_PUBLIC,
+ INACCESSIBLE_EXTERN_CRATE,
INVALID_TYPE_PARAM_DEFAULT,
MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT,
CONST_ERR,
id: LintId::of(PRIVATE_IN_PUBLIC),
reference: "the explanation for E0446 (`--explain E0446`)",
},
+ FutureIncompatibleInfo {
+ id: LintId::of(INACCESSIBLE_EXTERN_CRATE),
+ reference: "PR 31362 <https://github.com/rust-lang/rust/pull/31362>",
+ },
FutureIncompatibleInfo {
id: LintId::of(INVALID_TYPE_PARAM_DEFAULT),
reference: "PR 30742 <https://github.com/rust-lang/rust/pull/30724>",
source_did: Option<DefId>,
msg: &str)
-> CheckResult {
+ use rustc_front::hir::Item_::ItemExternCrate;
debug!("ensure_public(span={:?}, to_check={:?}, source_did={:?}, msg={:?})",
span, to_check, source_did, msg);
let def_privacy = self.def_privacy(to_check);
// be local.)
let def_id = source_did.unwrap_or(to_check);
let node_id = self.tcx.map.as_local_node_id(def_id);
+
+ // Warn when using a inaccessible extern crate.
+ if let Some(node_id) = self.tcx.map.as_local_node_id(to_check) {
+ match self.tcx.map.get(node_id) {
+ ast_map::Node::NodeItem(&hir::Item { node: ItemExternCrate(_), name, .. }) => {
+ self.tcx.sess.add_lint(lint::builtin::INACCESSIBLE_EXTERN_CRATE,
+ node_id,
+ span,
+ format!("extern crate `{}` is private", name));
+ return None;
+ }
+ _ => {}
+ }
+ }
+
let (err_span, err_msg) = if Some(id) == node_id {
return Some((span, format!("{} is private", msg), None));
} else {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#![feature(rustc_attrs)]
+#![allow(dead_code)]
+#![allow(unused_imports)]
+
mod foo {
extern crate core;
- pub use self::core as reexported_core; // Check that private extern crates can be reexported
}
-// Check that private crates cannot be used from outside their modules
-use foo::core; //~ ERROR module `core` is inaccessible
-use foo::core::cell; //~ ERROR
+// Check that private crates can be used from outside their modules, albeit with warnings
+use foo::core; //~ WARN extern crate `core` is private
+//~^ WARN this was previously accepted by the compiler but is being phased out
+use foo::core::cell; //~ WARN extern crate `core` is private
+//~^ WARN this was previously accepted by the compiler but is being phased out
+
+fn f() {
+ foo::core::cell::Cell::new(0); //~ WARN extern crate `core` is private
+ //~^ WARN this was previously accepted by the compiler but is being phased out
-fn main() {
use foo::*;
mod core {} // Check that private crates are not glob imported
}
+
+#[rustc_error]
+fn main() {} //~ ERROR compilation successful