Skip to content

Commit 48ec29d

Browse files
committed
Replace --extern-public with --extern-private
1 parent b29a21f commit 48ec29d

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

src/librustc/session/config.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,9 @@ top_level_options!(
412412

413413
edition: Edition [TRACKED],
414414

415-
// The list of crates to consider public for
415+
// The list of crates to consider private when
416416
// checking leaked private dependency types in public interfaces
417-
extern_public: Option<Vec<String>> [TRACKED],
417+
extern_private: Vec<String> [TRACKED],
418418
}
419419
);
420420

@@ -610,7 +610,7 @@ impl Default for Options {
610610
cli_forced_thinlto_off: false,
611611
remap_path_prefix: Vec::new(),
612612
edition: DEFAULT_EDITION,
613-
extern_public: None
613+
extern_private: Vec::new()
614614
}
615615
}
616616
}
@@ -1736,6 +1736,12 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
17361736
"Specify where an external rust library is located",
17371737
"NAME=PATH",
17381738
),
1739+
opt::multi_s(
1740+
"",
1741+
"extern-private",
1742+
"Specify where an extern rust library is located, marking it as a private dependency",
1743+
"NAME=PATH",
1744+
),
17391745
opt::opt_s("", "sysroot", "Override the system root", "PATH"),
17401746
opt::multi("Z", "", "Set internal debugging options", "FLAG"),
17411747
opt::opt_s(
@@ -1936,22 +1942,7 @@ pub fn build_session_options_and_crate_config(
19361942
);
19371943
}
19381944

1939-
if matches.opt_present("extern-public") && !debugging_opts.unstable_options {
1940-
early_error(
1941-
ErrorOutputType::default(),
1942-
"'--extern-public' is unstable and only \
1943-
available for nightly builds of rustc."
1944-
)
1945-
}
1946-
1947-
let mut extern_public: Option<Vec<String>> = matches.opt_str("extern-public").
1948-
map(|s| s.split(',').map(|c| (*c).to_string()).collect());
19491945

1950-
// FIXME - come up with a better way of handling this
1951-
if let Some(p) = extern_public.as_mut() {
1952-
p.push("core".to_string());
1953-
p.push("std".to_string());
1954-
}
19551946

19561947

19571948
let mut output_types = BTreeMap::new();
@@ -2249,8 +2240,18 @@ pub fn build_session_options_and_crate_config(
22492240
);
22502241
}
22512242

2243+
if matches.opt_present("extern-private") && !debugging_opts.unstable_options {
2244+
early_error(
2245+
ErrorOutputType::default(),
2246+
"'--extern-private' is unstable and only \
2247+
available for nightly builds of rustc."
2248+
)
2249+
}
2250+
2251+
let extern_private = matches.opt_strs("extern-private");
2252+
22522253
let mut externs: BTreeMap<_, BTreeSet<_>> = BTreeMap::new();
2253-
for arg in &matches.opt_strs("extern") {
2254+
for arg in matches.opt_strs("extern").into_iter().chain(matches.opt_strs("extern-private")) {
22542255
let mut parts = arg.splitn(2, '=');
22552256
let name = parts.next().unwrap_or_else(||
22562257
early_error(error_format, "--extern value must not be empty"));
@@ -2318,7 +2319,7 @@ pub fn build_session_options_and_crate_config(
23182319
cli_forced_thinlto_off: disable_thinlto,
23192320
remap_path_prefix,
23202321
edition,
2321-
extern_public
2322+
extern_private
23222323
},
23232324
cfg,
23242325
)

src/librustc_privacy/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,7 @@ struct SearchInterfaceForPrivateItemsVisitor<'a, 'tcx: 'a> {
14601460
has_pub_restricted: bool,
14611461
has_old_errors: bool,
14621462
in_assoc_ty: bool,
1463-
public_crates: Option<FxHashSet<CrateNum>>
1463+
private_crates: FxHashSet<CrateNum>
14641464
}
14651465

