@@ -283,22 +283,29 @@ impl OutputTypes {
283283// DO NOT switch BTreeMap or BTreeSet out for an unsorted container type! That
284284// would break dependency tracking for command-line arguments.
285285#[ derive( Clone , Hash ) ]
286- pub struct Externs ( BTreeMap < String , BTreeSet < Option < String > > > ) ;
286+ pub struct Externs ( BTreeMap < String , ExternEntry > ) ;
287+
288+ #[ derive( Clone , Hash , Eq , PartialEq , Ord , PartialOrd , Debug , Default ) ]
289+ pub struct ExternEntry {
290+ pub locations : BTreeSet < Option < String > > ,
291+ pub is_private_dep : bool
292+ }
287293
288294impl Externs {
289- pub fn new ( data : BTreeMap < String , BTreeSet < Option < String > > > ) -> Externs {
295+ pub fn new ( data : BTreeMap < String , ExternEntry > ) -> Externs {
290296 Externs ( data)
291297 }
292298
293- pub fn get ( & self , key : & str ) -> Option < & BTreeSet < Option < String > > > {
299+ pub fn get ( & self , key : & str ) -> Option < & ExternEntry > {
294300 self . 0 . get ( key)
295301 }
296302
297- pub fn iter < ' a > ( & ' a self ) -> BTreeMapIter < ' a , String , BTreeSet < Option < String > > > {
303+ pub fn iter < ' a > ( & ' a self ) -> BTreeMapIter < ' a , String , ExternEntry > {
298304 self . 0 . iter ( )
299305 }
300306}
301307
308+
302309macro_rules! hash_option {
303310 ( $opt_name: ident, $opt_expr: expr, $sub_hashes: expr, [ UNTRACKED ] ) => ( { } ) ;
304311 ( $opt_name: ident, $opt_expr: expr, $sub_hashes: expr, [ TRACKED ] ) => ( {
@@ -427,10 +434,6 @@ top_level_options!(
427434 remap_path_prefix: Vec <( PathBuf , PathBuf ) > [ UNTRACKED ] ,
428435
429436 edition: Edition [ TRACKED ] ,
430-
431- // The list of crates to consider private when
432- // checking leaked private dependency types in public interfaces
433- extern_private: Vec <String > [ TRACKED ] ,
434437 }
435438) ;
436439
@@ -633,7 +636,6 @@ impl Default for Options {
633636 cli_forced_thinlto_off : false ,
634637 remap_path_prefix : Vec :: new ( ) ,
635638 edition : DEFAULT_EDITION ,
636- extern_private : Vec :: new ( )
637639 }
638640 }
639641}
@@ -2315,10 +2317,14 @@ pub fn build_session_options_and_crate_config(
23152317 )
23162318 }
23172319
2318- let extern_private = matches. opt_strs ( "extern-private" ) ;
2320+ // We start out with a Vec<(Option<String>, bool)>>,
2321+ // and later convert it into a BTreeSet<(Option<String>, bool)>
2322+ // This allows to modify entries in-place to set their correct
2323+ // 'public' value
2324+ let mut externs: BTreeMap < String , ExternEntry > = BTreeMap :: new ( ) ;
2325+ for ( arg, private) in matches. opt_strs ( "extern" ) . into_iter ( ) . map ( |v| ( v, false ) )
2326+ . chain ( matches. opt_strs ( "extern-private" ) . into_iter ( ) . map ( |v| ( v, true ) ) ) {
23192327
2320- let mut externs: BTreeMap < _ , BTreeSet < _ > > = BTreeMap :: new ( ) ;
2321- for arg in matches. opt_strs ( "extern" ) . into_iter ( ) . chain ( matches. opt_strs ( "extern-private" ) ) {
23222328 let mut parts = arg. splitn ( 2 , '=' ) ;
23232329 let name = parts. next ( ) . unwrap_or_else ( ||
23242330 early_error ( error_format, "--extern value must not be empty" ) ) ;
@@ -2331,10 +2337,17 @@ pub fn build_session_options_and_crate_config(
23312337 ) ;
23322338 } ;
23332339
2334- externs
2340+ let entry = externs
23352341 . entry ( name. to_owned ( ) )
2336- . or_default ( )
2337- . insert ( location) ;
2342+ . or_default ( ) ;
2343+
2344+
2345+ entry. locations . insert ( location. clone ( ) ) ;
2346+
2347+ // Crates start out being not private,
2348+ // and go to being private if we see an '--extern-private'
2349+ // flag
2350+ entry. is_private_dep |= private;
23382351 }
23392352
23402353 let crate_name = matches. opt_str ( "crate-name" ) ;
@@ -2386,7 +2399,6 @@ pub fn build_session_options_and_crate_config(
23862399 cli_forced_thinlto_off : disable_thinlto,
23872400 remap_path_prefix,
23882401 edition,
2389- extern_private
23902402 } ,
23912403 cfg,
23922404 )
@@ -2651,7 +2663,7 @@ mod tests {
26512663 build_session_options_and_crate_config,
26522664 to_crate_config
26532665 } ;
2654- use crate :: session:: config:: { LtoCli , LinkerPluginLto , PgoGenerate } ;
2666+ use crate :: session:: config:: { LtoCli , LinkerPluginLto , PgoGenerate , ExternEntry } ;
26552667 use crate :: session:: build_session;
26562668 use crate :: session:: search_paths:: SearchPath ;
26572669 use std:: collections:: { BTreeMap , BTreeSet } ;
@@ -2664,6 +2676,19 @@ mod tests {
26642676 use syntax;
26652677 use super :: Options ;
26662678
2679+ impl ExternEntry {
2680+ fn new_public < S : Into < String > ,
2681+ I : IntoIterator < Item = Option < S > > > ( locations : I ) -> ExternEntry {
2682+ let locations: BTreeSet < _ > = locations. into_iter ( ) . map ( |o| o. map ( |s| s. into ( ) ) )
2683+ . collect ( ) ;
2684+
2685+ ExternEntry {
2686+ locations,
2687+ is_private_dep : false
2688+ }
2689+ }
2690+ }
2691+
26672692 fn optgroups ( ) -> getopts:: Options {
26682693 let mut opts = getopts:: Options :: new ( ) ;
26692694 for group in super :: rustc_optgroups ( ) {
@@ -2676,10 +2701,6 @@ mod tests {
26762701 BTreeMap :: from_iter ( entries. into_iter ( ) )
26772702 }
26782703
2679- fn mk_set < V : Ord > ( entries : Vec < V > ) -> BTreeSet < V > {
2680- BTreeSet :: from_iter ( entries. into_iter ( ) )
2681- }
2682-
26832704 // When the user supplies --test we should implicitly supply --cfg test
26842705 #[ test]
26852706 fn test_switch_implies_cfg_test ( ) {
@@ -2797,33 +2818,33 @@ mod tests {
27972818 v1. externs = Externs :: new ( mk_map ( vec ! [
27982819 (
27992820 String :: from( "a" ) ,
2800- mk_set ( vec![ Some ( String :: from ( "b" ) ) , Some ( String :: from ( "c" ) ) ] ) ,
2821+ ExternEntry :: new_public ( vec![ Some ( "b" ) , Some ( "c" ) ] )
28012822 ) ,
28022823 (
28032824 String :: from( "d" ) ,
2804- mk_set ( vec![ Some ( String :: from ( "e" ) ) , Some ( String :: from ( "f" ) ) ] ) ,
2825+ ExternEntry :: new_public ( vec![ Some ( "e" ) , Some ( "f" ) ] )
28052826 ) ,
28062827 ] ) ) ;
28072828
28082829 v2. externs = Externs :: new ( mk_map ( vec ! [
28092830 (
28102831 String :: from( "d" ) ,
2811- mk_set ( vec![ Some ( String :: from ( "e" ) ) , Some ( String :: from ( "f" ) ) ] ) ,
2832+ ExternEntry :: new_public ( vec![ Some ( "e" ) , Some ( "f" ) ] )
28122833 ) ,
28132834 (
28142835 String :: from( "a" ) ,
2815- mk_set ( vec![ Some ( String :: from ( "b" ) ) , Some ( String :: from ( "c" ) ) ] ) ,
2836+ ExternEntry :: new_public ( vec![ Some ( "b" ) , Some ( "c" ) ] )
28162837 ) ,
28172838 ] ) ) ;
28182839
28192840 v3. externs = Externs :: new ( mk_map ( vec ! [
28202841 (
28212842 String :: from( "a" ) ,
2822- mk_set ( vec![ Some ( String :: from ( "b" ) ) , Some ( String :: from ( "c" ) ) ] ) ,
2843+ ExternEntry :: new_public ( vec![ Some ( "b" ) , Some ( "c" ) ] )
28232844 ) ,
28242845 (
28252846 String :: from( "d" ) ,
2826- mk_set ( vec![ Some ( String :: from ( "f" ) ) , Some ( String :: from ( "e" ) ) ] ) ,
2847+ ExternEntry :: new_public ( vec![ Some ( "f" ) , Some ( "e" ) ] )
28272848 ) ,
28282849 ] ) ) ;
28292850
0 commit comments