Skip to content

Commit e9cf215

Browse files
committed
---
yaml --- r: 275190 b: refs/heads/stable c: 5172745 h: refs/heads/master
1 parent 11634d9 commit e9cf215

File tree

5 files changed

+44
-6
lines changed

5 files changed

+44
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: c0221c8897db309a79990367476177b1230bb264
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: f8d6dcf46ec646a41d0dc222764cc0ed026ceb03
32+
refs/heads/stable: 5172745da761842a40a625c804f5e0360586996d
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e

branches/stable/src/librustc/lint/builtin.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ declare_lint! {
124124
"detect private items in public interfaces not caught by the old implementation"
125125
}
126126

127+
declare_lint! {
128+
pub INACCESSIBLE_EXTERN_CRATE,
129+
Warn,
130+
"use of inaccessible extern crate erroneously allowed"
131+
}
132+
127133
declare_lint! {
128134
pub INVALID_TYPE_PARAM_DEFAULT,
129135
Warn,
@@ -167,6 +173,7 @@ impl LintPass for HardwiredLints {
167173
TRIVIAL_CASTS,
168174
TRIVIAL_NUMERIC_CASTS,
169175
PRIVATE_IN_PUBLIC,
176+
INACCESSIBLE_EXTERN_CRATE,
170177
INVALID_TYPE_PARAM_DEFAULT,
171178
MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT,
172179
CONST_ERR,

branches/stable/src/librustc_lint/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
158158
id: LintId::of(PRIVATE_IN_PUBLIC),
159159
reference: "the explanation for E0446 (`--explain E0446`)",
160160
},
161+
FutureIncompatibleInfo {
162+
id: LintId::of(INACCESSIBLE_EXTERN_CRATE),
163+
reference: "PR 31362 <https://github.com/rust-lang/rust/pull/31362>",
164+
},
161165
FutureIncompatibleInfo {
162166
id: LintId::of(INVALID_TYPE_PARAM_DEFAULT),
163167
reference: "PR 30742 <https://github.com/rust-lang/rust/pull/30724>",

branches/stable/src/librustc_privacy/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
743743
source_did: Option<DefId>,
744744
msg: &str)
745745
-> CheckResult {
746+
use rustc_front::hir::Item_::ItemExternCrate;
746747
debug!("ensure_public(span={:?}, to_check={:?}, source_did={:?}, msg={:?})",
747748
span, to_check, source_did, msg);
748749
let def_privacy = self.def_privacy(to_check);
@@ -763,6 +764,21 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
763764
// be local.)
764765
let def_id = source_did.unwrap_or(to_check);
765766
let node_id = self.tcx.map.as_local_node_id(def_id);
767+
768+
// Warn when using a inaccessible extern crate.
769+
if let Some(node_id) = self.tcx.map.as_local_node_id(to_check) {
770+
match self.tcx.map.get(node_id) {
771+
ast_map::Node::NodeItem(&hir::Item { node: ItemExternCrate(_), name, .. }) => {
772+
self.tcx.sess.add_lint(lint::builtin::INACCESSIBLE_EXTERN_CRATE,
773+
node_id,
774+
span,
775+
format!("extern crate `{}` is private", name));
776+
return None;
777+
}
778+
_ => {}
779+
}
780+
}
781+
766782
let (err_span, err_msg) = if Some(id) == node_id {
767783
return Some((span, format!("{} is private", msg), None));
768784
} else {

branches/stable/src/test/compile-fail/extern-crate-visibility.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,27 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(rustc_attrs)]
12+
#![allow(dead_code)]
13+
#![allow(unused_imports)]
14+
1115
mod foo {
1216
extern crate core;
13-
pub use self::core as reexported_core; // Check that private extern crates can be reexported
1417
}
1518

16-
// Check that private crates cannot be used from outside their modules
17-
use foo::core; //~ ERROR module `core` is inaccessible
18-
use foo::core::cell; //~ ERROR
19+
// Check that private crates can be used from outside their modules, albeit with warnings
20+
use foo::core; //~ WARN extern crate `core` is private
21+
//~^ WARN this was previously accepted by the compiler but is being phased out
22+
use foo::core::cell; //~ WARN extern crate `core` is private
23+
//~^ WARN this was previously accepted by the compiler but is being phased out
24+
25+
fn f() {
26+
foo::core::cell::Cell::new(0); //~ WARN extern crate `core` is private
27+
//~^ WARN this was previously accepted by the compiler but is being phased out
1928

20-
fn main() {
2129
use foo::*;
2230
mod core {} // Check that private crates are not glob imported
2331
}
32+
33+
#[rustc_error]
34+
fn main() {} //~ ERROR compilation successful

0 commit comments

Comments
 (0)