Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Replace --extern-public with --extern-private
  • Loading branch information
Aaron1011 committed Feb 1, 2019
1 parent b29a21f commit 48ec29d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
41 changes: 21 additions & 20 deletions src/librustc/session/config.rs
Expand Up @@ -412,9 +412,9 @@ top_level_options!(

edition: Edition [TRACKED],

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

Expand Down Expand Up @@ -610,7 +610,7 @@ impl Default for Options {
cli_forced_thinlto_off: false,
remap_path_prefix: Vec::new(),
edition: DEFAULT_EDITION,
extern_public: None
extern_private: Vec::new()
}
}
}
Expand Down Expand Up @@ -1736,6 +1736,12 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
"Specify where an external rust library is located",
"NAME=PATH",
),
opt::multi_s(
"",
"extern-private",
"Specify where an extern rust library is located, marking it as a private dependency",
"NAME=PATH",
),
opt::opt_s("", "sysroot", "Override the system root", "PATH"),
opt::multi("Z", "", "Set internal debugging options", "FLAG"),
opt::opt_s(
Expand Down Expand Up @@ -1936,22 +1942,7 @@ pub fn build_session_options_and_crate_config(
);
}

if matches.opt_present("extern-public") && !debugging_opts.unstable_options {
early_error(
ErrorOutputType::default(),
"'--extern-public' is unstable and only \
available for nightly builds of rustc."
)
}

let mut extern_public: Option<Vec<String>> = matches.opt_str("extern-public").
map(|s| s.split(',').map(|c| (*c).to_string()).collect());

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


let mut output_types = BTreeMap::new();
Expand Down Expand Up @@ -2249,8 +2240,18 @@ pub fn build_session_options_and_crate_config(
);
}

if matches.opt_present("extern-private") && !debugging_opts.unstable_options {
early_error(
ErrorOutputType::default(),
"'--extern-private' is unstable and only \
available for nightly builds of rustc."
)
}

let extern_private = matches.opt_strs("extern-private");

let mut externs: BTreeMap<_, BTreeSet<_>> = BTreeMap::new();
for arg in &matches.opt_strs("extern") {
for arg in matches.opt_strs("extern").into_iter().chain(matches.opt_strs("extern-private")) {
let mut parts = arg.splitn(2, '=');
let name = parts.next().unwrap_or_else(||
early_error(error_format, "--extern value must not be empty"));
Expand Down Expand Up @@ -2318,7 +2319,7 @@ pub fn build_session_options_and_crate_config(
cli_forced_thinlto_off: disable_thinlto,
remap_path_prefix,
edition,
extern_public
extern_private
},
cfg,
)
Expand Down
20 changes: 10 additions & 10 deletions src/librustc_privacy/lib.rs
Expand Up @@ -1460,7 +1460,7 @@ struct SearchInterfaceForPrivateItemsVisitor<'a, 'tcx: 'a> {
has_pub_restricted: bool,
has_old_errors: bool,
in_assoc_ty: bool,
public_crates: Option<FxHashSet<CrateNum>>
private_crates: FxHashSet<CrateNum>
}

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


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

impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> {
Expand Down Expand Up @@ -1601,7 +1601,7 @@ impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> {
has_pub_restricted: self.has_pub_restricted,
has_old_errors,
in_assoc_ty: false,
public_crates: self.public_crates.clone()
private_crates: self.private_crates.clone()
}
}

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

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


// Build up a set of all exported items in the AST. This is a set of all
Expand Down Expand Up @@ -1810,7 +1810,7 @@ fn privacy_access_levels<'tcx>(
tcx,
has_pub_restricted,
old_error_set: &visitor.old_error_set,
public_crates
private_crates
};
krate.visit_all_item_likes(&mut DeepVisitor::new(&mut visitor));
}
Expand Down
3 changes: 1 addition & 2 deletions src/test/ui/privacy/pub-priv-dep/pub-priv1.rs
@@ -1,7 +1,6 @@
// aux-build:priv_dep.rs
// aux-build:pub_dep.rs
// compile-flags: --extern-public=pub_dep
#![feature(public_private_dependencies)]
// compile-flags: --extern-private priv_dep
#![deny(exported_private_dependencies)]

// This crate is a private dependency
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/privacy/pub-priv-dep/pub-priv1.stderr
@@ -1,19 +1,19 @@
error: type `priv_dep::OtherType` from private dependency 'priv_dep' in public interface
--> $DIR/pub-priv1.rs:22:5
--> $DIR/pub-priv1.rs:21:5
|
LL | pub field: OtherType,
| ^^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
--> $DIR/pub-priv1.rs:5:9
--> $DIR/pub-priv1.rs:4:9
|
LL | #![deny(exported_private_dependencies)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #44663 <https://github.com/rust-lang/rust/issues/44663>

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

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

0 comments on commit 48ec29d

Please sign in to comment.