Skip to content

Commit fe15f71

Browse files
committed
Move --extern-public behind -Z unstable-options
1 parent 173f5cf commit fe15f71

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

src/librustc/session/config.rs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ top_level_options!(
414414

415415
// The list of crates to consider public for
416416
// checking leaked private dependency types in public interfaces
417-
extern_public: Vec<String> [TRACKED],
417+
extern_public: Option<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: vec![]
613+
extern_public: None
614614
}
615615
}
616616
}
@@ -1917,21 +1917,7 @@ pub fn build_session_options_and_crate_config(
19171917
let crate_types = parse_crate_types_from_list(unparsed_crate_types)
19181918
.unwrap_or_else(|e| early_error(error_format, &e[..]));
19191919

1920-
if matches.opt_present("extern-public") && !nightly_options::is_nightly_build() {
1921-
early_error(
1922-
ErrorOutputType::default(),
1923-
"'--extern-public' is unstable and only \
1924-
available for nightly builds of rustc."
1925-
)
1926-
}
1927-
1928-
let mut extern_public: Vec<String> = matches.opt_strs("extern-public").
1929-
iter().cloned().collect();
1930-
1931-
// FIXME - come up with a better way of handling this
1932-
extern_public.push("core".to_string());
1933-
extern_public.push("std".to_string());
1934-
1920+
19351921
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);
19361922

19371923
let mut debugging_opts = build_debugging_options(matches, error_format);
@@ -1950,6 +1936,24 @@ pub fn build_session_options_and_crate_config(
19501936
);
19511937
}
19521938

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());
1949+
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+
}
1955+
1956+
19531957
let mut output_types = BTreeMap::new();
19541958
if !debugging_opts.parse_only {
19551959
for list in matches.opt_strs("emit") {
@@ -2488,6 +2492,7 @@ mod dep_tracking {
24882492
impl_dep_tracking_hash_via_hash!(Option<usize>);
24892493
impl_dep_tracking_hash_via_hash!(Option<String>);
24902494
impl_dep_tracking_hash_via_hash!(Option<(String, u64)>);
2495+
impl_dep_tracking_hash_via_hash!(Option<Vec<String>>);
24912496
impl_dep_tracking_hash_via_hash!(Option<MergeFunctions>);
24922497
impl_dep_tracking_hash_via_hash!(Option<PanicStrategy>);
24932498
impl_dep_tracking_hash_via_hash!(Option<RelroLevel>);

src/librustc_privacy/lib.rs

Lines changed: 7 additions & 7 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: FxHashSet<CrateNum>
1463+
public_crates: Option<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-
// Never do any leak checking if the feature is not enabled
1542-
if !self.tcx.features().public_private_dependencies {
1541+
// Don't do any leak checking if no public crates were specified
1542+
if self.public_crates.is_none() {
15431543
return false
15441544
}
15451545
let ret = self.required_visibility == ty::Visibility::Public &&
15461546
!item_id.is_local() &&
1547-
!self.public_crates.contains(&item_id.krate);
1547+
!self.public_crates.as_ref().unwrap().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: FxHashSet<CrateNum>
1566+
public_crates: Option<FxHashSet<CrateNum>>
15671567
}
15681568

15691569
impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> {
@@ -1762,9 +1762,9 @@ fn privacy_access_levels<'tcx>(
17621762
queries::check_mod_privacy::ensure(tcx, tcx.hir().local_def_id(module));
17631763
}
17641764

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

17691769

17701770
// Build up a set of all exported items in the AST. This is a set of all

0 commit comments

Comments
 (0)