Replace --extern-public with --extern-private
This commit is contained in:
parent
b29a21fbae
commit
48ec29d38e
@ -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],
|
||||
}
|
||||
);
|
||||
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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(
|
||||
@ -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();
|
||||
@ -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"));
|
||||
@ -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,
|
||||
)
|
||||
|
@ -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> {
|
||||
@ -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);
|
||||
@ -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> {
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -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));
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -1,11 +1,11 @@
|
||||
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)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -13,7 +13,7 @@ LL | #![deny(exported_private_dependencies)]
|
||||
= 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) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user