From fe15f7177f59f4ac9e9eb22dff727cd58a097e11 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Tue, 29 Jan 2019 16:10:49 -0500 Subject: [PATCH] Move --extern-public behind -Z unstable-options --- src/librustc/session/config.rs | 39 +++++++++++++++++++--------------- src/librustc_privacy/lib.rs | 14 ++++++------ 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index e63336437cd..132a5a2a62b 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -414,7 +414,7 @@ top_level_options!( // The list of crates to consider public for // checking leaked private dependency types in public interfaces - extern_public: Vec [TRACKED], + extern_public: Option> [TRACKED], } ); @@ -610,7 +610,7 @@ impl Default for Options { cli_forced_thinlto_off: false, remap_path_prefix: Vec::new(), edition: DEFAULT_EDITION, - extern_public: vec![] + extern_public: None } } } @@ -1917,21 +1917,7 @@ pub fn build_session_options_and_crate_config( let crate_types = parse_crate_types_from_list(unparsed_crate_types) .unwrap_or_else(|e| early_error(error_format, &e[..])); - if matches.opt_present("extern-public") && !nightly_options::is_nightly_build() { - early_error( - ErrorOutputType::default(), - "'--extern-public' is unstable and only \ - available for nightly builds of rustc." - ) - } - - let mut extern_public: Vec = matches.opt_strs("extern-public"). - iter().cloned().collect(); - - // FIXME - come up with a better way of handling this - extern_public.push("core".to_string()); - extern_public.push("std".to_string()); - + let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format); let mut debugging_opts = build_debugging_options(matches, error_format); @@ -1950,6 +1936,24 @@ 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> = 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(); if !debugging_opts.parse_only { for list in matches.opt_strs("emit") { @@ -2488,6 +2492,7 @@ mod dep_tracking { impl_dep_tracking_hash_via_hash!(Option); impl_dep_tracking_hash_via_hash!(Option); impl_dep_tracking_hash_via_hash!(Option<(String, u64)>); + impl_dep_tracking_hash_via_hash!(Option>); impl_dep_tracking_hash_via_hash!(Option); impl_dep_tracking_hash_via_hash!(Option); impl_dep_tracking_hash_via_hash!(Option); diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 01694df1df1..f4f09db1087 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -1460,7 +1460,7 @@ struct SearchInterfaceForPrivateItemsVisitor<'a, 'tcx: 'a> { has_pub_restricted: bool, has_old_errors: bool, in_assoc_ty: bool, - public_crates: FxHashSet + public_crates: Option> } 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 { - // Never do any leak checking if the feature is not enabled - if !self.tcx.features().public_private_dependencies { + // Don't do any leak checking if no public crates were specified + if self.public_crates.is_none() { return false } let ret = self.required_visibility == ty::Visibility::Public && !item_id.is_local() && - !self.public_crates.contains(&item_id.krate); + !self.public_crates.as_ref().unwrap().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: FxHashSet + public_crates: Option> } impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> { @@ -1762,9 +1762,9 @@ fn privacy_access_levels<'tcx>( queries::check_mod_privacy::ensure(tcx, tcx.hir().local_def_id(module)); } - let public_crates: FxHashSet = tcx.sess.opts.extern_public.iter().flat_map(|c| { + let public_crates: Option> = tcx.sess.opts.extern_public.as_ref().map(|s| s.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