14661466
impl<'a, 'tcx: 'a> SearchInterfaceForPrivateItemsVisitor<'a, 'tcx> {
@@ -1538,13 +1538,13 @@ impl<'a, 'tcx: 'a> SearchInterfaceForPrivateItemsVisitor<'a, 'tcx> {
15381538
/// 1. It's contained within a public type
15391539
/// 2. It does not come from a crate marked as public
15401540
fn leaks_private_dep(&self, item_id: DefId) -> bool {
1541-
// Don't do any leak checking if no public crates were specified
1542-
if self.public_crates.is_none() {
1541+
// Don't do any leak checking if no private crates were specified
1542+
if self.private_crates.is_empty() {
15431543
return false
15441544
}
15451545
let ret = self.required_visibility == ty::Visibility::Public &&
15461546
!item_id.is_local() &&
1547-
!self.public_crates.as_ref().unwrap().contains(&item_id.krate);
1547+
self.private_crates.contains(&item_id.krate);
15481548

15491549

15501550
debug!("leaks_private_dep(item_id={:?})={}", item_id, ret);
@@ -1563,7 +1563,7 @@ struct PrivateItemsInPublicInterfacesVisitor<'a, 'tcx: 'a> {
15631563
tcx: TyCtxt<'a, 'tcx, 'tcx>,
15641564
has_pub_restricted: bool,
15651565
old_error_set: &'a NodeSet,
1566-
public_crates: Option<FxHashSet<CrateNum>>
1566+
private_crates: FxHashSet<CrateNum>
15671567
}
15681568

15691569
impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> {
@@ -1601,7 +1601,7 @@ impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> {
16011601
has_pub_restricted: self.has_pub_restricted,
16021602
has_old_errors,
16031603
in_assoc_ty: false,
1604-
public_crates: self.public_crates.clone()
1604+
private_crates: self.private_crates.clone()
16051605
}
16061606
}
16071607

@@ -1762,10 +1762,10 @@ fn privacy_access_levels<'tcx>(
17621762
queries::check_mod_privacy::ensure(tcx, tcx.hir().local_def_id(module));
17631763
}
17641764

1765-
let public_crates: Option<FxHashSet<CrateNum>> = tcx.sess.opts.extern_public.as_ref()
1766-
.map(|s| s.iter().flat_map(|c| {
1765+
let private_crates: FxHashSet<CrateNum> = tcx.sess.opts.extern_private.iter()
1766+
.flat_map(|c| {
17671767
tcx.crates().iter().find(|&&krate| &tcx.crate_name(krate) == c).cloned()
1768-
}).collect());
1768+
}).collect();
17691769

17701770

17711771
// Build up a set of all exported items in the AST. This is a set of all
@@ -1810,7 +1810,7 @@ fn privacy_access_levels<'tcx>(
18101810
tcx,
18111811
has_pub_restricted,
18121812
old_error_set: &visitor.old_error_set,
1813-
public_crates
1813+
private_crates
18141814
};
18151815
krate.visit_all_item_likes(&mut DeepVisitor::new(&mut visitor));
18161816
}

src/test/ui/privacy/pub-priv-dep/pub-priv1.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// aux-build:priv_dep.rs
22
// aux-build:pub_dep.rs
3-
// compile-flags: --extern-public=pub_dep
4-
#![feature(public_private_dependencies)]
3+
// compile-flags: --extern-private priv_dep
54
#![deny(exported_private_dependencies)]
65

76
// This crate is a private dependency

src/test/ui/privacy/pub-priv-dep/pub-priv1.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
error: type `priv_dep::OtherType` from private dependency 'priv_dep' in public interface
2-
--> $DIR/pub-priv1.rs:22:5
2+
--> $DIR/pub-priv1.rs:21:5
33
|
44
LL | pub field: OtherType,
55
| ^^^^^^^^^^^^^^^^^^^^
66
|
77
note: lint level defined here
8-
--> $DIR/pub-priv1.rs:5:9
8+
--> $DIR/pub-priv1.rs:4:9
99
|
1010
LL | #![deny(exported_private_dependencies)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1313
= note: for more information, see issue #44663 <https://github.com/rust-lang/rust/issues/44663>
1414

1515
error: type `priv_dep::OtherType` from private dependency 'priv_dep' in public interface
16-
--> $DIR/pub-priv1.rs:30:5
16+
--> $DIR/pub-priv1.rs:29:5
1717
|
1818
LL | pub fn pub_fn(param: OtherType) {}
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -22,7 +22,7 @@ LL | pub fn pub_fn(param: OtherType) {}
2222
= note: for more information, see issue #44663 <https://github.com/rust-lang/rust/issues/44663>
2323

2424
error: trait `priv_dep::OtherTrait` from private dependency 'priv_dep' in public interface
25-
--> $DIR/pub-priv1.rs:37:1
25+
--> $DIR/pub-priv1.rs:36:1
2626
|
2727
LL | / pub trait MyPubTrait {
2828
LL | | type Foo: OtherTrait;

0 commit comments

Comments
 (0)